Пример #1
0
        public uint GetDeviceCount(DeviceType deviceType)
        {
            Result result = DevicesNativeApi.GetDeviceIds(
                Handle,
                (Interop.Devices.DeviceType)deviceType,
                0,
                null,
                out uint numberOfAvailableDevices
                );

            return(numberOfAvailableDevices);
        }
Пример #2
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(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));
            }
        }