extern internal static ComputeErrorCode GetProgramBuildInfo(
     CLProgramHandle program,
     CLDeviceHandle device,
     ComputeProgramBuildInfo param_name,
     IntPtr param_value_size,
     IntPtr param_value,
     out IntPtr param_value_size_ret);
 extern internal static ComputeErrorCode GetKernelWorkGroupInfo(
     CLKernelHandle kernel,
     CLDeviceHandle device,
     ComputeKernelWorkGroupInfo param_name,
     IntPtr param_value_size,
     IntPtr param_value,
     out IntPtr param_value_size_ret);
Exemple #3
0
        internal OpenCLDevice(OpenCLPlatform platform, CLDeviceHandle handle)
        {
            Handle = handle;
            SetID(Handle.Value);

            this.Platform = platform;
        }
Exemple #4
0
        public GPURadixSort(
            ComputeCommandQueue commandQue,
            ComputeContext context,
            ComputeDevice device
            )
        {
            gpuConstants   = new GPUConstants();
            gpuConstants.L = radix_BitsL;
            gpuConstants.numGroupsPerBlock = NumGroupsPerBlock;
            gpuConstants.R = R;
            gpuConstants.numThreadsPerGroup = numThreadsPerBlock / NumGroupsPerBlock;
            gpuConstants.numThreadsPerBlock = numThreadsPerBlock;
            gpuConstants.numBlocks          = numBlocks;
            gpuConstants.numRadices         = num_Radices;
            gpuConstants.numRadicesPerBlock = num_Radices / numBlocks;
            gpuConstants.bitMask            = BIT_MASK_START;
            counters.Initialize();
            ComputeErrorCode error;

            cxGPUContext   = context.Handle;
            cqCommandQueue = commandQue.Handle;
            _device        = device.Handle;
            //Create a command queue, where all of the commands for execution will be added

            /*cqCommandQueue = CL10.CreateCommandQueue(cxGPUContext, _device, (CommandQueueProperties)0, out  error);
             * CheckErr(error, "CL10.CreateCommandQueue");*/
            string programSource = System.IO.File.ReadAllText(programPath);

            IntPtr[] progSize = new IntPtr[] { (IntPtr)programSource.Length };
            string   flags    = "-cl-fast-relaxed-math";

            ComputeProgram prog = new ComputeProgram(context, programSource);

            prog.Build(new List <ComputeDevice>()
            {
                device
            }, flags, null, IntPtr.Zero);


            if (prog.GetBuildStatus(device) != ComputeProgramBuildStatus.Success)
            {
                Debug.WriteLine(prog.GetBuildLog(device));
                throw new ArgumentException("UNABLE to build programm");
            }
            //            ComputeProgram clProgramRadix = CL10.CreateProgramWithSource(cxGPUContext, 1, new[] { programSource },progSize,
            //                out error);

            CLProgramHandle clProgramRadix = prog.Handle;



            ckSetupAndCount = CL10.CreateKernel(clProgramRadix, "SetupAndCount", out error);
            CheckErr(error, "CL10.CreateKernel");
            ckSumIt = CL10.CreateKernel(clProgramRadix, "SumIt", out error);
            CheckErr(error, "CL10.CreateKernel");
            ckReorderingKeysOnly = CL10.CreateKernel(clProgramRadix, "ReorderingKeysOnly", out error);
            CheckErr(error, "CL10.CreateKernel");
            ckReorderingKeyValue = CL10.CreateKernel(clProgramRadix, "ReorderingKeyValue", out error);
            CheckErr(error, "CL10.CreateKernel");
        }
