Exemple #1
0
        /// <summary>
        /// Creates a new program from an array of source code strings.
        /// </summary>
        /// <param name="context"> A context. </param>
        /// <param name="source"> The source code lines for the program. </param>
        /// <remarks> The created program is associated with the devices. </remarks>
        public IComputeProgram BuildComputeProgram(IComputeContext context, string[] source)
        {
            var program = new ComputeProgram110();

            program.Handle = OpenCL110.CreateProgramWithSource(
                context.Handle,
                source.Length,
                source,
                null,
                out ComputeErrorCode error);
            ComputeException.ThrowOnError(error);
            logger.Info("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information");
            return(program);
        }
        /// <summary>
        /// Creates a new program from a specified list of binaries.
        /// </summary>
        /// <param name="context"> A context. </param>
        /// <param name="binaries"> A list of binaries, one for each item in <paramref name="devices"/>. </param>
        /// <param name="devices"> A subset of the context devices. If <paramref name="devices"/> is <c>null</c>, OpenCL will associate every binary from binaries with a corresponding device from devices. </param>
        public IComputeProgram BuildComputeProgram(IComputeContext context, IList <byte[]> binaries, IList <IComputeDevice> devices)
        {
            var program = new ComputeProgram120();
            int count;

            CLDeviceHandle[] deviceHandles;
            if (devices != null)
            {
                deviceHandles = ComputeTools.ExtractHandles(devices, out count);
            }
            else
            {
                deviceHandles = ComputeTools.ExtractHandles(context.Devices, out count);
            }

            IntPtr[]   binariesPtrs      = new IntPtr[count];
            IntPtr[]   binariesLengths   = new IntPtr[count];
            int[]      binariesStats     = new int[count];
            GCHandle[] binariesGCHandles = new GCHandle[count];

            try
            {
                for (int i = 0; i < count; i++)
                {
                    binariesGCHandles[i] = GCHandle.Alloc(binaries[i], GCHandleType.Pinned);
                    binariesPtrs[i]      = binariesGCHandles[i].AddrOfPinnedObject();
                    binariesLengths[i]   = new IntPtr(binaries[i].Length);
                }

                program.Handle = OpenCL120.CreateProgramWithBinary(
                    context.Handle,
                    count,
                    deviceHandles,
                    binariesLengths,
                    binariesPtrs,
                    binariesStats,
                    out ComputeErrorCode error);
                ComputeException.ThrowOnError(error);
            }
            finally
            {
                for (int i = 0; i < count; i++)
                {
                    binariesGCHandles[i].Free();
                }
            }
            logger.Info("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information");
            return(program);
        }
        /// <summary>
        /// Creates a kernel for a kernel function of a specified name.
        /// </summary>
        /// <returns> The created kernel. </returns>
        public IComputeKernel CreateKernel(IComputeProgram program, string functionName)
        {
            var kernel = new ComputeKernel120();

            kernel.Handle = OpenCL120.CreateKernel(
                program.Handle,
                functionName,
                out ComputeErrorCode error);
            ComputeException.ThrowOnError(error);

            kernel.SetID(kernel.Handle.Value);
            kernel.FunctionName = functionName;
            logger.Info("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information");
            return(kernel);
        }
        /// <summary>
        /// Creates a new sampler.
        /// </summary>
        /// <param name="context"> A context. </param>
        /// <param name="normalizedCoords"> The usage state of normalized coordinates when accessing a image in a kernel. </param>
        /// <param name="addressing"> The <see cref="ComputeImageAddressing"/> mode of the sampler. Specifies how out-of-range image coordinates are handled while reading. </param>
        /// <param name="filtering"> The <see cref="ComputeImageFiltering"/> mode of the sampler. Specifies the type of filter that must be applied when reading data from an image. </param>
        public IComputeSampler CreateSampler(IComputeContext context, bool normalizedCoords,
                                             ComputeImageAddressing addressing, ComputeImageFiltering filtering)
        {
            var sampler = new ComputeSampler120();

            sampler.Handle = OpenCL120.CreateSampler(context.Handle, normalizedCoords, addressing, filtering, out ComputeErrorCode error);
            ComputeException.ThrowOnError(error);

            sampler.SetID(sampler.Handle.Value);

            sampler.Addressing       = addressing;
            sampler.Filtering        = filtering;
            sampler.NormalizedCoords = normalizedCoords;

            logger.Info("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information");
            return(sampler);
        }
