コード例 #1
0
ファイル: Program.cs プロジェクト: peterwurzinger/CL.Core
        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>();
        }
コード例 #2
0
        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>();
        }
コード例 #3
0
        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);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: peterwurzinger/CL.Core
        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>();
        }
コード例 #5
0
        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();
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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();
        }
コード例 #8
0
ファイル: Buffer.cs プロジェクト: peterwurzinger/CL.Core
 internal Buffer(IOpenClApi api, Context context, IntPtr id)
     : this(api, context, id, null)
 {
 }
コード例 #9
0
ファイル: Buffer.cs プロジェクト: peterwurzinger/CL.Core
 internal Buffer(IOpenClApi api, Context context, IntPtr id, MemoryHandle?hostMemory = null)
     : base(api, context, id, hostMemory)
 {
     _attachedSubBuffers = new List <SubBuffer <T> >();
 }
コード例 #10
0
 internal BufferMemoryUsageConfiguration(IOpenClApi api, Context context, Action <Buffer <T> > memoryObjectCreatedCallback, MemoryFlags flags, Memory <T> hostMemory)
     : base(api, context, memoryObjectCreatedCallback, flags)
 {
     _hostMemory = hostMemory;
 }
コード例 #11
0
 public FakeBufferConfigurationStep(IOpenClApi api, Context context, Action <Buffer <T> > bufferCreatedCallback)
     : base(api, context, bufferCreatedCallback)
 {
 }
コード例 #12
0
 public PlatformFactory(IOpenClApi openClApi)
 {
     _openClApi = openClApi ?? throw new ArgumentNullException(nameof(openClApi));
 }
コード例 #13
0
 protected internal BufferConfigurationStep(IOpenClApi api, Context context, Action <Buffer <T> > memoryObjectCreatedCallback)
     : base(api, context, memoryObjectCreatedCallback)
 {
 }
コード例 #14
0
 internal SubBufferMemoryBehaviorConfiguration(IOpenClApi api, Context context, Action <SubBuffer <T> > memoryObjectCreatedCallback, Buffer <T> parent, BufferRegion region)
     : base(api, context, memoryObjectCreatedCallback)
 {
     _parent = parent;
     _region = region;
 }
コード例 #15
0
 internal BufferBase(IOpenClApi api, Context context, IntPtr id, MemoryHandle?hostMemory = null)
     : base(api, context, id, hostMemory)
 {
     Length = Size / (uint)Marshal.SizeOf <T>();
 }
コード例 #16
0
 // ReSharper disable once SuggestBaseTypeForParameter
 internal SubBuffer(IOpenClApi api, Buffer <T> parent, IntPtr id)
     : base(api, parent?.Context, id)
 {
     Parent = parent;
 }
コード例 #17
0
ファイル: Event.cs プロジェクト: peterwurzinger/CL.Core
 internal Event(IOpenClApi api, IntPtr evt)
     : base(api, evt, true)
 {
 }
コード例 #18
0
 internal SubBufferStubConfiguration(IOpenClApi api, Context context, Action <SubBuffer <T> > memoryObjectCreatedCallback, Buffer <T> parent)
     : base(api, context, memoryObjectCreatedCallback)
 {
     _parent = parent ?? throw new ArgumentNullException(nameof(parent));
 }
コード例 #19
0
 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;
 }
コード例 #20
0
 internal BufferMemoryAllocationConfiguration(IOpenClApi api, Context context, Action <Buffer <T> > memoryObjectCreatedCallback, MemoryFlags flags, ulong numElements)
     : base(api, context, memoryObjectCreatedCallback, flags)
 {
     _numElements = numElements;
 }
コード例 #21
0
 internal BufferMemoryBehaviorConfiguration(IOpenClApi api, Context context, Action <Buffer <T> > memoryObjectCreatedCallback, MemoryFlags flags)
     : base(api, context, memoryObjectCreatedCallback)
 {
     Flags = flags;
 }
コード例 #22
0
 internal SuspiciousPlatform(IntPtr platformId, IOpenClApi openClApi) : base(platformId, openClApi)
 {
 }