Exemple #5
0
        internal ComputeDevice(ComputePlatform platform, CLDeviceHandle handle)
        {
            Handle = handle;
            SetID(Handle.Value);

            addressBits            = GetInfo <uint>(ComputeDeviceInfo.AddressBits);
            available              = GetBoolInfo(ComputeDeviceInfo.Available);
            compilerAvailable      = GetBoolInfo(ComputeDeviceInfo.CompilerAvailable);
            driverVersion          = GetStringInfo(ComputeDeviceInfo.DriverVersion);
            endianLittle           = GetBoolInfo(ComputeDeviceInfo.EndianLittle);
            errorCorrectionSupport = GetBoolInfo(ComputeDeviceInfo.ErrorCorrectionSupport);
            executionCapabilities  = (ComputeDeviceExecutionCapabilities)GetInfo <long>(ComputeDeviceInfo.ExecutionCapabilities);

            string extensionString = GetStringInfo(ComputeDeviceInfo.Extensions);

            extensions = new ReadOnlyCollection <string>(extensionString.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));

            globalMemoryCachelineSize = GetInfo <uint>(ComputeDeviceInfo.GlobalMemoryCachelineSize);
            globalMemoryCacheSize     = (long)GetInfo <ulong>(ComputeDeviceInfo.GlobalMemoryCacheSize);
            globalMemoryCacheType     = (ComputeDeviceMemoryCacheType)GetInfo <long>(ComputeDeviceInfo.GlobalMemoryCacheType);
            globalMemorySize          = (long)GetInfo <ulong>(ComputeDeviceInfo.GlobalMemorySize);
            image2DMaxHeight          = (long)GetInfo <IntPtr>(ComputeDeviceInfo.Image2DMaxHeight);
            image2DMaxWidth           = (long)GetInfo <IntPtr>(ComputeDeviceInfo.Image2DMaxWidth);
            image3DMaxDepth           = (long)GetInfo <IntPtr>(ComputeDeviceInfo.Image3DMaxDepth);
            image3DMaxHeight          = (long)GetInfo <IntPtr>(ComputeDeviceInfo.Image3DMaxHeight);
            image3DMaxWidth           = (long)GetInfo <IntPtr>(ComputeDeviceInfo.Image3DMaxWidth);
            imageSupport          = GetBoolInfo(ComputeDeviceInfo.ImageSupport);
            localMemorySize       = (long)GetInfo <ulong>(ComputeDeviceInfo.LocalMemorySize);
            localMemoryType       = (ComputeDeviceLocalMemoryType)GetInfo <long>(ComputeDeviceInfo.LocalMemoryType);
            maxClockFrequency     = GetInfo <uint>(ComputeDeviceInfo.MaxClockFrequency);
            maxComputeUnits       = GetInfo <uint>(ComputeDeviceInfo.MaxComputeUnits);
            maxConstantArguments  = GetInfo <uint>(ComputeDeviceInfo.MaxConstantArguments);
            maxConstantBufferSize = (long)GetInfo <ulong>(ComputeDeviceInfo.MaxConstantBufferSize);
            maxMemAllocSize       = (long)GetInfo <ulong>(ComputeDeviceInfo.MaxMemoryAllocationSize);
            maxParameterSize      = (long)GetInfo <IntPtr>(ComputeDeviceInfo.MaxParameterSize);
            maxReadImageArgs      = GetInfo <uint>(ComputeDeviceInfo.MaxReadImageArguments);
            maxSamplers           = GetInfo <uint>(ComputeDeviceInfo.MaxSamplers);
            maxWorkGroupSize      = (long)GetInfo <IntPtr>(ComputeDeviceInfo.MaxWorkGroupSize);
            maxWorkItemDimensions = GetInfo <uint>(ComputeDeviceInfo.MaxWorkItemDimensions);
            maxWorkItemSizes      = new ReadOnlyCollection <long>(ComputeTools.ConvertArray(GetArrayInfo <CLDeviceHandle, ComputeDeviceInfo, IntPtr>(Handle, ComputeDeviceInfo.MaxWorkItemSizes, CL10.GetDeviceInfo)));
            maxWriteImageArgs     = GetInfo <uint>(ComputeDeviceInfo.MaxWriteImageArguments);
            memBaseAddrAlign      = GetInfo <uint>(ComputeDeviceInfo.MemoryBaseAddressAlignment);
            minDataTypeAlignSize  = GetInfo <uint>(ComputeDeviceInfo.MinDataTypeAlignmentSize);
            name                      = GetStringInfo(ComputeDeviceInfo.Name);
            this.platform             = platform;
            preferredVectorWidthChar  = GetInfo <uint>(ComputeDeviceInfo.PreferredVectorWidthChar);
            preferredVectorWidthFloat = GetInfo <uint>(ComputeDeviceInfo.PreferredVectorWidthFloat);
            preferredVectorWidthInt   = GetInfo <uint>(ComputeDeviceInfo.PreferredVectorWidthInt);
            preferredVectorWidthLong  = GetInfo <uint>(ComputeDeviceInfo.PreferredVectorWidthLong);
            preferredVectorWidthShort = GetInfo <uint>(ComputeDeviceInfo.PreferredVectorWidthShort);
            profile                   = GetStringInfo(ComputeDeviceInfo.Profile);
            profilingTimerResolution  = (long)GetInfo <IntPtr>(ComputeDeviceInfo.ProfilingTimerResolution);
            queueProperties           = (ComputeCommandQueueFlags)GetInfo <long>(ComputeDeviceInfo.CommandQueueProperties);
            singleCapabilities        = (ComputeDeviceSingleCapabilities)GetInfo <long>(ComputeDeviceInfo.SingleFPConfig);
            type                      = (ComputeDeviceTypes)GetInfo <long>(ComputeDeviceInfo.Type);
            vendor                    = GetStringInfo(ComputeDeviceInfo.Vendor);
            vendorId                  = GetInfo <uint>(ComputeDeviceInfo.VendorId);
            version                   = GetStringInfo(ComputeDeviceInfo.Version);
        }
