Ejemplo n.º 1
0
        public static void Initialize(ComputeDeviceTypes selectedComputeDeviceTypes, int platformId = 0, int deviceIndex = 0)
        {
            Platform = ComputePlatform.Platforms[platformId];

            Devices = Platform
                      .Devices
                      .Where(d => (long)d.Type == (long)selectedComputeDeviceTypes)
                      .ToArray();

            DeviceIndex = deviceIndex;

            if (Devices.Length > 0)
            {
                Context = new ComputeContext(
                    Devices,
                    new ComputeContextPropertyList(Platform),
                    null,
                    IntPtr.Zero
                    );

                CommandQueue = new ComputeCommandQueue(
                    Context,
                    Devices[DeviceIndex],
                    ComputeCommandQueueFlags.None
                    );

                Enable = true;
            }
        }
Ejemplo n.º 2
0
        public DeviceSwitchHandler Switch(ComputeDeviceTypes type, bool flush = true)
        {
            if (Device == type)
            {
                return(new DeviceSwitchHandler(this, Device));
            }

            switch (type)
            {
            case ComputeDeviceTypes.Default:
            case ComputeDeviceTypes.Cpu:
                IsGpu = false;
                if (cpuData == null || cpuData.Length != gpuData.Count)
                {
                    cpuData = new Real[(int)gpuData.Count];
                }
                Weaver.CommandQueue.ReadFromBuffer(gpuData, ref cpuData, true, null);
                if (flush)
                {
                    gpuData.Dispose();
                    gpuData = null;
                }
                break;

            case ComputeDeviceTypes.Gpu:
                IsGpu = true;
                if (gpuData != null)
                {
                    if (gpuData.Count != cpuData.Length)
                    {
                        gpuData.Dispose();
                        gpuData = new ComputeBuffer <Real>(GpuComputeContext, GpuMemoryFlag, cpuData);
                    }
                    else
                    {
                        Weaver.CommandQueue.WriteToBuffer(cpuData, gpuData, true, null);
                    }
                }
                else
                {
                    gpuData = new ComputeBuffer <Real>(GpuComputeContext, GpuMemoryFlag, cpuData);
                }
                if (flush)
                {
                    cpuData = null;
                }
                break;

            case ComputeDeviceTypes.Accelerator:
            case ComputeDeviceTypes.All:
            default:
                break;
            }

            var preDevice = Device;

            Device = type;

            return(new DeviceSwitchHandler(this, preDevice));
        }
Ejemplo n.º 3
0
        public void LoadTestParameters(string device, string mask)
        {
            // what device to use
            switch (device)
            {
            case "gpu":
                ComputeDevice = ComputeDeviceTypes.Gpu;
                break;

            case "cpu":
                ComputeDevice = ComputeDeviceTypes.Cpu;
                break;

            default:
                ComputeDevice = ComputeDeviceTypes.All;
                break;
            }

            Masks = new string[] { Normalise(mask) };

            ListfileHandler = new ListfileHandler();
            ResultQueue     = new Queue <ulong>();
            ResultStrings   = new HashSet <string>();
            IsBenchmark     = true;
        }
Ejemplo n.º 4
0
 public AcceleratorDevice(ComputeDevice Device)
 {
     this.Device = Device;
     this.Name   = Device.Name;
     this.Vendor = Device.Vendor;
     this.Type   = Device.Type;
 }
