예제 #1
0
        /// <summary>
        /// Detects Cuda devices.
        /// </summary>
        /// <param name="predicate">
        /// The predicate to include a given device.
        /// </param>
        /// <param name="registry">The registry to add all devices to.</param>
        private static void GetDevicesInternal(
            Predicate <CudaDevice> predicate,
            DeviceRegistry registry)
        {
            // Resolve all devices
            if (CurrentAPI.GetDeviceCount(out int numDevices) !=
                CudaError.CUDA_SUCCESS ||
                numDevices < 1)
            {
                return;
            }

            for (int i = 0; i < numDevices; ++i)
            {
                if (CurrentAPI.GetDevice(out int device, i) != CudaError.CUDA_SUCCESS)
                {
                    continue;
                }

                var desc = new CudaDevice(device);
                if (predicate(desc))
                {
                    registry.Register(desc);
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Enables all Cuda devices.
 /// </summary>
 /// <param name="builder">The builder instance.</param>
 /// <param name="predicate">
 /// The predicate to include a given device.
 /// </param>
 /// <returns>The updated builder instance.</returns>
 public static Context.Builder Cuda(
     this Context.Builder builder,
     Predicate <CudaDevice> predicate)
 {
     CudaDevice.GetDevices(
         predicate,
         builder.DeviceRegistry);
     return(builder);
 }
예제 #3
0
        /// <summary>
        /// Enables all Cuda devices.
        /// </summary>
        /// <param name="builder">The builder instance.</param>
        /// <param name="predicate">
        /// The predicate to include a given device.
        /// </param>
        /// <returns>The updated builder instance.</returns>
        public static Context.Builder Cuda(
            this Context.Builder builder,
            Predicate <CudaDevice> predicate)
        {
            if (Backend.RuntimePlatform != TargetPlatform.X64)
            {
                throw new NotSupportedException(string.Format(
                                                    RuntimeErrorMessages.CudaPlatformX64,
                                                    Backend.RuntimePlatform));
            }

            CudaDevice.GetDevices(
                predicate,
                builder.DeviceRegistry);
            return(builder);
        }