Exemple #6
0
        /// <summary>
        /// Gets a read-only collection of available devices on the platform.
        /// </summary>
        /// <returns> A read-only collection of the available devices on the platform. </returns>
        /// <remarks> This method resets the <c>ComputePlatform.Devices</c>. This is useful if one or more of them become unavailable (<c>ComputeDevice.Available</c> is <c>false</c>) after a device and command queues that use the device have been created and commands have been queued to them. Further calls will trigger an <c>OutOfResourcesComputeException</c> until this method is executed. You will also need to recreate any <see cref="ComputeResource"/> that was created on the no longer available device. </remarks>
        public ReadOnlyCollection <IComputeDevice> QueryDevices()
        {
            CL10.GetDeviceIDsWrapper(Handle, ComputeDeviceTypes.All, 0, null, out int handlesLength);
            var handles = new CLDeviceHandle[handlesLength];

            CL10.GetDeviceIDsWrapper(Handle, ComputeDeviceTypes.All, handlesLength, handles, out handlesLength);
            var devices = new ComputeDevice[handlesLength];

            for (int i = 0; i < handlesLength; i++)
            {
                devices[i] = new ComputeDevice(this, handles[i]);
            }
            Devices = new ReadOnlyCollection <IComputeDevice>(devices);
            return(Devices);
        }
Exemple #7
0
        ///<summary>
        ///<See cref = "ComputeDevice"/> s on the <see cref = "ComputePlatform"/>.
        ///</summary>
        ///<returns> A read-only collection of the available <see cref = "ComputeDevice"/> s on the <see cref = "ComputePlatform"/>. </returns>
        ///<c> ComputeDevice.Available </c> is <c> false </c> </remarks> This method resets the <c> ComputePlatform.Devices </c>   after see <cref = "ComputeContext"/> and <see cref = "ComputeCommandQueue"/> s that use the <see cref = "ComputeDevice"/> have been created and commands have been queued to them. Further calls will trigger an   <c> cref = "ComputeDevice"/>. </c> </c> After this method is executed.   remarks>
        public ReadOnlyCollection<ComputeDevice> QueryDevices()
        {
            int handlesLength = 0;
            ComputeErrorCode error = CL12.GetDeviceIDs(Handle, ComputeDeviceTypes.All, 0, null, out handlesLength);
            ComputeException.ThrowOnError(error);

            CLDeviceHandle[] handles = new CLDeviceHandle[handlesLength];
            error = CL12.GetDeviceIDs(Handle, ComputeDeviceTypes.All, handlesLength, handles, out handlesLength);
            ComputeException.ThrowOnError(error);

            ComputeDevice[] devices = new ComputeDevice[handlesLength];
            for (int i = 0; i < handlesLength; i++)
                devices[i] = new ComputeDevice(this, handles[i]);

            this.devices = new ReadOnlyCollection<ComputeDevice>(devices);

            return this.devices;
        }
Exemple #8
0
        internal static CLDeviceHandle[] ExtractHandles(IList <OpenCLDevice> computeObjects, out int handleCount)
        {
            if (computeObjects == null || computeObjects.Count == 0)
            {
                handleCount = 0;
                return(null);
            }

            CLDeviceHandle[] result = new CLDeviceHandle[computeObjects.Count];
            int i = 0;

            foreach (OpenCLDevice computeObj in computeObjects)
            {
                result[i] = computeObj.Handle;
                i++;
            }
            handleCount = computeObjects.Count;
            return(result);
        }
Exemple #9
0
        /// <summary>
        /// Extract device handles of <see cref="ComputeDevice"/>s
        /// </summary>
        /// <param name="computeObjects"></param>
        /// <param name="handleCount"></param>
        /// <returns></returns>
        public static CLDeviceHandle[] ExtractHandles(ICollection <ComputeDevice> computeObjects, out int handleCount)
        {
            if (computeObjects == null || computeObjects.Count == 0)
            {
                handleCount = 0;
                return(null);
            }

            CLDeviceHandle[] result = new CLDeviceHandle[computeObjects.Count];
            int i = 0;

            foreach (ComputeDevice computeObj in computeObjects)
            {
                result[i] = computeObj.Handle;
                i++;
            }
            handleCount = computeObjects.Count;
            return(result);
        }
