Exemplo n.º 1
0
        internal unsafe Program(IOpenClApi api, Context context, IReadOnlyDictionary <Device, ReadOnlyMemory <byte> > deviceBinaries)
        {
            _api    = api ?? throw new ArgumentNullException(nameof(api));
            Context = context ?? throw new ArgumentNullException(nameof(context));
            if (deviceBinaries == null)
            {
                throw new ArgumentNullException(nameof(deviceBinaries));
            }

            var handles = deviceBinaries.Values.Select(f => f.Pin()).ToArray();

            var binaryStatus = new OpenClErrorCode[deviceBinaries.Count];
            var id           = api.ProgramApi.clCreateProgramWithBinary(context.Id, (uint)deviceBinaries.Count,
                                                                        deviceBinaries.Select(bin => bin.Key.Id).ToArray(),
                                                                        deviceBinaries.Select(bin => (uint)bin.Value.Length).ToArray(),
                                                                        handles.Select(h => new IntPtr(h.Pointer)).ToArray(), binaryStatus, out var errorCode);

            foreach (var hdl in handles)
            {
                hdl.Dispose();
            }

            errorCode.ThrowOnError();
            Id = id;

            //TODO: Validate binaryStatus?

            _builds = new Dictionary <Device, BuildInfo>(deviceBinaries.Zip(binaryStatus, (binary, status) =>
                                                                            new KeyValuePair <Device, BuildInfo>(binary.Key, new BuildInfo(status == OpenClErrorCode.Success ? BuildStatus.Success : BuildStatus.Error, binary.Value))
                                                                            ).ToDictionary(k => k.Key, v => v.Value));

            _attachedKernels = new List <Kernel>();
        }
 public static void ThrowOnError(this OpenClErrorCode error)
 {
     //TODO: Decide which exception to throw based on errorcode
     if (error != OpenClErrorCode.Success)
     {
         throw new ClCoreException(error);
     }
 }
Exemplo n.º 3
0
        public IntPtr clCreateCommandQueue(IntPtr context, IntPtr device, CommandQueueProperties properties,
                                           out OpenClErrorCode errorCode)
        {
            errorCode = clCreateCommandQueueErrorCode ?? OpenClErrorCode.Success;
            var id = clCreateCommandQueueResult ?? new IntPtr(1);

            if (errorCode == OpenClErrorCode.Success)
            {
                FakeCommandQueues[id] = new FakeCommandQueue(context, device, properties);
            }

            return(id);
        }
Exemplo n.º 4
0
        public IntPtr clCreateContext(IntPtr properties, uint numDevices, IntPtr[] deviceIds, IntPtr pfnNotify,
                                      IntPtr userData,
                                      out OpenClErrorCode errorCode)
        {
            errorCode = ClCreateContextErrorCode ?? OpenClErrorCode.Success;
            var id = clCreateContextResult ?? new IntPtr(1);

            if (errorCode == OpenClErrorCode.Success)
            {
                FakeContexts[id] = new FakeContext(properties, deviceIds, pfnNotify);
            }

            return(id);
        }
Exemplo n.º 5
0
        public IntPtr clCreateKernel(IntPtr program, string kernelName, out OpenClErrorCode errorCodeRet)
        {
            errorCodeRet = clCreateKernelErrorCode ?? OpenClErrorCode.Success;

            if (errorCodeRet != OpenClErrorCode.Success)
            {
                return(IntPtr.Zero);
            }

            var id = clCreateKernelReturn ?? new IntPtr(1);

            FakeKernels[id] = new FakeKernel(program, kernelName);

            return(id);
        }
Exemplo n.º 6
0
        public IntPtr clCreateSubBuffer(IntPtr buffer, MemoryFlags flags, BufferCreateType bufferCreateType, IntPtr bufferCreateInfo,
                                        out OpenClErrorCode errorCode)
        {
            errorCode = clCreateSubBufferErrorCode ?? OpenClErrorCode.Success;

            if (errorCode == OpenClErrorCode.Success)
            {
                var id                    = clCreateSubBufferResult ?? new IntPtr(1);
                var regionObject          = Marshal.PtrToStructure <BufferRegion>(bufferCreateInfo);
                const MemoryFlags memMask = MemoryFlags.AllocHostPointer | MemoryFlags.UseHostPointer | MemoryFlags.CopyHostPointer;

                var parent     = FakeMemoryObjects[buffer];
                var validFlags = (parent.Flags & (memMask)) | flags;

                FakeMemoryObjects[id] = new FakeMemoryObject(regionObject.Size, validFlags, parent.HostPointer);
                return(id);
            }

            return(IntPtr.Zero);
        }
Exemplo n.º 7
0
 public static extern IntPtr clCreateSubBuffer(IntPtr buffer, MemoryFlags flags,
                                               BufferCreateType bufferCreateType, IntPtr bufferCreateInfo,
                                               out OpenClErrorCode errorCode);
Exemplo n.º 8
0
 public static extern IntPtr clCreateProgramWithBinary(IntPtr context, uint numDevices, IntPtr[] deviceList, uint[] lengths,
                                                       IntPtr[] binaries, OpenClErrorCode[] binaryStatus, out OpenClErrorCode errorCodeRet);
Exemplo n.º 9
0
 public static extern IntPtr clCreateKernel(IntPtr program, [MarshalAs(UnmanagedType.LPStr)] string kernelName, out OpenClErrorCode errorCodeRet);