Ejemplo n.º 5
0
        public void LoadTestParameters(string device, string mask)
        {
            // what device to use
            switch (device)
            {
            case "gpu":
                ComputeDevice = ComputeDeviceTypes.Gpu;
                break;

            case "cpu":
                ComputeDevice = ComputeDeviceTypes.Cpu;
                break;

            default:
                ComputeDevice = ComputeDeviceTypes.All;
                break;
            }

            Masks        = new string[] { Normalise(mask) };
            TargetHashes = new HashSet <ulong>()
            {
                0, 4097458660625243137
            };

            ResultQueue   = new Queue <ulong>();
            ResultStrings = new HashSet <string>();
            IsBenchmark   = true;
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        internal ComputeDevice(ComputePlatform platform, IntPtr handle)
        {
            this.handle = handle;

            name          = GetStringInfo(ComputeDeviceInfo.Name);
            this.platform = platform;
            type          = (ComputeDeviceTypes)GetInfo <long>(ComputeDeviceInfo.Type);
        }
Ejemplo n.º 8
0
 public void SetFilter(ComputeDeviceTypes filter)
 {
     this.Accelerators = AcceleratorDevice.All.Where(x => filter.HasFlag(x.Type)).ToArray();
     this.Context      = Accelerators.Select(x => new OpenCL()
     {
         Accelerator = x
     }).ToArray();
 }
Ejemplo n.º 9
0
        public void LoadParameters(params string[] args)
        {
            if (args.Length < 3)
            {
                throw new ArgumentException("Incorrect number of arguments");
            }

            // what device to use
            switch (args[1].ToLower().Trim())
            {
            case "gpu":
                ComputeDevice = ComputeDeviceTypes.Gpu;
                break;

            case "cpu":
                ComputeDevice = ComputeDeviceTypes.Cpu;
                break;

            default:
                ComputeDevice = ComputeDeviceTypes.All;
                break;
            }

            // format + validate template masks
            if (File.Exists(args[2]))
            {
                Masks = File.ReadAllLines(args[2])
                        .Select(x => Normalise(x))
                        .Where(x => !string.IsNullOrWhiteSpace(x))
                        .OrderBy(x => Path.GetExtension(x))
                        .ToArray();
            }
            else if (!string.IsNullOrWhiteSpace(args[2]))
            {
                Masks = new string[] { Normalise(args[2]) };
            }

            if (Masks == null || Masks.Length == 0)
            {
                throw new ArgumentException("No valid masks");
            }

            // check for mirrored flag
            IsMirrored = (args.Length > 3 && args[3].Trim() == "1");

            // grab any listfile filters
            string product    = args.Length > 4 ? args[4] : "";
            string exclusions = args.Length > 5 ? args[5] : "";

            ListfileHandler = new ListfileHandler(product, exclusions);

            ResultQueue   = new Queue <ulong>();
            ResultStrings = new HashSet <string>();
            IsBenchmark   = false;
        }
Ejemplo n.º 10
0
        public void LoadParameters(params string[] args)
        {
            if (args.Length < 3)
            {
                throw new ArgumentException("Incorrect number of arguments");
            }

            // what device to use
            switch (args[1].ToLower().Trim())
            {
            case "gpu":
                ComputeDevice = ComputeDeviceTypes.Gpu;
                break;

            case "cpu":
                ComputeDevice = ComputeDeviceTypes.Cpu;
                break;

            default:
                ComputeDevice = ComputeDeviceTypes.All;
                break;
            }

            // format + validate template masks
            if (File.Exists(args[2]))
            {
                Masks = File.ReadAllLines(args[2]).Where(x => x.Contains('%')).Select(x => Normalise(x)).ToArray();
            }
            else if (args[2].Contains('%'))
            {
                Masks = new string[] { Normalise(args[2]) };
            }

            if (Masks == null || Masks.Length == 0)
            {
                throw new ArgumentException("No valid masks");
            }

            // check for mirrored flag
            IsMirrored = (args.Length > 3 && args[3].Trim() == "1");

            // check for listfile and sort out the target hashes
            ParseHashes();

            if (TargetHashes.Count <= 1)
            {
                throw new ArgumentException("Unknown listfile is missing or empty");
            }

            ResultQueue   = new Queue <ulong>();
            ResultStrings = new HashSet <string>();
            IsBenchmark   = false;
        }
Ejemplo n.º 11
0
        public void LoadParameters(params string[] args)
        {
            if (args.Length < 3)
            {
                throw new ArgumentException("Incorrect number of arguments");
            }

            // what device to use
            switch (args[1].ToLower().Trim())
            {
            case "gpu":
                ComputeDevice = ComputeDeviceTypes.Gpu;
                break;

            case "cpu":
                ComputeDevice = ComputeDeviceTypes.Cpu;
                break;

            default:
                ComputeDevice = ComputeDeviceTypes.All;
                break;
            }

            // format + validate template masks
            if (File.Exists(args[2]))
            {
                Masks = File.ReadAllLines(args[2])
                        .Select(x => Normalise(x))
                        .Where(x => !string.IsNullOrWhiteSpace(x))
                        .OrderBy(x => Path.GetExtension(x))
                        .ToArray();
            }
            else if (!string.IsNullOrWhiteSpace(args[2]))
            {
                Masks = new string[] { Normalise(args[2]) };
            }

            if (Masks == null || Masks.Length == 0)
            {
                throw new ArgumentException("No valid masks");
            }

            if (args.Length > 2)
            {
                ParseHashes(args[3]);
            }

            ResultQueue   = new Queue <ulong>();
            ResultStrings = new HashSet <string>();
            IsBenchmark   = false;
        }
Ejemplo n.º 12
0
        public static void Initialize(ComputeDeviceTypes selectedComputeDeviceTypes, int deviceIndex = 0)
        {
            //最初に見つかったプラットフォームを採用する
            for (int i = 0; i < ComputePlatform.Platforms.Count; i++)
            {
                var checklist = ComputePlatform.Platforms[i].Devices.Where(d => (long)d.Type == (long)selectedComputeDeviceTypes).ToArray();

                if (checklist.Length > 0)
                {
                    Initialize(i, deviceIndex);
                    return;
                }
            }
        }
Ejemplo n.º 13
0
        /// <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 ComputeContext100();
            var propertyArray = context.ToIntPtrArray(properties);

            context.Handle = OpenCL100.CreateContextFromTypeWrapper(propertyArray, deviceType, notify, userDataPtr);
            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);
        }
