コード例 #1
0
        internal OpenCLDevice(OpenCLComputeDeviceDesc desc, DeviceConfig _deviceConfig)
            : base(desc)
        {
            this.deviceConfig = _deviceConfig == null ? new DeviceConfig() : _deviceConfig;

            computeFramework = new ComputeFramework(GetDevice(), new string[] { CLSourceProvider.ReadSourceFile() }, new string[] { calcLayerKernel, forwardPass, backwardPassKernel }, deviceConfig.compileOptions);
        }
コード例 #2
0
 internal static ComputeDevice CreateDevice(OpenCLComputeDeviceDesc desc, DeviceConfig deviceConfig = null)
 {
     return(new OpenCLDevice(desc, deviceConfig));
 }
コード例 #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);
        }