private unsafe Dictionary <IntPtr, ReadOnlyMemory <byte> > GetBinaries() { var sortedDevices = _programInfoHelper.GetValues <IntPtr>(ProgramInfoParameter.Devices); if (!sortedDevices.Any()) { return(new Dictionary <IntPtr, ReadOnlyMemory <byte> >()); } //This will throw and OutOfHostMemory-Exception when build was not successfull! //TODO var binarySizes = _programInfoHelper.GetValues <ulong>(ProgramInfoParameter.BinarySizes); var memorySegments = binarySizes.Select(size => new ReadOnlyMemory <byte>(new byte[size])).ToArray(); var handles = memorySegments.Select(mem => mem.Pin()).ToArray(); OpenClErrorCode error; fixed(void *ptr = handles.Select(handle => new IntPtr(handle.Pointer)).ToArray()) { error = _programApi.clGetProgramInfo(_program.Id, ProgramInfoParameter.Binaries, (uint)(sizeof(IntPtr) * binarySizes.Length), new IntPtr(ptr), out _); } //Unpin the Memory handles foreach (var handle in handles) { handle.Dispose(); } error.ThrowOnError(); return(sortedDevices.Zip(memorySegments, (device, memory) => new KeyValuePair <IntPtr, ReadOnlyMemory <byte> >(device, memory) ).ToDictionary(k => k.Key, v => v.Value)); }
internal Device(Platform platform, IntPtr deviceId, IDeviceApi deviceApi) { Platform = platform ?? throw new ArgumentNullException(nameof(platform)); _deviceApi = deviceApi ?? throw new ArgumentNullException(nameof(deviceApi)); Id = deviceId; _deviceInfoHelper = new InfoHelper <DeviceInfoParameter>(this, _deviceApi.clGetDeviceInfo); Name = _deviceInfoHelper.GetStringValue(DeviceInfoParameter.Name); Type = _deviceInfoHelper.GetValue <DeviceType>(DeviceInfoParameter.Type); VendorId = _deviceInfoHelper.GetValue <uint>(DeviceInfoParameter.VendorId); MaxComputeUnits = _deviceInfoHelper.GetValue <uint>(DeviceInfoParameter.MaxComputeUnits); MaxWorkItemDimensions = _deviceInfoHelper.GetValue <uint>(DeviceInfoParameter.MaxWorkItemDimensions); MaxWorkGroupSize = _deviceInfoHelper.GetValue <uint>(DeviceInfoParameter.MaxWorkGroupSize); MaxWorkItemSizes = _deviceInfoHelper.GetValues <ulong>(DeviceInfoParameter.MaxWorkItemSizes); //TODO: Get bit width of size_t from AddressBits - property //From enqueueNDRangeKernel: The sizeof(size_t) for a device can be determined using CL_DEVICE_ADDRESS_BITS MaxClockFrequency = _deviceInfoHelper.GetValue <uint>(DeviceInfoParameter.MaxClockFrequency); GlobalMemorySize = _deviceInfoHelper.GetValue <ulong>(DeviceInfoParameter.GlobalMemSize); MaxConstantArgs = _deviceInfoHelper.GetValue <uint>(DeviceInfoParameter.MaxConstantArgs); AddressBits = _deviceInfoHelper.GetValue <uint>(DeviceInfoParameter.AddressBits); Vendor = _deviceInfoHelper.GetStringValue(DeviceInfoParameter.Vendor); PreferredVectorWidthChar = _deviceInfoHelper.GetValue <uint>(DeviceInfoParameter.PreferredVectorWidthChar); PreferredVectorWidthDouble = _deviceInfoHelper.GetValue <uint>(DeviceInfoParameter.PreferredVectorWidthDouble); PreferredVectorWidthFloat = _deviceInfoHelper.GetValue <uint>(DeviceInfoParameter.PreferredVectorWidthFloat); PreferredVectorWidthHalf = _deviceInfoHelper.GetValue <uint>(DeviceInfoParameter.PreferredVectorWidthHalf); PreferredVectorWidthInt = _deviceInfoHelper.GetValue <uint>(DeviceInfoParameter.PreferredVectorWidthInt); PreferredVectorWidthLong = _deviceInfoHelper.GetValue <uint>(DeviceInfoParameter.PreferredVectorWidthLong); PreferredVectorWidthShort = _deviceInfoHelper.GetValue <uint>(DeviceInfoParameter.PreferredVectorWidthShort); NativeVectorWidthChar = _deviceInfoHelper.GetValue <uint>(DeviceInfoParameter.NativeVectorWidthChar); NativeVectorWidthDouble = _deviceInfoHelper.GetValue <uint>(DeviceInfoParameter.NativeVectorWidthDouble); NativeVectorWidthFloat = _deviceInfoHelper.GetValue <uint>(DeviceInfoParameter.NativeVectorWidthFloat); NativeVectorWidthHalf = _deviceInfoHelper.GetValue <uint>(DeviceInfoParameter.NativeVectorWidthHalf); NativeVectorWidthInt = _deviceInfoHelper.GetValue <uint>(DeviceInfoParameter.NativeVectorWidthInt); NativeVectorWidthLong = _deviceInfoHelper.GetValue <uint>(DeviceInfoParameter.NativeVectorWidthLong); NativeVectorWidthShort = _deviceInfoHelper.GetValue <uint>(DeviceInfoParameter.NativeVectorWidthShort); Image2DMaxHeight = _deviceInfoHelper.GetValue <ulong>(DeviceInfoParameter.Image2DMaxHeight); Image2DMaxWidth = _deviceInfoHelper.GetValue <ulong>(DeviceInfoParameter.Image2DMaxWidth); Image3DMaxHeight = _deviceInfoHelper.GetValue <ulong>(DeviceInfoParameter.Image3DMaxHeight); Image3DMaxWidth = _deviceInfoHelper.GetValue <ulong>(DeviceInfoParameter.Image3DMaxWidth); Image3DMaxDepth = _deviceInfoHelper.GetValue <ulong>(DeviceInfoParameter.Image3DMaxDepth); MaxReadImageArgs = _deviceInfoHelper.GetValue <uint>(DeviceInfoParameter.MaxReadImageArgs); MaxWriteImageArgs = _deviceInfoHelper.GetValue <uint>(DeviceInfoParameter.MaxWriteImageArgs); ImageSupport = _deviceInfoHelper.GetValue <bool>(DeviceInfoParameter.ImageSupport); MaxSamplers = _deviceInfoHelper.GetValue <uint>(DeviceInfoParameter.MaxSamplers); MaxParameterSize = _deviceInfoHelper.GetValue <ulong>(DeviceInfoParameter.MaxParameterSize); MemBaseAddressAlign = _deviceInfoHelper.GetValue <uint>(DeviceInfoParameter.MemBaseAddrAlign); MinDataTypeAlignSize = _deviceInfoHelper.GetValue <uint>(DeviceInfoParameter.MinDataTypeAlignSize); MaxMemAllocSize = _deviceInfoHelper.GetValue <ulong>(DeviceInfoParameter.MaxMemAllocSize); GlobalMemCacheType = _deviceInfoHelper.GetValue <CacheType>(DeviceInfoParameter.GlobalMemCacheType); GlobalMemCacheSize = _deviceInfoHelper.GetValue <ulong>(DeviceInfoParameter.GlobalMemCacheSize); GlobalMemCacheLineSize = _deviceInfoHelper.GetValue <uint>(DeviceInfoParameter.GlobalMemCachelineSize); MaxConstantBufferSize = _deviceInfoHelper.GetValue <ulong>(DeviceInfoParameter.MaxConstantBufferSize); LocalMemorySize = _deviceInfoHelper.GetValue <ulong>(DeviceInfoParameter.LocalMemSize); LocalMemoryType = _deviceInfoHelper.GetValue <LocalMemoryType>(DeviceInfoParameter.LocalMemType); ErrorCorrectionSupport = _deviceInfoHelper.GetValue <bool>(DeviceInfoParameter.ErrorCorrectionSupport); ProfilingTimerResolution = _deviceInfoHelper.GetValue <ulong>(DeviceInfoParameter.ProfilingTimerResolution); EndianLittle = _deviceInfoHelper.GetValue <bool>(DeviceInfoParameter.EndianLittle); DriverVersion = _deviceInfoHelper.GetStringValue(DeviceInfoParameter.DriverVersion); OpenClCVersion = _deviceInfoHelper.GetStringValue(DeviceInfoParameter.OpenClCVersion); HostUnifiedMemory = _deviceInfoHelper.GetValue <bool>(DeviceInfoParameter.HostUnifiedMemory); ExecutionCapabilities = _deviceInfoHelper.GetValue <ExecutionCapabilities>(DeviceInfoParameter.ExecutionCapabilities); QueueProperties = _deviceInfoHelper.GetValue <CommandQueueProperties>(DeviceInfoParameter.QueueProperties); SinglePrecisionFloatConfigurations = _deviceInfoHelper.GetValue <FloatConfigurations>(DeviceInfoParameter.SingleFpConfig); //Is double precision supported if (NativeVectorWidthDouble != 0) { DoublePrecisionFloatConfigurations = _deviceInfoHelper.GetValue <FloatConfigurations>(DeviceInfoParameter.DoubleFpConfig); } //Is half precision supported if (NativeVectorWidthHalf != 0) { HalfPrecisionFloatConfigurations = _deviceInfoHelper.GetValue <FloatConfigurations>(DeviceInfoParameter.HalfFpConfig); } }