Ejemplo n.º 14
0
        public void SetFilter(ComputeDeviceTypes filter)
        {
            var accelerators = AcceleratorDevice.All.Where(x => filter.HasFlag(x.Type));

            // remove Intel graphics if there is a GPU
            if (filter == ComputeDeviceTypes.Gpu && !accelerators.All(x => x.Vendor.ToLower().Contains("intel")))
            {
                accelerators = accelerators.Where(x => !x.Vendor.ToLower().Contains("intel"));
            }

            this.Accelerators = accelerators.ToArray();
            this.Context      = Accelerators.Select(x => new OpenCL()
            {
                Accelerator = x
            }).ToArray();
        }
Ejemplo n.º 15
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Creates a new <see cref="ComputeContext"/> on all the <see cref="ComputeDevice"/>s that match
        /// the specified <see cref="ComputeDeviceTypes"/>.
        /// </summary>
        ///
        /// <param name="deviceType">   A bit-field that identifies the type of
        ///                             <see cref="ComputeDevice"/> to associate with the
        ///                             <see cref="ComputeContext"/>. </param>
        /// <param name="properties">   A <see cref="ComputeContextPropertyList"/> of the
        ///                             <see cref="ComputeContext"/>. </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
        ///                             <see cref="ComputeContext"/>. 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
        ///                             <see cref="ComputeContext"/> 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 ComputeContext(ComputeDeviceTypes deviceType, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr userDataPtr)
        {
            IntPtr[] propertyArray = properties?.ToIntPtrArray();
            callback = notify;

            Handle = CL12.CreateContextFromType(propertyArray, deviceType, notify, userDataPtr, out var error);
            ComputeException.ThrowOnError(error);

            SetID(Handle.Value);

            this.properties = properties;
            ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform);

            platform = ComputePlatform.GetByHandle(platformProperty.Value);
            devices  = GetDevices();

            RILogManager.Default?.SendTrace("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information");
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Creates a new <see cref="ComputeContext"/> on all the <see cref="ComputeDevice"/>s that match the specified <see cref="ComputeDeviceTypes"/>.
        /// </summary>
        /// <param name="deviceType"> A bit-field that identifies the type of <see cref="ComputeDevice"/> to associate with the <see cref="ComputeContext"/>. </param>
        /// <param name="properties"> A <see cref="ComputeContextPropertyList"/> of the <see cref="ComputeContext"/>. </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 <see cref="ComputeContext"/>. 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 <see cref="ComputeContext"/> 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 ComputeContext(ComputeDeviceTypes deviceType, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr userDataPtr)
        {
            IntPtr[] propertyArray = (properties != null) ? properties.ToIntPtrArray() : null;
            callback = notify;

            ComputeErrorCode error = ComputeErrorCode.Success;

            Handle = CLInterface.CL12.CreateContextFromType(propertyArray, deviceType, notify, userDataPtr, out error);
            ComputeException.ThrowOnError(error);

            SetID(Handle.Value);

            this.properties = properties;
            ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform);

            this.platform = ComputePlatform.GetByHandle(platformProperty.Value);
            this.devices  = GetDevices();
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Creates a new <see cref="ComputeContext"/> on all the <see cref="ComputeDevice"/>s that match the specified <see cref="ComputeDeviceTypes"/>.
        /// </summary>
        /// <param name="deviceType"> A bit-field that identifies the type of <see cref="ComputeDevice"/> to associate with the <see cref="ComputeContext"/>. </param>
        /// <param name="properties"> A <see cref="ComputeContextPropertyList"/> of the <see cref="ComputeContext"/>. </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 <see cref="ComputeContext"/>. 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 <see cref="ComputeContext"/> 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 ComputeContext(ComputeDeviceTypes deviceType, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr userDataPtr)
        {
            IntPtr[] propertyArray = (properties != null) ? properties.ToIntPtrArray() : null;
            callback = notify;

            ComputeErrorCode error = ComputeErrorCode.Success;

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

            SetID(Handle.Value);

            this.properties = properties;
            ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform);

            this.platform = ComputePlatform.GetByHandle(platformProperty.Value);
            this.devices  = GetDevices();

            Trace.WriteLine("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information");
        }
