Exemplo n.º 1
0
        private void AsyncBuildCallback(IntPtr program, IntPtr userData)
        {
            _delegateHandle.Free();

            var buildErrors = new List <ProgramBuildException>();
            var builds      = new Dictionary <Device, BuildInfo>();

            var availableBinaries = GetBinaries();

            foreach (var device in _devices)
            {
                var buildInfoHelper = new InfoHelper <ProgramBuildInfoParameter>(device, BuildInfoFuncCurried);
                var status          = buildInfoHelper.GetValue <BuildStatus>(ProgramBuildInfoParameter.Status);
                var log             = buildInfoHelper.GetStringValue(ProgramBuildInfoParameter.Log);
                var options         = buildInfoHelper.GetStringValue(ProgramBuildInfoParameter.Options);

                if (status == BuildStatus.Error)
                {
                    buildErrors.Add(new ProgramBuildException(_program, device, log));
                }

                builds[device] = new BuildInfo(status, log, options, availableBinaries[device.Id]);
            }

            if (buildErrors.Any())
            {
                _taskCompletionSource.SetException(buildErrors);
            }
            else
            {
                _taskCompletionSource.SetResult(builds);
            }
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
0
        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);
            }
        }