Exemple #5
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);
        }
        /// <summary>
        /// Creates a new context on all the devices that match the specified <see cref="ComputeDeviceTypes"/>.
        /// </summary>
        /// <param name="deviceType"> A bit-field that identifies the type of device to associate with the context. </param>
        /// <param name="properties"> A list of context properties of the context. </param>
        /// <param name="notify"> A delegate instance that refers to a notification routine. This routine is a callback function that will be used by the OpenCL implementation to report information on errors that occur in the context. The callback function may be called asynchronously by the OpenCL implementation. It is the application's responsibility to ensure that the callback function is thread-safe and that the delegate instance doesn't get collected by the Garbage Collector until context is disposed. If <paramref name="notify"/> is <c>null</c>, no callback function is registered. </param>
        /// <param name="userDataPtr"> Optional user data that will be passed to <paramref name="notify"/>. </param>
        public IComputeContext CreateContext(ComputeDeviceTypes deviceType, List <ComputeContextProperty> properties,
                                             ComputeContextNotifier notify, IntPtr userDataPtr)
        {
            var context       = new ComputeContext120();
            var propertyArray = context.ToIntPtrArray(properties);

            context.Handle = OpenCL120.CreateContextFromType(
                propertyArray,
                deviceType,
                notify,
                userDataPtr,
                out ComputeErrorCode error);
            ComputeException.ThrowOnError(error);

            context.SetID(context.Handle.Value);
            var platformProperty = context.GetByName(properties, ComputeContextPropertyName.Platform);

            context.Platform = ComputePlatform.GetByHandle(platformProperty.Value);
            context.Devices  = context.GetDevices();
            logger.Info("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information");
            return(context);
        }
Exemple #7
0
 public static void ReleaseContextWrapper(CLContextHandle context)
 {
     ComputeException.ThrowOnError(ReleaseContext(context));
 }
Exemple #8
0
 public static void ReleaseCommandQueueWrapper(CLCommandQueueHandle command_queue)
 {
     ComputeException.ThrowOnError(ReleaseCommandQueue(command_queue));
 }
Exemple #9
0
 public static void GetSamplerInfoWrapper(CLSamplerHandle sample, ComputeSamplerInfo param_name, IntPtr param_value_size, IntPtr param_value, out IntPtr param_value_size_ret)
 {
     ComputeException.ThrowOnError(GetSamplerInfo(sample, param_name, param_value_size, param_value, out param_value_size_ret));
 }
Exemple #10
0
 public static void ReleaseSamplerWrapper(CLSamplerHandle sample)
 {
     ComputeException.ThrowOnError(ReleaseSampler(sample));
 }
Exemple #11
0
 public static void GetDeviceInfoWrapper(CLDeviceHandle device, ComputeDeviceInfo param_name, IntPtr param_value_size, IntPtr param_value, out IntPtr param_value_size_ret)
 {
     ComputeException.ThrowOnError(GetDeviceInfo(device, param_name, param_value_size, param_value, out param_value_size_ret));
 }
Exemple #12
0
 public static void GetEventProfilingInfoWrapper(CLEventHandle @event, ComputeCommandProfilingInfo param_name, IntPtr param_value_size, IntPtr param_value, out IntPtr param_value_size_ret)
 {
     ComputeException.ThrowOnError(GetEventProfilingInfo(@event, param_name, param_value_size, param_value, out param_value_size_ret));
 }
Exemple #13
0
 public static void GetProgramInfoWrapper(CLProgramHandle program, ComputeProgramInfo param_name, IntPtr param_value_size, IntPtr param_value, out IntPtr param_value_size_ret)
 {
     ComputeException.ThrowOnError(GetProgramInfo(program, param_name, param_value_size, param_value, out param_value_size_ret));
 }
Exemple #14
0
 public static void CreateKernelsInProgramWrapper(CLProgramHandle program, Int32 num_kernels, CLKernelHandle[] kernels, out Int32 num_kernels_ret)
 {
     ComputeException.ThrowOnError(CreateKernelsInProgram(program, num_kernels, kernels, out num_kernels_ret));
 }