Exemplo n.º 10
0
 IntPtr IKernelApi.clCreateKernel(IntPtr program, string kernelName, out OpenClErrorCode errorCodeRet)
 {
     return(clCreateKernel(program, kernelName, out errorCodeRet));
 }
Exemplo n.º 11
0
 public static extern IntPtr clCreateProgramWithSource(IntPtr context, uint count, string[] strings, uint[] lengths,
                                                       out OpenClErrorCode errorCodeRet);
Exemplo n.º 12
0
 public static extern IntPtr clCreateContext(IntPtr properties, uint numDevices, IntPtr[] deviceIds,
                                             IntPtr pfnNotify, IntPtr userData, out OpenClErrorCode errorCode);
Exemplo n.º 13
0
 public static extern IntPtr clCreateBuffer(IntPtr context, MemoryFlags flags, ulong size, IntPtr hostPtr,
                                            out OpenClErrorCode errorCode);
Exemplo n.º 14
0
 public static extern IntPtr clCreateUserEvent(IntPtr context, out OpenClErrorCode errorCodeRet);
Exemplo n.º 15
0
 IntPtr IEventApi.clCreateUserEvent(IntPtr context, out OpenClErrorCode errorCodeRet)
 {
     return(clCreateUserEvent(context, out errorCodeRet));
 }
Exemplo n.º 16
0
 public IntPtr clCreateUserEvent(IntPtr context, out OpenClErrorCode errorCodeRet)
 {
     errorCodeRet = clCreateUserEventErrorCode ?? OpenClErrorCode.Success;
     return(clCreateUserEventReturn ?? new IntPtr(1));
 }
Exemplo n.º 17
0
 IntPtr IProgramApi.clCreateProgramWithSource(IntPtr context, uint count, string[] strings, uint[] lengths,
                                              out OpenClErrorCode errorCodeRet)
 {
     return(clCreateProgramWithSource(context, count, strings, lengths, out errorCodeRet));
 }
 public ClCoreException(OpenClErrorCode openClErrorCode) : this(openClErrorCode.ToString())
 {
     OpenClErrorCode = openClErrorCode;
 }
Exemplo n.º 19
0
        public IntPtr clCreateBuffer(IntPtr context, MemoryFlags flags, ulong size, IntPtr hostPtr, out OpenClErrorCode errorCode)
        {
            errorCode = clCreateBufferErrorCode ?? OpenClErrorCode.Success;
            var id = clCreateBufferResult ?? IntPtr.Zero;

            if (errorCode == OpenClErrorCode.Success)
            {
                FakeMemoryObjects[id] = new FakeMemoryObject(size, flags, hostPtr);
                return(id);
            }

            return(IntPtr.Zero);
        }
Exemplo n.º 20
0
 IntPtr IBufferApi.clCreateSubBuffer(IntPtr buffer, MemoryFlags flags, BufferCreateType bufferCreateType, IntPtr bufferCreateInfo,
                                     out OpenClErrorCode errorCode)
 {
     return(clCreateSubBuffer(buffer, flags, bufferCreateType, bufferCreateInfo, out errorCode));
 }
Exemplo n.º 21
0
 IntPtr IBufferApi.clCreateBuffer(IntPtr context, MemoryFlags flags, ulong size, IntPtr hostPtr, out OpenClErrorCode errorCode)
 {
     return(clCreateBuffer(context, flags, size, hostPtr, out errorCode));
 }
Exemplo n.º 22
0
        public static OpenClErrorCode GetInfo <TFake, TInfoParameter>(this TFake fake, TInfoParameter paramName, uint paramValueSize, IntPtr paramValue, out uint paramValueSizeRet, OpenClErrorCode errorCode = OpenClErrorCode.Success)
            where TFake : IInfoProvider <TInfoParameter>
            where TInfoParameter : Enum
        {
            if (errorCode != OpenClErrorCode.Success)
            {
                paramValueSizeRet = 0;
                return(errorCode);
            }

            //First call, obtain size
            if (paramValueSize == 0)
            {
                paramValueSizeRet = (uint)fake.Infos[paramName].Length;
                return(OpenClErrorCode.Success);
            }

            fake.Infos.CopyTo(paramName, paramValue, (int)paramValueSize);
            paramValueSizeRet = paramValueSize;
            return(OpenClErrorCode.Success);
        }
Exemplo n.º 23
0
 IntPtr IContextApi.clCreateContext(IntPtr properties, uint numDevices, IntPtr[] deviceIds, IntPtr pfnNotify, IntPtr userData,
                                    out OpenClErrorCode errorCode)
 {
     return(clCreateContext(properties, numDevices, deviceIds, pfnNotify, userData, out errorCode));
 }
Exemplo n.º 24
0
 IntPtr ICommandQueueApi.clCreateCommandQueue(IntPtr context, IntPtr device, CommandQueueProperties properties, out OpenClErrorCode errorCode)
 {
     return(clCreateCommandQueue(context, device, properties, out errorCode));
 }
Exemplo n.º 25
0
 public static extern IntPtr clCreateCommandQueue(IntPtr context, IntPtr device, CommandQueueProperties properties,
                                                  out OpenClErrorCode errorCode);
Exemplo n.º 26
0
 IntPtr IProgramApi.clCreateProgramWithBinary(IntPtr context, uint numDevices, IntPtr[] deviceList, uint[] lengths,
                                              IntPtr[] binaries, OpenClErrorCode[] binaryStatus, out OpenClErrorCode errorCodeRet)
 {
     return(clCreateProgramWithBinary(context, numDevices, deviceList, lengths, binaries, binaryStatus, out errorCodeRet));
 }