Exemplo n.º 1
0
        /// <summary>
        /// Gets all devices of the platform that match the specified device type.
        /// </summary>
        /// <param name="deviceType">The type of devices that is to be retrieved.</param>
        /// <exception cref="OpenClException">If the devices could not be retrieved, then a <see cref="OpenClException"/> is thrown.</exception>
        /// <returns>Returns a list of all devices that matched the specified device type.</returns>
        public IEnumerable <Device> GetDevices(Devices.DeviceType deviceType)
        {
            // Gets the number of available devices of the specified type
            uint   numberOfAvailableDevices;
            Result result = DevicesNativeApi.GetDeviceIds(Handle, (Interop.Devices.DeviceType)deviceType, 0, null,
                                                          out numberOfAvailableDevices);

            if (result != Result.Success)
            {
                throw new OpenClException("The number of available devices could not be queried.", result);
            }

            // Gets the pointers to the devices of the specified type
            IntPtr[] devicePointers = new IntPtr[numberOfAvailableDevices];
            result = DevicesNativeApi.GetDeviceIds(Handle, (Interop.Devices.DeviceType)deviceType,
                                                   numberOfAvailableDevices, devicePointers, out numberOfAvailableDevices);
            if (result != Result.Success)
            {
                throw new OpenClException("The devices could not be retrieved.", result);
            }

            // Converts the pointer to device objects
            foreach (IntPtr devicePointer in devicePointers)
            {
                yield return(new Device(devicePointer));
            }
        }
Exemplo n.º 2
0
        public uint GetDeviceCount(DeviceType deviceType)
        {
            Result result = DevicesNativeApi.GetDeviceIds(
                Handle,
                (Interop.Devices.DeviceType)deviceType,
                0,
                null,
                out uint numberOfAvailableDevices
                );

            return(numberOfAvailableDevices);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Provides a list of available OpenCL devices on the system
        /// </summary>
        /// <returns>A list of OpenCL devices</returns>
        public static List <ComputeDeviceDesc> GetDevices()
        {
            List <ComputeDeviceDesc> ret = new List <ComputeDeviceDesc>();

            // Gets the number of available platforms
            uint   numberOfAvailablePlatforms;
            Result result = PlatformsNativeApi.GetPlatformIds(0, null, out numberOfAvailablePlatforms);

            if (result != Result.Success)
            {
                throw new OpenClException("The number of platforms could not be queried.", result);
            }

            // Gets pointers to all the platforms
            IntPtr[] platformPointers = new IntPtr[numberOfAvailablePlatforms];
            result = PlatformsNativeApi.GetPlatformIds(numberOfAvailablePlatforms, platformPointers, out numberOfAvailablePlatforms);
            if (result != Result.Success)
            {
                throw new OpenClException("The platforms could not be retrieved.", result);
            }

            // Converts the pointers to platform objects
            int platformId = 0;

            foreach (IntPtr platformPointer in platformPointers)
            {
                ++platformId;

                // Gets the number of available devices of the specified type
                uint   numberOfAvailableDevices;
                Result result_d = DevicesNativeApi.GetDeviceIds(platformPointer, DeviceType.All, 0, null, out numberOfAvailableDevices);
                if (result_d != Result.Success)
                {
                    throw new OpenClException("The number of available devices could not be queried.", result_d);
                }

                // Gets the pointers to the devices of the specified type
                IntPtr[] devicePointers = new IntPtr[numberOfAvailableDevices];
                result_d = DevicesNativeApi.GetDeviceIds(platformPointer, DeviceType.All, numberOfAvailableDevices, devicePointers, out numberOfAvailableDevices);
                if (result_d != Result.Success)
                {
                    throw new OpenClException("The devices could not be retrieved.", result_d);
                }

                // Converts the pointer to device objects
                int deviceId = 0;
                foreach (IntPtr devicePointer in devicePointers)
                {
                    ++deviceId;

                    OpenCLComputeDeviceDesc devDesc = new OpenCLComputeDeviceDesc();
                    devDesc.platform   = platformPointer;
                    devDesc.device     = devicePointer;
                    devDesc.platformId = platformId;
                    devDesc.deviceId   = deviceId;
                    ret.Add(devDesc);
                }
            }

            return(ret);
        }