Ejemplo n.º 18
0
        public static void Initialize(ComputeDeviceTypes selectedComputeDeviceTypes, int platformId = 0, int deviceIndex = 0)
        {
            Platform = ComputePlatform.Platforms[platformId];

            Devices = Platform
                      .Devices
                      .Where(d => (long)d.Type == (long)selectedComputeDeviceTypes)
                      .ToArray();

            DeviceIndex = deviceIndex;

            int id = 0;

            foreach (var item in Devices)
            {
                Console.WriteLine($"Compute[{item.Type},{id}], {item.Name}, {item.VersionString}, Driver:{item.DriverVersion}");
                id++;
            }

            if (Devices.Length > 0)
            {
                Context = new ComputeContext(
                    Devices,
                    new ComputeContextPropertyList(Platform),
                    null,
                    IntPtr.Zero
                    );

                CommandQueue = new ComputeCommandQueue(
                    Context,
                    Devices[DeviceIndex],
                    ComputeCommandQueueFlags.None
                    );

                Enable = true;

                Console.WriteLine("Device Initialized");
            }
        }
Ejemplo n.º 19
0
 /// <summary>Initializes OpenCL and reads devices</summary>
 public static void InitCL(ComputeDeviceTypes DevicesToUse, int PlatformToUse)
 {
     InitCL(DevicesToUse, null, null, PlatformToUse);
 }
Ejemplo n.º 20
0
 public static unsafe extern ComputeErrorCode GetDeviceIDs(
     IntPtr platform,
     ComputeDeviceTypes device_type,
     Int32 num_entries,
     [MarshalAs(UnmanagedType.LPArray)] IntPtr[] devices,
     Int32* num_devices);
Ejemplo n.º 21
0
 public static unsafe extern IntPtr CreateContextFromType(
     [MarshalAs(UnmanagedType.LPArray)] IntPtr[] properties,
     ComputeDeviceTypes device_type,
     /* void (*pfn_notify)(const char *, const IntPtr, IntPtr, IntPtr) */ ComputeContextNotifier pfn_notify,
     /* void* */ IntPtr user_data,
     ComputeErrorCode* errcode_ret);
