Exemple #1
0
        static string TestCopyIntsDeviceToDevice()
        {
            string testName = "TestCopyIntsDeviceToDevice";
            uint   arrayLen = 1000;
            var    alist    = Enumerable.Range(4, (int)arrayLen).ToArray();
            var    aa       = new CudaArray();
            IntPtr devDataA = new System.IntPtr();
            IntPtr devDataB = new System.IntPtr();
            var    retlist  = new int[(int)arrayLen];

            try
            {
                var res = aa.ResetDevice();
                res = res + aa.MallocIntsOnDevice(ref devDataA, arrayLen);
                res = res + aa.MallocIntsOnDevice(ref devDataB, arrayLen);
                res = res + aa.CopyIntsToDevice(alist, devDataA, arrayLen);
                res = res + aa.CopyIntsDeviceToDevice(devDataB, devDataA, arrayLen);
                res = res + aa.CopyIntsFromDevice(retlist, devDataB, arrayLen);
                res = res + aa.ReleaseDevicePtr(devDataA);
                res = res + aa.ReleaseDevicePtr(devDataB);

                if (!alist.SequenceEqual(retlist))
                {
                    return(testName + " fail: sequences do not match");
                }

                if (res != String.Empty)
                {
                    return(testName + " fail: " + res);
                }
                return(testName + " pass");
            }
            catch (Exception ex)
            {
                return(testName + " exception " + ex.Message);
            }
            finally
            {
                aa.ReleaseDevicePtr(devDataA);
                aa.ReleaseDevicePtr(devDataB);
                aa.ResetDevice();
            }
        }
Exemple #2
0
        static string TestMakeNormalRands()
        {
            string testName = "TestMakeNormalRands";
            var    rdo      = new RandoClr.RandoProcs();
            var    aa       = new CudaArray();
            uint   arrayLen = 1000;
            int    seed     = 1234;
            IntPtr devRando = new IntPtr();
            IntPtr devData  = new IntPtr();
            var    retlist  = new float[(int)arrayLen];

            try
            {
                var res = aa.ResetDevice();

                res = res + rdo.MakeGenerator64(ref devRando, seed);
                res = res + aa.MallocFloatsOnDevice(ref devData, arrayLen);
                res = res + rdo.MakeNormalRands(devData, devRando, arrayLen, 0.0f, 1.0f);
                res = res + aa.CopyFloatsFromDevice(retlist, devData, arrayLen);

                res = res + aa.ReleaseDevicePtr(devData);
                res = res + rdo.DestroyGenerator(devRando);

                if (res != String.Empty)
                {
                    return(testName + " fail: " + res);
                }
                return(testName + " pass");
            }
            catch
            {
                return(testName + " fail");
            }
            finally
            {
                //rdo.DestroyGenerator(devRando);
                aa.ReleaseDevicePtr(devData);
                aa.ResetDevice();
            }
        }
Exemple #3
0
        public static string ClearOnDevice(out GpuMatrix gmOut, GpuMatrix gmIn)
        {
            if (gmIn.DevHostState == DevHostState.DeviceNotAllocated)
            {
                gmOut = null;
                return("Device data pointer already cleared");
            }

            var aa     = new CudaArray();
            var strRet = aa.ReleaseDevicePtr(gmIn.DevPtr);

            if (!String.IsNullOrEmpty(strRet))
            {
                gmOut = null;
                return(strRet);
            }

            gmOut = new GpuMatrix(
                matrix: gmIn.Matrix,
                devPtr: new IntPtr(),
                devHostState: DevHostState.DeviceNotAllocated);

            return(String.Empty);
        }