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>(); }
internal Context(IOpenClApi openClApi, IReadOnlyCollection <Device> devices) { _openClApi = openClApi ?? throw new ArgumentNullException(nameof(openClApi)); if (devices == null) { throw new ArgumentNullException(nameof(devices)); } if (devices.Count == 0) { throw new ArgumentException("Value cannot be an empty collection.", nameof(devices)); } if (devices.GroupBy(d => d.Platform.Id).Count() > 1) { throw new ClCoreException("Contexts containing devices from multiple platforms are not supported."); } Devices = devices; var callbackDelegate = (ContextErrorDelegate)NotificationCallbackProxy; _notificationHandle = GCHandle.Alloc(callbackDelegate); var fp = Marshal.GetFunctionPointerForDelegate(callbackDelegate); var id = _openClApi.ContextApi.clCreateContext(IntPtr.Zero, (uint)devices.Count, devices.Select(device => device.Id).ToArray(), fp, IntPtr.Zero, out var error); error.ThrowOnError(); Id = id; _attachedCommandQueues = new List <CommandQueue>(); _attachedMemoryObjects = new List <MemoryObject>(); _attachedProgramObjects = new List <Program>(); }
protected MemoryObject(IOpenClApi api, Context context, IntPtr id, MemoryHandle?hostMemory = null) { Api = api ?? throw new ArgumentNullException(nameof(api)); Context = context ?? throw new ArgumentNullException(nameof(context)); Id = id; _hostMemory = hostMemory; var infoHelper = new InfoHelper <MemoryObjectInfoParameter>(this, Api.BufferApi.clGetMemObjectInfo); Flags = infoHelper.GetValue <MemoryFlags>(MemoryObjectInfoParameter.Flags); Size = infoHelper.GetValue <ulong>(MemoryObjectInfoParameter.Size); }
internal Program(IOpenClApi api, Context context, string[] sources) { _api = api ?? throw new ArgumentNullException(nameof(api)); Context = context ?? throw new ArgumentNullException(nameof(context)); if (sources == null) { throw new ArgumentNullException(nameof(sources)); } var id = api.ProgramApi.clCreateProgramWithSource(context.Id, (uint)sources.Length, sources, sources.Select(source => (uint)source.Length).ToArray(), out var error); error.ThrowOnError(); Id = id; _builds = new Dictionary <Device, BuildInfo>(); _attachedKernels = new List <Kernel>(); }
protected EventBase(IOpenClApi api, IntPtr evt, TResult result) { Api = api ?? throw new ArgumentNullException(nameof(api)); Id = evt; _result = result; _infoHelper = new InfoHelper <EventInfoParameter>(this, api.EventApi.clGetEventInfo); api.EventApi.clRetainEvent(evt).ThrowOnError(); TaskCompletionSource = new TaskCompletionSource <TResult>(); var callbackDelegate = new EventCallback(Callback); _handle = GCHandle.Alloc(callbackDelegate); var fp = Marshal.GetFunctionPointerForDelegate(callbackDelegate); api.EventApi.clSetEventCallback(evt, EventCommandExecutionStatus.Complete, fp, IntPtr.Zero).ThrowOnError(); }
internal Kernel(IOpenClApi api, Program program, string name) { _api = api ?? throw new ArgumentNullException(nameof(api)); Program = program ?? throw new ArgumentNullException(nameof(program)); if (string.IsNullOrEmpty(name)) { throw new ArgumentException("Value cannot be null or empty.", nameof(name)); } Name = name; var id = _api.KernelApi.clCreateKernel(program.Id, name, out var error); error.ThrowOnError(); Id = id; var infoHelper = new InfoHelper <KernelInfoParameter>(this, _api.KernelApi.clGetKernelInfo); NumberOfArguments = infoHelper.GetValue <uint>(KernelInfoParameter.NumberOfArguments); }
internal Platform(IntPtr platformId, IOpenClApi openClApi) { _openClApi = openClApi ?? throw new ArgumentNullException(nameof(openClApi)); Id = platformId; var platformInfoHelper = new InfoHelper <PlatformInfoParameter>(this, openClApi.PlatformApi.clGetPlatformInfo); Profile = platformInfoHelper.GetStringValue(PlatformInfoParameter.Profile); Version = platformInfoHelper.GetStringValue(PlatformInfoParameter.Version); Name = platformInfoHelper.GetStringValue(PlatformInfoParameter.Name); Vendor = platformInfoHelper.GetStringValue(PlatformInfoParameter.Vendor); Extensions = platformInfoHelper.GetStringValue(PlatformInfoParameter.Extensions).Split(' '); var errorCode = openClApi.DeviceApi.clGetDeviceIDs(platformId, DeviceType.All, 0, null, out var numDevices); errorCode.ThrowOnError(); var deviceIds = new IntPtr[numDevices]; errorCode = openClApi.DeviceApi.clGetDeviceIDs(platformId, DeviceType.All, numDevices, deviceIds, out _); errorCode.ThrowOnError(); Devices = deviceIds.Select(deviceId => new Device(this, deviceId, openClApi.DeviceApi)).ToList().AsReadOnly(); }
internal Buffer(IOpenClApi api, Context context, IntPtr id) : this(api, context, id, null) { }
internal Buffer(IOpenClApi api, Context context, IntPtr id, MemoryHandle?hostMemory = null) : base(api, context, id, hostMemory) { _attachedSubBuffers = new List <SubBuffer <T> >(); }
internal BufferMemoryUsageConfiguration(IOpenClApi api, Context context, Action <Buffer <T> > memoryObjectCreatedCallback, MemoryFlags flags, Memory <T> hostMemory) : base(api, context, memoryObjectCreatedCallback, flags) { _hostMemory = hostMemory; }
public FakeBufferConfigurationStep(IOpenClApi api, Context context, Action <Buffer <T> > bufferCreatedCallback) : base(api, context, bufferCreatedCallback) { }
public PlatformFactory(IOpenClApi openClApi) { _openClApi = openClApi ?? throw new ArgumentNullException(nameof(openClApi)); }
protected internal BufferConfigurationStep(IOpenClApi api, Context context, Action <Buffer <T> > memoryObjectCreatedCallback) : base(api, context, memoryObjectCreatedCallback) { }
internal SubBufferMemoryBehaviorConfiguration(IOpenClApi api, Context context, Action <SubBuffer <T> > memoryObjectCreatedCallback, Buffer <T> parent, BufferRegion region) : base(api, context, memoryObjectCreatedCallback) { _parent = parent; _region = region; }
internal BufferBase(IOpenClApi api, Context context, IntPtr id, MemoryHandle?hostMemory = null) : base(api, context, id, hostMemory) { Length = Size / (uint)Marshal.SizeOf <T>(); }
// ReSharper disable once SuggestBaseTypeForParameter internal SubBuffer(IOpenClApi api, Buffer <T> parent, IntPtr id) : base(api, parent?.Context, id) { Parent = parent; }
internal Event(IOpenClApi api, IntPtr evt) : base(api, evt, true) { }
internal SubBufferStubConfiguration(IOpenClApi api, Context context, Action <SubBuffer <T> > memoryObjectCreatedCallback, Buffer <T> parent) : base(api, context, memoryObjectCreatedCallback) { _parent = parent ?? throw new ArgumentNullException(nameof(parent)); }
protected internal ConfigurationStep(IOpenClApi api, Context context, Action <TMemoryObject> memoryObjectCreatedCallback) { Api = api ?? throw new ArgumentNullException(nameof(api)); Context = context ?? throw new ArgumentNullException(nameof(context)); MemoryObjectCreatedCallback = memoryObjectCreatedCallback; }
internal BufferMemoryAllocationConfiguration(IOpenClApi api, Context context, Action <Buffer <T> > memoryObjectCreatedCallback, MemoryFlags flags, ulong numElements) : base(api, context, memoryObjectCreatedCallback, flags) { _numElements = numElements; }
internal BufferMemoryBehaviorConfiguration(IOpenClApi api, Context context, Action <Buffer <T> > memoryObjectCreatedCallback, MemoryFlags flags) : base(api, context, memoryObjectCreatedCallback) { Flags = flags; }
internal SuspiciousPlatform(IntPtr platformId, IOpenClApi openClApi) : base(platformId, openClApi) { }