Exemple #10
0
        /// <summary>
        /// Gets a read-only collection of available devices on the platform.
        /// </summary>
        /// <returns> A read-only collection of the available devices on the platform. </returns>
        /// <remarks> This method resets the <c>ComputePlatform.Devices</c>. This is useful if one or more of them become unavailable (<c>ComputeDevice.Available</c> is <c>false</c>) after a device and command queues that use the device have been created and commands have been queued to them. Further calls will trigger an <c>OutOfResourcesComputeException</c> until this method is executed. You will also need to recreate any <see cref="ComputeResource"/> that was created on the no longer available device. </remarks>
        public ReadOnlyCollection <IComputeDevice> QueryDevices()
        {
            var error = CL10.GetDeviceIDs(Handle, ComputeDeviceTypes.All, 0, null, out int handlesLength);

            ComputeException.ThrowOnError(error);

            var handles = new CLDeviceHandle[handlesLength];

            error = CL10.GetDeviceIDs(Handle, ComputeDeviceTypes.All, handlesLength, handles, out handlesLength);
            ComputeException.ThrowOnError(error);

            var devices = new ComputeDevice[handlesLength];

            for (int i = 0; i < handlesLength; i++)
            {
                devices[i] = new ComputeDevice(this, handles[i]);
            }
            Devices = new ReadOnlyCollection <IComputeDevice>(devices);
            return(Devices);
        }
Exemple #11
0
        /// <summary>
        /// Gets a read-only collection of available <see cref="OpenCLDevice"/>s on the <see cref="OpenCLPlatform"/>.
        /// </summary>
        /// <returns> A read-only collection of the available <see cref="OpenCLDevice"/>s on the <see cref="OpenCLPlatform"/>. </returns>
        /// <remarks> This method resets the <c>OpenCLPlatform.Devices</c>. This is useful if one or more of them become unavailable (<c>OpenCLDevice.Available</c> is <c>false</c>) after a <see cref="OpenCLContext"/> and <see cref="OpenCLCommandQueue"/>s that use the <see cref="OpenCLDevice"/> have been created and commands have been queued to them. Further calls will trigger an <c>OutOfResourcesOpenCLException</c> until this method is executed. You will also need to recreate any <see cref="OpenCLResource"/> that was created on the no longer available <see cref="OpenCLDevice"/>. </remarks>
        public ReadOnlyCollection <OpenCLDevice> QueryDevices()
        {
            int             handlesLength = 0;
            OpenCLErrorCode error         = CL10.GetDeviceIDs(Handle, OpenCLDeviceType.All, 0, null, out handlesLength);

            OpenCLException.ThrowOnError(error);

            CLDeviceHandle[] handles = new CLDeviceHandle[handlesLength];
            error = CL10.GetDeviceIDs(Handle, OpenCLDeviceType.All, handlesLength, handles, out handlesLength);
            OpenCLException.ThrowOnError(error);

            OpenCLDevice[] devices = new OpenCLDevice[handlesLength];
            for (int i = 0; i < handlesLength; i++)
            {
                devices[i] = new OpenCLDevice(this, handles[i]);
            }

            this.devices = new ReadOnlyCollection <OpenCLDevice>(devices);

            return(this.devices);
        }
        public ReadOnlyCollection <ComputeDevice> CreateSubDevices(uint num_devices)
        {
            CLDeviceHandle[] handles = new CLDeviceHandle[num_devices];
            cl_device_partition_property[] properties = new cl_device_partition_property[] {
                cl_device_partition_property.CL_DEVICE_PARTITION_EQUALLY,
                (cl_device_partition_property)(uint)(MaxComputeUnits / num_devices),
                0
            };
            ComputeErrorCode error = CL12.CreateSubDevices(Handle, num_devices, properties, handles, out num_devices);

            ComputeException.ThrowOnError(error);

            ComputeDevice[] subDevices = new ComputeDevice[num_devices];
            for (int i = 0; i < num_devices; i++)
            {
                subDevices[i] = new ComputeDevice(this.Platform, handles[i]);
            }

            this.subDevices = subDevices;

            return(new ReadOnlyCollection <ComputeDevice> (this.subDevices));
        }
 extern internal static ComputeErrorCode SetDefaultDeviceCommandQueue(
     CLContextHandle context,
     CLDeviceHandle device,
     CLCommandQueueHandle command_queue);
 extern internal static CLCommandQueueHandle CreateCommandQueueWithProperties(
     CLContextHandle context,
     CLDeviceHandle device,
     [MarshalAs(UnmanagedType.LPArray)] ComputeCommandQueueFlags[] properties,
     out ComputeErrorCode errcode_ret);
 extern internal static CLCommandQueueHandle CreateCommandQueue(
     CLContextHandle context,
     CLDeviceHandle device,
     ComputeCommandQueueFlags properties,
     out ComputeErrorCode errcode_ret);