Example #1
0
        /// <summary>
        /// Release all GPU and Host resources used.
        /// </summary>
        public void Dispose()
        {
            if (m_hData != 0)
            {
                m_cuda.FreeMemory(m_hData);
                m_hData = 0;
            }

            if (m_hDiff != 0)
            {
                m_cuda.FreeMemory(m_hDiff);
                m_hDiff = 0;
            }

            if (m_hStream != 0)
            {
                m_cuda.FreeStream(m_hStream);
                m_hStream = 0;
            }
        }
Example #2
0
 private void free()
 {
     if (m_hGpuData != 0)
     {
         check_device();
         if (m_bOwnData)
         {
             m_cuda.FreeMemory(m_hGpuData);
         }
         else
         {
             m_cuda.FreeMemoryPointer(m_hGpuData);
         }
     }
 }
Example #3
0
        static void Main(string[] args)
        {
            // This memory will reside on the GPU.
            long hGpuMem = 0;

            Console.WriteLine("Creating CudaCuDnn...");
            CudaDnn <float> cuda = new CudaDnn <float>(0);

            try
            {
                string strDeviceInfo = cuda.GetDeviceName(0);
                Console.WriteLine(strDeviceInfo);
                strDeviceInfo = cuda.GetDeviceP2PInfo(0);
                Console.WriteLine(strDeviceInfo);
                strDeviceInfo = cuda.GetDeviceInfo(0, true);
                Console.WriteLine(strDeviceInfo);

                List <long> rghGpuMem = new List <long>();
                long        lOffset   = 0;

                // You must first allocate the GPU memory to use.
                // Below we will allocate an array of 1000 float values.
                Console.WriteLine("Allocate 1000 items...");
                hGpuMem = cuda.AllocMemory(1000);
                cuda.set(1000, hGpuMem, 0.0);

                Console.WriteLine("Create memory pointers...");
                for (int i = 0; i < 10; i++)
                {
                    long hMem1 = cuda.CreateMemoryPointer(hGpuMem, lOffset, 100);
                    cuda.set(100, hMem1, (double)(i + 1));
                    rghGpuMem.Add(hMem1);
                    lOffset += 100;
                }

                Console.WriteLine("Test memory...");
                for (int i = 0; i < 10; i++)
                {
                    long    hMem1  = rghGpuMem[i];
                    float[] rgData = cuda.GetMemoryFloat(hMem1);

                    if (rgData.Length != 100)
                    {
                        throw new Exception("The data length should = 100!");
                    }

                    for (int j = 0; j < 100; j++)
                    {
                        if (rgData[j] != (float)(i + 1))
                        {
                            throw new Exception("The data at index " + j.ToString() + " is not correct!");
                        }
                    }
                }

                Console.WriteLine("Memory test passed successfully!");
            }
            catch (Exception excpt)
            {
                Console.WriteLine("ERROR: " + excpt.Message);
            }
            finally
            {
                // Clean-up and release all GPU memory used.
                if (hGpuMem != 0)
                {
                    cuda.FreeMemory(hGpuMem);
                    hGpuMem = 0;
                }

                cuda.Dispose();
            }

            Console.WriteLine("Press any key to exit.");
            Console.Read();
        }