Exemple #15
0
 public static void BuildProgramWrapper(CLProgramHandle program, int num_devices, CLDeviceHandle[] device_list, string options, ComputeProgramBuildNotifier pfn_notify, IntPtr user_data)
 {
     ComputeException.ThrowOnError(BuildProgram(program, num_devices, device_list, options, pfn_notify, user_data));
 }
Exemple #16
0
 public static void GetPlatformIDsWrapper(Int32 num_entries, CLPlatformHandle[] platforms, out Int32 num_platforms)
 {
     ComputeException.ThrowOnError(GetPlatformIDs(num_entries, platforms, out num_platforms));
 }
Exemple #17
0
 public static void SetCommandQueuePropertyWrapper(CLCommandQueueHandle command_queue, ComputeCommandQueueFlags properties, bool enable, out ComputeCommandQueueFlags old_properties)
 {
     ComputeException.ThrowOnError(SetCommandQueueProperty(command_queue, properties, enable, out old_properties));
 }
 public static void TerminateContextKHRWrapper(CLContextHandle context)
 {
     ComputeException.ThrowOnError(TerminateContextKHR(context));
 }
 public static void SetDefaultDeviceCommandQueueWrapper(CLContextHandle context, CLDeviceHandle device, CLCommandQueueHandle command_queue)
 {
     ComputeException.ThrowOnError(SetDefaultDeviceCommandQueue(context, device, command_queue));
 }
Exemple #20
0
 public static void GetContextInfoWrapper(CLContextHandle context, ComputeContextInfo param_name, IntPtr param_value_size, IntPtr param_value, out IntPtr param_value_size_ret)
 {
     ComputeException.ThrowOnError(GetContextInfo(context, param_name, param_value_size, param_value, out param_value_size_ret));
 }
Exemple #21
0
 public static void ReleaseProgramWrapper(CLProgramHandle program)
 {
     ComputeException.ThrowOnError(ReleaseProgram(program));
 }
Exemple #22
0
 public static void GetImageInfoWrapper(CLMemoryHandle image, ComputeImageInfo param_name, IntPtr param_value_size, IntPtr param_value, out IntPtr param_value_size_ret)
 {
     ComputeException.ThrowOnError(GetImageInfo(image, param_name, param_value_size, param_value, out param_value_size_ret));
 }
Exemple #23
0
        /// <summary>
        /// Sets the new status of the user created event to an error value.
        /// </summary>
        /// <param name="status"> The error status of the user created event. This should be a negative value. </param>
        public void SetStatus(int status)
        {
            ComputeErrorCode error = CL11.SetUserEventStatus(Handle, status);

            ComputeException.ThrowOnError(error);
        }
Exemple #24
0
 public static void GetKernelInfoWrapper(CLKernelHandle kernel, ComputeKernelInfo param_name, IntPtr param_value_size, IntPtr param_value, out IntPtr param_value_size_ret)
 {
     ComputeException.ThrowOnError(GetKernelInfo(kernel, param_name, param_value_size, param_value, out param_value_size_ret));
 }
Exemple #25
0
 public static void SetKernelArgWrapper(CLKernelHandle kernel, int arg_index, IntPtr arg_size, IntPtr arg_value)
 {
     ComputeException.ThrowOnError(SetKernelArg(kernel, arg_index, arg_size, arg_value));
 }
Exemple #26
0
 public static void GetDeviceIDsWrapper(CLPlatformHandle platform, ComputeDeviceTypes device_type, Int32 num_entries, CLDeviceHandle[] devices, out Int32 num_devices)
 {
     ComputeException.ThrowOnError(GetDeviceIDs(platform, device_type, num_entries, devices, out num_devices));
 }
Exemple #27
0
 public static void ReleaseKernelWrapper(CLKernelHandle kernel)
 {
     ComputeException.ThrowOnError(ReleaseKernel(kernel));
 }
Exemple #28
0
 public static void GetMemObjectInfoWrapper(CLMemoryHandle memobj, ComputeMemoryInfo param_name, IntPtr param_value_size, IntPtr param_value, out IntPtr param_value_size_ret)
 {
     ComputeException.ThrowOnError(GetMemObjectInfo(memobj, param_name, param_value_size, param_value, out param_value_size_ret));
 }