示例#1
0
        internal Gpu4DTensor(CudaProvider provider, IReadOnlyList <I3DTensor> tensorList)
        {
            var first = tensorList.First();

            _cuda    = provider;
            _rows    = first.RowCount;
            _columns = first.ColumnCount;
            _depth   = first.Depth;
            _count   = tensorList.Count;
            provider.Register(this);

            _data       = _cuda.CreateZeroMatrix(_rows * _columns * _depth, _count);
            _subVector  = new Lazy <List <GpuVector[]> >(_GetSubVectors);
            _tensorInfo = new Lazy <TensorInput>(_GetInput);

            for (var i = 0; i < _count; i++)
            {
                _data.Column(i).AddInPlace(tensorList[i].ConvertToVector());
            }

#if DEBUG
            if (_id == _badAlloc)
            {
                Debugger.Break();
            }
#endif
        }
示例#2
0
        public GpuMatrix(CudaProvider cuda, int rows, int columns, Func <int, int, float> init)
        {
            _cuda    = cuda;
            _rows    = rows;
            _columns = columns;

            var count = rows * columns;
            var data  = new float[count];

            for (var j = 0; j < columns; j++)
            {
                for (var i = 0; i < rows; i++)
                {
                    data[j * rows + i] = init(i, j);
                }
            }
            _data = cuda.Allocate(count);
            _data.CopyToDevice(data);
            cuda.Register(this);

#if DEBUG
            if (_id == _badAlloc)
            {
                Debugger.Break();
            }
#endif
        }
示例#3
0
        public Gpu4DTensor(CudaProvider provider, IReadOnlyList <FloatTensor> data)
        {
            var firstTensor = data.First();
            var firstMatrix = firstTensor.Matrix.First();

            _cuda    = provider;
            _rows    = firstMatrix.RowCount;
            _columns = firstMatrix.ColumnCount;
            _depth   = firstTensor.Matrix.Length;
            _count   = data.Count;

            var matrixSize = _rows * _columns;

            _data = provider.CreateMatrix(matrixSize * _depth, _count, (index, k) => {
                var z   = index / matrixSize;
                var rem = index % matrixSize;
                var i   = rem / _rows;
                var j   = rem % _rows;
                return(data[k].Matrix[z].Row[j].Data[i]);
            });
            provider.Register(this);

            _subVector  = new Lazy <List <GpuVector[]> >(_GetSubVectors);
            _tensorInfo = new Lazy <TensorInput>(_GetInput);

#if DEBUG
            if (_id == _badAlloc)
            {
                Debugger.Break();
            }
#endif
        }
示例#4
0
 public Gpu3DTensor(CudaProvider provider, int rows, int columns, int depth, IReadOnlyList <GpuMatrix> data)
 {
     _cuda    = provider;
     _rows    = rows;
     _columns = columns;
     _depth   = depth;
     _data    = data;
 }
示例#5
0
        public GpuVector(CudaProvider cuda, IDeviceMemoryPtr data, bool isOwner)
        {
            _cuda = cuda;
            _data = data;
            cuda.Register(this);
#if DEBUG
            if (_id == _badAlloc)
            {
                Debugger.Break();
            }
#endif
        }
示例#6
0
        internal GpuMatrix(CudaProvider cuda, int rows, int columns, IDeviceMemoryPtr gpuData)
        {
            _cuda    = cuda;
            _rows    = rows;
            _columns = columns;
            _data    = gpuData;
            cuda.Register(this);
#if DEBUG
            if (_id == _badAlloc)
            {
                Debugger.Break();
            }
#endif
        }
示例#7
0
        public GpuMatrix(CudaProvider cuda, int rows, int columns, IDeviceMemoryPtr data, bool isOwner)
        {
            Debug.Assert(rows * columns == data.Size);
            _cuda    = cuda;
            _rows    = rows;
            _columns = columns;
            _data    = data;
            cuda.Register(this);
#if DEBUG
            if (_id == _badAlloc)
            {
                Debugger.Break();
            }
#endif
        }
