Пример #1
0
        /// <summary>
        /// Simulate a memory free.
        /// </summary>
        /// <param name="hKernel">Specifies the CudaDnn kernel that holds the allocated memory.</param>
        /// <param name="nDeviceID">Specifies the CudaDnn device ID on which the memory was allocated.</param>
        /// <param name="hMemory">Specifies the CudaDnn handle to the memory.</param>
        public void FreeMemory(long hKernel, int nDeviceID, long hMemory)
        {
            string strKey   = MemoryInfo.ToKey(nDeviceID, hKernel, hMemory);
            int    nKeyHash = strKey.GetHashCode();

            if (!m_rgItems.ContainsKey(nKeyHash))
            {
                throw new Exception("Memory item '" + strKey + "' does not exist!");
            }

            m_rgItems.Remove(nKeyHash);
        }
Пример #2
0
        /// <summary>
        /// Simulate a memory allocation.
        /// </summary>
        /// <param name="hKernel">Specifies the CudaDnn kernel that holds the allocated memory.</param>
        /// <param name="nDeviceID">Specifies the CudaDnn device ID on which the memory was allocated.</param>
        /// <param name="hMemory">Specifies the CudaDnn handle to the memory.</param>
        /// <param name="lSize">Specifies the size of the memory (in items).</param>
        /// <returns></returns>
        public long AllocMemory(long hKernel, int nDeviceID, long hMemory, long lSize)
        {
            MemoryInfo mi       = new MemoryInfo(hKernel, nDeviceID, hMemory, lSize);
            string     strKey   = mi.ToKey();
            int        nKeyHash = strKey.GetHashCode();

            if (m_rgItems.ContainsKey(nKeyHash))
            {
                throw new Exception("Memory item '" + strKey + "' already exists!");
            }

            m_rgItems.Add(nKeyHash, mi);

            return(hMemory);
        }
Пример #3
0
        /// <summary>
        /// Simulate a memory free.
        /// </summary>
        /// <param name="hKernel">Specifies the CudaDnn kernel that holds the allocated memory.</param>
        /// <param name="nDeviceID">Specifies the CudaDnn device ID on which the memory was allocated.</param>
        /// <param name="hMemory">Specifies the CudaDnn handle to the memory.</param>
        public void FreeMemory(long hKernel, int nDeviceID, long hMemory)
        {
            string strKey   = MemoryInfo.ToKey(nDeviceID, hKernel, hMemory);
            int    nKeyHash = strKey.GetHashCode();

            if (!m_rgItems.ContainsKey(nKeyHash))
            {
                throw new Exception("Memory item '" + strKey + "' does not exist!");
            }

            m_rgItems.Remove(nKeyHash);

#if DEBUG
            if (m_bEnableMemoryTrace)
            {
                Trace.WriteLine("Memory Used: " + TotalMemoryUsedText);
            }
#endif
        }
Пример #4
0
        /// <summary>
        /// Simulate a memory allocation.
        /// </summary>
        /// <param name="hKernel">Specifies the CudaDnn kernel that holds the allocated memory.</param>
        /// <param name="nDeviceID">Specifies the CudaDnn device ID on which the memory was allocated.</param>
        /// <param name="hMemory">Specifies the CudaDnn handle to the memory.</param>
        /// <param name="lSize">Specifies the size of the memory (in items).</param>
        /// <param name="bHalf">Specifies whether or not half memory is used.</param>
        /// <returns></returns>
        public long AllocMemory(long hKernel, int nDeviceID, long hMemory, ulong lSize, bool bHalf)
        {
            MemoryInfo mi       = new MemoryInfo(hKernel, nDeviceID, hMemory, lSize, bHalf);
            string     strKey   = mi.ToKey();
            int        nKeyHash = strKey.GetHashCode();

            if (m_rgItems.ContainsKey(nKeyHash))
            {
                throw new Exception("Memory item '" + strKey + "' already exists!");
            }

            m_rgItems.Add(nKeyHash, mi);

#if DEBUG
            if (m_bEnableMemoryTrace)
            {
                Trace.WriteLine("Memory Used: " + TotalMemoryUsedText);
            }
#endif

            return(hMemory);
        }