Esempio n. 1
0
 protected override DevicePtrEx GetDevicePtr(Array array, ref int n)
 {
     EmuDevicePtrEx ptrEx = new EmuDevicePtrEx(0, array, array.Length);
     if (n == 0)
         n = ptrEx.TotalSize;
     return ptrEx;
 }
Esempio n. 2
0
        protected override DevicePtrEx GetDevicePtr(Array array, ref int n)
        {
            EmuDevicePtrEx ptrEx = new EmuDevicePtrEx(0, array, array.Length);

            if (n == 0)
            {
                n = ptrEx.TotalSize;
            }
            return(ptrEx);
        }
Esempio n. 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();
                }
            }
        }
Esempio n. 4
0
        ////public override double ASUM<T>(Types.ComplexD[,] devMatrix, int n = 0, int row = 0, int col = 0, bool columnWise = true, int incx = 1)
        ////{
        ////    throw new NotImplementedException();
        ////}

        //public override double ASUM<T>(Types.ComplexD[] vector, int n = 0, int row = 0, int incx = 1)
        //{
        //    throw new NotImplementedException();
        //}

        ////public override float ASUM<T>(Types.ComplexF[,] devMatrix, int n = 0, int row = 0, int col = 0, bool columnWise = true, int incx = 1)
        ////{
        ////    throw new NotImplementedException();
        ////}

        //public override float ASUM<T>(Types.ComplexF[] vector, int n = 0, int row = 0, int incx = 1)
        //{
        //    throw new NotImplementedException();
        //}

        ////public override double ASUM<T>(double[,] devMatrix, int n = 0, int row = 0, int col = 0, bool columnWise = true, int incx = 1)
        ////{
        ////    throw new NotImplementedException();
        ////}

        //public override double ASUM<T>(double[] vector, int n = 0, int row = 0, int incx = 1)
        //{
        //    throw new NotImplementedException();
        //}

        ////public override float ASUM<T>(float[,] devMatrix, int n = 0, int row = 0, int col = 0, bool columnWise = true, int incx = 1)
        ////{
        ////    throw new NotImplementedException();
        ////}

        //public override float ASUM<T>(float[] vector, int n = 0, int row = 0, int incx = 1)
        //{
        //    throw new NotImplementedException();
        //}

        ////protected override void AXPYEx<T>(object alpha, object vectorx, object vectory, int n = 0, int row = 0, int incx = 1, int y = 0, int incy = 1)
        ////{
        ////    throw new NotImplementedException();
        ////}

        //public override void AXPY<T>(T alpha, T[] vectorx, T[] vectory, int n = 0, int row = 0, int incx = 1, int y = 0, int incy = 1)
        //{
        //    throw new NotImplementedException();
        //}

        //protected override void COPY<T>(object src, object dst, int n = 0, int rowx = 0, int incx = 1, int rowy = 0, int incy = 1)
        //{
        //    throw new NotImplementedException();
        //}

        //public override T DOT<T>(T[] vectorx, T[] vectory, int n = 0, int rowx = 0, int incx = 1, int rowy = 0, int incy = 1)
        //{
        //    throw new NotImplementedException();
        //}

        //public override T NRM2<T>(T[] vectorx, int n = 0, int rowx = 0, int incx = 1)
        //{
        //    throw new NotImplementedException();
        //}

        //protected override int IAMAXEx<T>(object devArray, int n = 0, int row = 0, int incx = 1)
        //{
        //    throw new NotImplementedException();
        //}

        ////public override Tuple<int,int> IAMAX<T>(T[,] devMatrix, int n = 0, int row = 0, int col = 0, bool columnWise = true, int incx = 1)
        ////{
        ////    throw new NotImplementedException();
        ////}

        //protected override int IAMINEx<T>(object devArray, int n = 0, int row = 0, int incx = 1)
        //{
        //    throw new NotImplementedException();
        //}

        ////public override int IAMIN<T>(T[,] devMatrix, int n = 0, int row = 0, int col = 0, bool columnWise = true, int incx = 1)
        ////{
        ////    throw new NotImplementedException();
        ////}

        //public override void SCALEx<T>(T alpha, object vector, int n = 0, int row = 0, int incx = 1)
        //{
        //    throw new NotImplementedException();
        //}

        ////public override void SCAL<T>(T alpha, T[,] devMatrix, int n = 0, int row = 0, int col = 0, bool columnWise = true, int incx = 1)
        ////{
        ////    throw new NotImplementedException();
        ////}

        //public override T DOTC<T>(T[] vectorx, T[] vectory, int n = 0, int rowx = 0, int incx = 1, int rowy = 0, int incy = 1)
        //{
        //    throw new NotImplementedException();
        //}

        //public override void ROT(float[] vectorx, float[] vectory, float sc, float ss, int n = 0, int rowx = 0, int incx = 1, int rowy = 0, int incy = 0)
        //{
        //    throw new NotImplementedException();
        //}

        //public override void ROT(double[] vectorx, double[] vectory, double sc, double ss, int n = 0, int rowx = 0, int incx = 1, int rowy = 0, int incy = 0)
        //{
        //    throw new NotImplementedException();
        //}

        //public override void ROT(Types.ComplexF[] vectorx, Types.ComplexF[] vectory, float sc, Types.ComplexF ss, int n = 0, int rowx = 0, int incx = 1, int rowy = 0, int incy = 0)
        //{
        //    throw new NotImplementedException();
        //}

        //public override void ROT(Types.ComplexD[] vectorx, Types.ComplexD[] vectory, float sc, Types.ComplexD cs, int n = 0, int rowx = 0, int incx = 1, int rowy = 0, int incy = 0)
        //{
        //    throw new NotImplementedException();
        //}


        //public override void ROTM(float[] vectorx, float[] vectory, float[] sparam, int n = 0, int rowx = 0, int incx = 1, int rowy = 0, int incy = 0)
        //{
        //    throw new NotImplementedException();
        //}

        //public override void ROTM(double[] vectorx, double[] vectory, double[] sparam, int n = 0, int rowx = 0, int incx = 1, int rowy = 0, int incy = 0)
        //{
        //    throw new NotImplementedException();
        //}

        //public override void SWAP<T>(T[] vectorx, T[] vectory, int n = 0, int rowx = 0, int incx = 1, int rowy = 0, int incy = 0)
        //{
        //    throw new NotImplementedException();
        //}

        private IntPtr SetupVector <T>(object vector, int x, ref int n, ref int incx, out eDataType type)
        {
            EmuDevicePtrEx ptrEx = _gpu.GetDeviceMemory(vector) as EmuDevicePtrEx;

            if (incx == 0)
            {
                throw new CudafyHostException(CudafyHostException.csX_NOT_SET, "incx");
            }
            n    = (n == 0 ? ptrEx.TotalSize / incx : n);
            type = GetDataType <T>();
            int    size = Marshal.SizeOf(typeof(T));
            IntPtr ptr  = ptrEx.GetDevPtrPtr(size * x);// DevPtr + (uint)(size * x);

            return(ptr);
        }