Ejemplo n.º 22
0
        /// <summary>Initializes OpenCL and reads devices. Uses previously created context and command queue if supplied. In that case DevicesToUse is ignored.</summary>
        public static void InitCL(ComputeDeviceTypes DevicesToUse, ComputeContext PrevCtx, ComputeCommandQueue PrevCQ)
        {
            if (CLAcceleration != CLAccelerationType.UsingCL)
            {
                try
                {
                    if (ComputePlatform.Platforms.Count > 0) CLAccel = CLAccelerationType.UsingCL;
                    else CLAccel = CLAccelerationType.NotUsingCL;

                    //Program.Event = new List<ComputeEventBase>();

                    CLPlatforms = new List<ComputePlatform>();
                    foreach (ComputePlatform pp in ComputePlatform.Platforms) CLPlatforms.Add(pp);

                    ComputeContextPropertyList Properties = new ComputeContextPropertyList(ComputePlatform.Platforms[0]);

                    if (PrevCtx == null)
                    {
                        Program.Context = new ComputeContext(DevicesToUse, Properties, null, IntPtr.Zero);
                    }
                    else Program.Context = PrevCtx;

                    CLDevices = new List<ComputeDevice>();
                    for (int i = 0; i < Program.Context.Devices.Count; i++)
                    {
                        CLDevices.Add(Program.Context.Devices[i]);

                    }

                    Program.CommQueues = new List<ComputeCommandQueue>();
                    Program.AsyncCommQueues = new List<ComputeCommandQueue>();
                    Program.DefaultCQ = -1;

                    if (PrevCQ == null)
                    {
                        for (int i = 0; i < CLDevices.Count; i++)
                        {
                            //Comandos para os devices
                            ComputeCommandQueue CQ = new ComputeCommandQueue(Program.Context, CLDevices[i], ComputeCommandQueueFlags.None);

                            ComputeCommandQueue AsyncCQ = new ComputeCommandQueue(Program.Context, CLDevices[i], ComputeCommandQueueFlags.OutOfOrderExecution);

                            //Comando para a primeira GPU
                            if ((CLDevices[i].Type == ComputeDeviceTypes.Gpu || CLDevices[i].Type == ComputeDeviceTypes.Accelerator) && Program.DefaultCQ < 0)
                                Program.DefaultCQ = i;

                            Program.CommQueues.Add(CQ);
                            Program.AsyncCommQueues.Add(AsyncCQ);

                        }
                        //Só tem CPU
                        if (Program.DefaultCQ < 0 && Program.CommQueues.Count > 0) Program.DefaultCQ = 0;
                    }
                    else
                    {
                        Program.CommQueues.Add(PrevCQ);
                        Program.DefaultCQ = 0;
                    }
                }
                catch (Exception ex)
                {
                    CLInitErr = ex.ToString();
                    CLAccel = CLAccelerationType.NotUsingCL;
                }
            }
        }
Ejemplo n.º 23
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));
 }
Ejemplo n.º 24
0
 ComputeErrorCode ICL10.GetDeviceIDs(CLPlatformHandle platform, ComputeDeviceTypes device_type, int num_entries,
                                     CLDeviceHandle[] devices, out int num_devices)
 {
     return(GetDeviceIDs(platform, device_type, num_entries, devices, out num_devices));
 }
Ejemplo n.º 25
0
 public extern static ComputeErrorCode GetDeviceIDs(
     CLPlatformHandle platform,
     ComputeDeviceTypes device_type,
     Int32 num_entries,
     [Out, MarshalAs(UnmanagedType.LPArray)] CLDeviceHandle[] devices,
     out Int32 num_devices);
Ejemplo n.º 26
0
 public static extern ComputeErrorCode GetDeviceIDs(
     CLPlatformHandle platform,
     ComputeDeviceTypes device_type,
     Int32 num_entries,
     [Out, MarshalAs(UnmanagedType.LPArray)] CLDeviceHandle[] devices,
     out Int32 num_devices);
Ejemplo n.º 27
0
 public MultiCL(ComputeDeviceTypes filter = ComputeDeviceTypes.All)
 {
     SetFilter(filter);
 }
