Пример #1
0
        public void Test_copyOnHost()
        {
            int len = 35687;

            int[]  bufa = new int[len];
            int[]  bufb = new int[len];
            Random r    = new Random();

            for (int i = 0; i < len; i++)
            {
                bufa[i] = r.Next() + 1;
            }
            IntPtr ha = _gpu.HostAllocate <int>(len);

            ha.Write(bufa, 0, 0, len);
            IntPtr hb = _gpu.HostAllocate <int>(len);

            GPGPU.CopyMemory(hb, ha, (uint)len * sizeof(int));

            hb.Read(bufb, 0, 0, len);
            for (int i = 0; i < len; i++)
            {
                Assert.True(bufa[i] == bufb[i]);
                Assert.False(bufa[i] == 0);
            }
            _gpu.HostFreeAll();
        }
Пример #2
0
        public void SetMessage(string value, int length)
        {
            fixed(char *srcptr = value)
            {
                fixed(char *dstptr = _messageChars)
                {
                    IntPtr src = new IntPtr(srcptr);
                    IntPtr dst = new IntPtr(dstptr);

                    GPGPU.CopyMemory(dst, src, (uint)Math.Min(32, length * 2));
                }
            }
        }
Пример #3
0
        private void DoExecute <T, U>(FFTPlan plan, Array input, Array output, bool inverse = false)
        {
            //_gpu.VerifyOnGPU(input);
            //_gpu.VerifyOnGPU(output);
            EmuDevicePtrEx inputPtr   = _gpu.GetDeviceMemory(input) as EmuDevicePtrEx;
            EmuDevicePtrEx outputPtr  = _gpu.GetDeviceMemory(output) as EmuDevicePtrEx;
            FFTPlanEx      planEx     = Plans[plan];
            Ifftw_plan     fftwplan   = inverse ? planEx.FFTWInvPlan : planEx.FFTWFwdPlan;
            int            insize     = Marshal.SizeOf(typeof(T));
            int            inoffset   = inputPtr.OffsetBytes;
            int            outoffset  = outputPtr.OffsetBytes;
            int            outsize    = Marshal.SizeOf(typeof(U));
            int            batchSize  = plan.BatchSize;
            int            planLength = plan.Length;
            int            N          = planEx.N;

            unsafe
            {
                GCHandle inhandle  = new GCHandle();
                GCHandle outhandle = new GCHandle();
                try
                {
                    inhandle  = GCHandle.Alloc(inputPtr.DevPtr, GCHandleType.Pinned);
                    outhandle = GCHandle.Alloc(outputPtr.DevPtr, GCHandleType.Pinned);

                    long srcAddress = inhandle.AddrOfPinnedObject().ToInt64();
                    long dstAddress = outhandle.AddrOfPinnedObject().ToInt64();

                    int srcOffset = 0;
                    int dstOffset = 0;
                    //for (int b = 0; b < batchSize; b++)
                    {
                        IntPtr srcOffsetPtr = new IntPtr(srcAddress + inoffset + (srcOffset * insize));
                        GPGPU.CopyMemory(fftwplan.Input, srcOffsetPtr, (uint)(N * insize * batchSize));

                        fftwplan.Execute();
                        IntPtr dstIntPtrOffset = new IntPtr(dstAddress + outoffset + (dstOffset * outsize));
                        GPGPU.CopyMemory(dstIntPtrOffset, fftwplan.Output, (uint)(N * outsize * batchSize));

                        //srcOffset += planLength;
                        // dstOffset += planLength;
                    }
                }
                finally
                {
                    inhandle.Free();
                    outhandle.Free();
                }
            }
        }