示例#8
0
        public Gpu3DTensor(CudaProvider provider, int rows, int columns, int depth, IReadOnlyList <GpuMatrix> data)
        {
            _cuda       = provider;
            _rows       = rows;
            _columns    = columns;
            _depth      = depth;
            _data       = data;
            _tensorInfo = new Lazy <TensorInput>(() => new TensorInput(rows, columns, new[] { data.Select(m => m.Memory).ToList() }));
            provider.Register(this);

#if DEBUG
            if (_id == _badAlloc)
            {
                Debugger.Break();
            }
#endif
        }
示例#9
0
        internal GpuVector(CudaProvider cuda, int size, CudaDeviceVariable <float> data, bool shouldRegister = true)
        {
            _cuda = cuda;
            _data = data;
            _size = size;
            if (shouldRegister)
            {
                cuda.Register(this);
            }

#if DEBUG
            if (_id == _badAlloc)
            {
                Debugger.Break();
            }
#endif
        }
示例#10
0
        internal GpuMatrix(CudaProvider cuda, int rows, int columns, CudaDeviceVariable <float> gpuData, bool shouldRegister = true)
        {
            _cuda    = cuda;
            _rows    = rows;
            _columns = columns;
            _data    = gpuData;
            if (shouldRegister)
            {
                cuda.Register(this);
            }
#if DEBUG
            if (_id == _badAlloc)
            {
                Debugger.Break();
            }
#endif
        }
示例#11
0
        public Gpu3DTensor(CudaProvider provider, int rows, int columns, int depth, IDeviceMemoryPtr data, bool isOwner)
        {
            Debug.Assert(rows * columns * depth == data.Size);
            _cuda      = provider;
            _rows      = rows;
            _columns   = columns;
            _depth     = depth;
            _data      = data;
            _blockSize = rows * columns;
            provider.Register(this);

#if DEBUG
            if (_id == _badAlloc)
            {
                Debugger.Break();
            }
#endif
        }
示例#12
0
        public GpuVector(CudaProvider cuda, int size, Func <int, float> init)
        {
            _cuda = cuda;
            var data = new float[size];

            for (var i = 0; i < size; i++)
            {
                data[i] = init(i);
            }
            _data = cuda.Allocate(size);
            _data.CopyToDevice(data);
            cuda.Register(this);
#if DEBUG
            if (_id == _badAlloc)
            {
                Debugger.Break();
            }
#endif
        }
示例#13
0
        internal Gpu4DTensor(CudaProvider provider, IMatrix data, int rows, int columns, int depth)
        {
            _cuda    = provider;
            _data    = data;
            _rows    = rows;
            _columns = columns;
            _depth   = depth;
            _count   = data.ColumnCount;
            provider.Register(this);

            _subVector  = new Lazy <List <GpuVector[]> >(_GetSubVectors);
            _tensorInfo = new Lazy <TensorInput>(_GetInput);

#if DEBUG
            if (_id == _badAlloc)
            {
                Debugger.Break();
            }
#endif
        }
示例#14
0
        public GpuVector(CudaProvider cuda, int size, Func <int, float> init)
        {
            _cuda = cuda;
            var data = new float[size];

            for (var i = 0; i < size; i++)
            {
                data[i] = init(i);
            }
            _data = new CudaDeviceVariable <float>(cuda.Context.AllocateMemory(size * sizeof(float)));
            _data.CopyToDevice(data);
            _size = size;
            cuda.Register(this);
#if DEBUG
            if (_id == _badAlloc)
            {
                Debugger.Break();
            }
#endif
        }
示例#15
0
 public GpuMatrix(CudaProvider cuda, IIndexableMatrix matrix) : this(cuda, matrix.RowCount, matrix.ColumnCount, (j, k) => matrix[j, k])
 {
 }
示例#16
0
 public GpuVector(CudaProvider cuda, IIndexableVector vector) : this(cuda, vector.Count, i => vector[i])
 {
 }