コード例 #1
0
        /// <summary>
        /// Creates a new context on a collection of devices.
        /// </summary>
        /// <param name="devices"> A collection of devices 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="notifyDataPtr"> Optional user data that will be passed to <paramref name="notify"/>. </param>
        public IComputeContext CreateContext(ICollection <IComputeDevice> devices, List <ComputeContextProperty> properties,
                                             ComputeContextNotifier notify, IntPtr notifyDataPtr)
        {
            var context       = new ComputeContext120();
            var deviceHandles = ComputeTools.ExtractHandles(devices, out int handleCount);
            var propertyArray = context.ToIntPtrArray(properties);

            context.Handle = OpenCL120.CreateContext(
                propertyArray,
                handleCount,
                deviceHandles,
                notify,
                notifyDataPtr,
                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);
        }
コード例 #2
0
ファイル: WorkingDialog.cs プロジェクト: CHiiLD/net-toolkit
 /// <summary>
 /// Set the kb/s value
 /// </summary>
 /// <param name="val">Value now</param>
 public void ShowKBS(double val)
 {
     Form.Invoke(new Action(() =>
     {
         Form.lblSpeed.Text = ComputeTools.ComputeKBytesPerSecond(val,
                                                                  FirstTick, Environment.TickCount).ToByteSizeString();
     }));
 }
コード例 #3
0
 /// <summary>
 /// Set the kb/s value
 /// </summary>
 /// <param name="val">Value now</param>
 public void ShowKBS(double val)
 {
     win.Invoke(() =>
     {
         win.KBS = ComputeTools.ComputeKBytesPerSecond(val,
                                                       firstTick, Environment.TickCount).ToByteSizeString();
     });
 }
コード例 #4
0
ファイル: WorkingDialog.cs プロジェクト: CHiiLD/net-toolkit
            /// <summary>
            /// Set the time to end
            /// </summary>
            /// <param name="max">Maximum value</param>
            /// <param name="val">Value now (must be greater than 0)</param>
            /// <param name="type">Output of time</param>
            public void ShowTime(double max, double val, TimeSpanStringType type)
            {
                Form.Invoke(new Action(() =>
                {
                    if (val == 0)
                    {
                        throw new ArgumentException("Division by zero! Value cannot be 0!");
                    }

                    Form.lblTime.Text = ComputeTools.ComputeTimeToEnd(max, val,
                                                                      FirstTick, Environment.TickCount).ToString(type);
                }));
            }
コード例 #5
0
        /// <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);
        }
コード例 #6
0
        internal ComputeEvent(CLEventHandle handle, ComputeCommandQueue queue)
        {
            Handle = handle;
            SetID(Handle.Value);

            CommandQueue = queue;
            Type         = (ComputeCommandType)GetInfo <CLEventHandle, ComputeEventInfo, int>(Handle,
                                                                                              ComputeEventInfo.CommandType, CL10.GetEventInfo);

            if (ComputeTools.ParseVersionString(CommandQueue.Device.Platform.Version, 1) > new Version(1, 0))
            {
                HookNotifier();
            }
            logger.Info("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information");
        }
コード例 #7
0
 /// <summary>
 /// Gets the compile work-group size specified by the <c>__attribute__((reqd_work_group_size(X, Y, Z)))</c> qualifier.
 /// </summary>
 /// <param name="device"> One of the device. </param>
 /// <returns> The compile work-group size specified by the <c>__attribute__((reqd_work_group_size(X, Y, Z)))</c> qualifier. If no such qualifier is specified, (0, 0, 0) is returned. </returns>
 public long[] GetCompileWorkGroupSize(IComputeDevice device)
 {
     return(ComputeTools.ConvertArray(
                GetArrayInfo <CLKernelHandle, CLDeviceHandle, ComputeKernelWorkGroupInfo, IntPtr>(
                    Handle, device.Handle, ComputeKernelWorkGroupInfo.CompileWorkGroupSize, OpenCL200.GetKernelWorkGroupInfo)));
 }
コード例 #8
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);
            MaxMemoryAllocationSize    = (long)GetInfo <ulong>(ComputeDeviceInfo.MaxMemoryAllocationSize);
            MaxParameterSize           = (long)GetInfo <IntPtr>(ComputeDeviceInfo.MaxParameterSize);
            MaxReadImageArguments      = 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)));
            MaxWriteImageArguments     = GetInfo <uint>(ComputeDeviceInfo.MaxWriteImageArguments);
            MemoryBaseAddressAlignment = GetInfo <uint>(ComputeDeviceInfo.MemoryBaseAddressAlignment);
            MinDataTypeAlignmentSize   = GetInfo <uint>(ComputeDeviceInfo.MinDataTypeAlignmentSize);
            Name     = GetStringInfo(ComputeDeviceInfo.Name);
            Platform = platform;
            PreferredVectorWidthChar   = GetInfo <uint>(ComputeDeviceInfo.PreferredVectorWidthChar);
            PreferredVectorWidthDouble = GetInfo <uint>(ComputeDeviceInfo.PreferredVectorWidthDouble);
            PreferredVectorWidthFloat  = GetInfo <uint>(ComputeDeviceInfo.PreferredVectorWidthFloat);
            PreferredVectorWidthHalf   = GetInfo <uint>(ComputeDeviceInfo.PreferredVectorWidthHalf);
            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);
            CommandQueueFlags        = (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);
            VersionString = GetStringInfo(ComputeDeviceInfo.Version);
            Version       = ComputeTools.ParseVersionString(VersionString, 1);
        }