Ejemplo n.º 28
0
 CLContextHandle ICL10.CreateContextFromType(IntPtr[] properties, ComputeDeviceTypes device_type,
                                             ComputeContextNotifier pfn_notify, IntPtr user_data,
                                             out ComputeErrorCode errcode_ret)
 {
     return(CreateContextFromType(properties, device_type, pfn_notify, user_data, out errcode_ret));
 }
Ejemplo n.º 29
0
 public static extern int GetDeviceIDs(IntPtr platform, ComputeDeviceTypes device_type, int num_entries, [Out, MarshalAs(UnmanagedType.LPArray)] IntPtr[] devices, out int num_devices);
Ejemplo n.º 30
0
        public static CLContextHandle CreateContextFromTypeWrapper(IntPtr[] properties, ComputeDeviceTypes device_type, ComputeContextNotifier pfn_notify, IntPtr user_data)
        {
            var context = CreateContextFromType(properties, device_type, pfn_notify, user_data, out ComputeErrorCode errcode_ret);

            ComputeException.ThrowOnError(errcode_ret);
            return(context);
        }
Ejemplo n.º 31
0
 public static unsafe extern ComputeErrorCode GetDeviceIDs(
     IntPtr platform,
     ComputeDeviceTypes device_type,
     Int32 num_entries,
     IntPtr* devices,
     Int32* num_devices);
Ejemplo n.º 32
0
 /// <summary>Initializes OpenCL and reads devices</summary>
 public static void InitCL(ComputeDeviceTypes DevicesToUse)
 {
     InitCL(DevicesToUse, null, null);
 }
Ejemplo n.º 33
0
        /// <summary>
        /// Creates a new <see cref="ComputeContext"/> on all the <see cref="ComputeDevice"/>s that match the specified <see cref="ComputeDeviceTypes"/>.
        /// </summary>
        /// <param name="deviceType"> A bit-field that identifies the type of <see cref="ComputeDevice"/> to associate with the <see cref="ComputeContext"/>. </param>
        /// <param name="properties"> A <see cref="ComputeContextPropertyList"/> of the <see cref="ComputeContext"/>. </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 <see cref="ComputeContext"/>. 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 <see cref="ComputeContext"/> 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 ComputeContext(ComputeDeviceTypes deviceType, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr userDataPtr)
        {
            unsafe
            {
                IntPtr[] propertyArray = (properties != null) ? properties.ToIntPtrArray() : null;
                callback = notify;

                ComputeErrorCode error = ComputeErrorCode.Success;
                Handle = CL10.CreateContextFromType(propertyArray, deviceType, notify, userDataPtr, &error);
                ComputeException.ThrowOnError(error);

                this.properties = properties;
                ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform);
                this.platform = ComputePlatform.GetByHandle(platformProperty.Value);
                this.devices = GetDevices();
            }

            resourceTable.Add(GetHashCode(), this);
            Trace.WriteLine("Created " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").");
        }
Ejemplo n.º 34
0
 CLContextHandle ICL10.CreateContextFromType(IntPtr[] properties, ComputeDeviceTypes device_type,
                                             ComputeContextNotifier pfn_notify, IntPtr user_data,
                                             out ComputeErrorCode errcode_ret)
 {
     return CreateContextFromType(properties, device_type, pfn_notify, user_data, out errcode_ret);
 }
Ejemplo n.º 35
0
 public DeviceSwitchHandler(RealArray obj, ComputeDeviceTypes type)
 {
     this.obj  = obj;
     this.type = type;
 }
Ejemplo n.º 36
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="deviceType">device type</param>
 /// <param name="properties">context properties</param>
 /// <param name="notify">context notify</param>
 /// <param name="userDataPtr">user data pointer</param>
 public ClooContext(ComputeDeviceTypes deviceType, ComputeContextPropertyList properties, ComputeContextNotifier notify, System.IntPtr userDataPtr)
     : base(deviceType, properties, notify, userDataPtr)
 {
     foreach (ComputeDevice device in base.Devices)
         _devices.Add(ClooDevice.FromBaseDevice(device));
 }
