Beispiel #1
0
        public IntPtr CreateBuffer(uint size, CLEnum flags)
        {
            var result = Bindings.OpenCl.CreateBuffer(
                Handle,
                flags,
                (UIntPtr)size,
                Span <byte> .Empty,
                Span <int> .Empty
                );

            if (result == IntPtr.Zero)
            {
                throw new Exception("Failed to allocate device memory!");
            }

            var error = (CLEnum)Bindings.OpenCl.RetainMemObject(result);

            if (error != CLEnum.Success)
            {
                throw new Exception("Failed to retain device memory!");
            }

            OpenBuffers.Add(result);

            return(result);
        }
Beispiel #2
0
        private byte[] QueryInfo(CLEnum type)
        {
            var result = new byte[1024];

            var size = new UIntPtr[1];

            var error = (CLEnum)Bindings.OpenCl.GetDeviceInfo(
                Handle,
                (uint)type,
                (UIntPtr)result.Length,
                new Span <byte>(result),
                new Span <UIntPtr>(size)
                );

            if (error != CLEnum.Success)
            {
                throw new Exception($"Failed to get device info \"{type}\"!");
            }

            Array.Resize(ref result, (int)size[default]);
Beispiel #3
0
        public uint QueryCommandQueue(CLEnum flag)
        {
            var bytes = new byte[1024];

            var size = new UIntPtr[1];

            var error = (CLEnum)Bindings.OpenCl.GetCommandQueueInfo(
                Queue,
                (uint)flag,
                (UIntPtr)bytes.Length,
                new Span <byte>(bytes),
                new Span <UIntPtr>(size)
                );

            if (error != CLEnum.Success)
            {
                throw new Exception("Failed to query command queue!");
            }

            Array.Resize(ref bytes, (int)size[0]);

            return(BitConverter.ToUInt32(bytes));
        }
Beispiel #4
0
        public unsafe IntPtr MapBuffer(IntPtr buffer, uint size, CLEnum flags)
        {
            var result = Bindings.OpenCl.EnqueueMapBuffer(Queue,
                                                          buffer,
                                                          true,
                                                          flags,
                                                          (UIntPtr)0,
                                                          (UIntPtr)size,
                                                          0,
                                                          Span <IntPtr> .Empty,
                                                          Span <IntPtr> .Empty,
                                                          Span <int> .Empty
                                                          );

            var ptr = new IntPtr(result);

            if (ptr == IntPtr.Zero)
            {
                throw new Exception($"Failed to map device memory!");
            }

            return(ptr);
        }