Пример #1
0
        public void *Rent(long length, long unitlength)
        {
            lock (Mutex)
            {
                UnreturnedArrayCount++;

                length *= unitlength;
                if (Stacks.ContainsKey(length) && (Stacks[length] is Stack <PointerArray> x) && x.Count > 0)
                {
                    PointerArray sr = x.Pop();
                    return(sr.Ptr);
                }
                else
                {
                    if (this.Device.Type == DeviceType.NvidiaGPU)
                    {
                        GC.AddMemoryPressure(length);
                        CudaManagement.SetDevice(this.Device.ID);
                        return(CudaManagement.Allocate(length, Device.ID));
                    }
                    else if (this.Device.Type == DeviceType.Host)
                    {
                        GC.AddMemoryPressure(length);
                        return(MKL.MKL_malloc(length, 32));
                    }
                    else
                    {
                        throw new Exception("Uknown Device in ArrayPool!");
                    }
                }
            }
        }