Esempio n. 1
0
        public Buffer(ComputeProvider provider, Operations operations, Memory memory, IntPtr data, int length) // Create and copy/use data from host
        {
            ClNet.ErrorCode error;
            _length = length;
            _mem    = Cl.CreateBuffer(provider.Context, (ClNet.MemFlags)operations | (memory == Memory.Host ? ClNet.MemFlags.UseHostPtr : (ClNet.MemFlags)memory | (data != IntPtr.Zero ? ClNet.MemFlags.CopyHostPtr : 0)),
                                      (IntPtr)(_elementSize * _length), data, out error);

            if (error != ClNet.ErrorCode.Success)
            {
                throw new Cl.Exception(error);
            }

            Operations = operations;
            Memory     = memory;
        }
Esempio n. 2
0
        public Buffer(ComputeProvider provider, Operations operations, bool hostAccessible, int length) // Create, no data
        {
            ClNet.ErrorCode error;
            _length = length;
            var size = (IntPtr)(_length * _elementSize);

            _mem = Cl.CreateBuffer(
                provider.Context
                , (ClNet.MemFlags)operations | (hostAccessible ? ClNet.MemFlags.AllocHostPtr : 0)
                , size, null, out error);

            if (error != ClNet.ErrorCode.Success)
            {
                throw new Cl.Exception(error);
            }

            Operations = operations;
            Memory     = Memory.Device;
        }