Ejemplo n.º 37
0
 public static extern CLContextHandle CreateContextFromType(
     [MarshalAs(UnmanagedType.LPArray)] IntPtr[] properties,
     ComputeDeviceTypes device_type,
     ComputeContextNotifier pfn_notify,
     IntPtr user_data,
     out ComputeErrorCode errcode_ret);
Ejemplo n.º 38
0
 public static unsafe extern IntPtr CreateContextFromType(
     IntPtr* properties,
     ComputeDeviceTypes device_type,
     /* void (*pfn_notify)(const char *, const IntPtr, IntPtr, IntPtr) */ IntPtr pfn_notify,
     /* void* */ IntPtr user_data,
     ComputeErrorCode* errcode_ret);
Ejemplo n.º 39
0
 public extern static CLContextHandle CreateContextFromType(
     [MarshalAs(UnmanagedType.LPArray)] IntPtr[] properties,
     ComputeDeviceTypes device_type,
     ComputeContextNotifier pfn_notify,
     IntPtr user_data,
     out ComputeErrorCode errcode_ret);
Ejemplo n.º 40
0
 ComputeErrorCode ICL10.GetDeviceIDs(CLPlatformHandle platform, ComputeDeviceTypes device_type, int num_entries,
                                     CLDeviceHandle[] devices, out int num_devices)
 {
     return GetDeviceIDs(platform, device_type, num_entries, devices, out num_devices);
 }
Ejemplo n.º 41
0
        /// <summary>
        /// Creates a new <c>ComputeContext</c> on all the <c>ComputeDevice</c>s that match the specified <c>ComputeDeviceTypes</c>.
        /// </summary>
        /// <param name="deviceType"> A bit-field that identifies the type of <c>ComputeDevice</c> to associate with the <c>ComputeContext</c>. </param>
        /// <param name="properties"> A <c>ComputeContextPropertyList</c> of the <c>ComputeContext</c>. </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 <c>ComputeContext</c>. 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 <c>ComputeContext</c> 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 ComputeContext(ComputeDeviceTypes deviceType, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr userDataPtr)
        {
            unsafe
            {
                IntPtr[] propertyArray = (properties != null) ? properties.ToIntPtrArray() : null;
                callback = notify;

                ComputeErrorCode error = ComputeErrorCode.Success;
                Handle = CL10.CreateContextFromType(propertyArray, deviceType, notify, userDataPtr, &error);
                ComputeException.ThrowOnError(error);

                this.properties = properties;
                ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform);
                this.platform = ComputePlatform.GetByHandle(platformProperty.Value);
                this.devices = GetDevices();
            }
        }
Ejemplo n.º 42
0
        /// <summary>
        /// Creates a new <c>ComputeContext</c> on all the <c>ComputeDevice</c>s that match the specified <c>ComputeDeviceTypes</c>.
        /// </summary>
        /// <param name="deviceType"> A bit-field that identifies the type of <c>ComputeDevice</c> to associate with the <c>ComputeContext</c>. </param>
        /// <param name="properties"> A <c>ComputeContextPropertyList</c> of the <c>ComputeContext</c>. </param>
        /// <param name="notify"> A callback function that can be registered by the application. This callback function will be used by the OpenCL implementation to report information on errors that occur in the <c>ComputeContext</c>. This 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. 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 ComputeContext(ComputeDeviceTypes deviceType, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr userDataPtr)
        {
            unsafe
            {
                IntPtr[] propertiesList = (properties != null) ? properties.ToIntPtrArray() : null;
                IntPtr notifyFuncPtr = (notify != null) ? Marshal.GetFunctionPointerForDelegate(notify) : IntPtr.Zero;

                ComputeErrorCode error = ComputeErrorCode.Success;
                fixed (IntPtr* propertiesPtr = propertiesList)
                    Handle = CL10.CreateContextFromType(
                        propertiesPtr,
                        deviceType,
                        notifyFuncPtr,
                        userDataPtr,
                        &error);
                ComputeException.ThrowOnError(error);

                this.properties = properties;
                ComputeContextProperty platformProperty = properties.GetByName(ComputeContextPropertyName.Platform);
                this.platform = ComputePlatform.GetByHandle(platformProperty.Value);
                this.devices = GetDevices();
            }
        }