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); } }
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); }
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); }
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); }
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); }
public static extern IntPtr clCreateSubBuffer(IntPtr buffer, MemoryFlags flags, BufferCreateType bufferCreateType, IntPtr bufferCreateInfo, out OpenClErrorCode errorCode);
public static extern IntPtr clCreateProgramWithBinary(IntPtr context, uint numDevices, IntPtr[] deviceList, uint[] lengths, IntPtr[] binaries, OpenClErrorCode[] binaryStatus, out OpenClErrorCode errorCodeRet);
public static extern IntPtr clCreateKernel(IntPtr program, [MarshalAs(UnmanagedType.LPStr)] string kernelName, out OpenClErrorCode errorCodeRet);
IntPtr IKernelApi.clCreateKernel(IntPtr program, string kernelName, out OpenClErrorCode errorCodeRet) { return(clCreateKernel(program, kernelName, out errorCodeRet)); }
public static extern IntPtr clCreateProgramWithSource(IntPtr context, uint count, string[] strings, uint[] lengths, out OpenClErrorCode errorCodeRet);
public static extern IntPtr clCreateContext(IntPtr properties, uint numDevices, IntPtr[] deviceIds, IntPtr pfnNotify, IntPtr userData, out OpenClErrorCode errorCode);
public static extern IntPtr clCreateBuffer(IntPtr context, MemoryFlags flags, ulong size, IntPtr hostPtr, out OpenClErrorCode errorCode);
public static extern IntPtr clCreateUserEvent(IntPtr context, out OpenClErrorCode errorCodeRet);
IntPtr IEventApi.clCreateUserEvent(IntPtr context, out OpenClErrorCode errorCodeRet) { return(clCreateUserEvent(context, out errorCodeRet)); }
public IntPtr clCreateUserEvent(IntPtr context, out OpenClErrorCode errorCodeRet) { errorCodeRet = clCreateUserEventErrorCode ?? OpenClErrorCode.Success; return(clCreateUserEventReturn ?? new IntPtr(1)); }
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; }
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); }
IntPtr IBufferApi.clCreateSubBuffer(IntPtr buffer, MemoryFlags flags, BufferCreateType bufferCreateType, IntPtr bufferCreateInfo, out OpenClErrorCode errorCode) { return(clCreateSubBuffer(buffer, flags, bufferCreateType, bufferCreateInfo, out errorCode)); }
IntPtr IBufferApi.clCreateBuffer(IntPtr context, MemoryFlags flags, ulong size, IntPtr hostPtr, out OpenClErrorCode errorCode) { return(clCreateBuffer(context, flags, size, hostPtr, out errorCode)); }
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); }
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)); }
IntPtr ICommandQueueApi.clCreateCommandQueue(IntPtr context, IntPtr device, CommandQueueProperties properties, out OpenClErrorCode errorCode) { return(clCreateCommandQueue(context, device, properties, out errorCode)); }
public static extern IntPtr clCreateCommandQueue(IntPtr context, IntPtr device, CommandQueueProperties properties, out OpenClErrorCode errorCode);
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)); }