Beispiel #1
0
        /// <summary>
        /// Throws if different devices.
        /// </summary>
        /// <param name="tensors">The tensors.</param>
        /// <exception cref="InvalidOperationException">All tensors must reside on the same device</exception>
        public static void ThrowIfDifferentDevices(params NDArray[] tensors)
        {
            var nonNull = tensors.Where(x => x != null);

            if (!nonNull.Any())
            {
                return;
            }

            var device = CudaHelpers.GetDeviceId(nonNull.First());

            if (nonNull.Any(x => CudaHelpers.GetDeviceId(x) != device))
            {
                throw new InvalidOperationException("All tensors must reside on the same device");
            }
        }
Beispiel #2
0
        /// <summary>
        /// DNNs for tensor.
        /// </summary>
        /// <param name="tensor">The tensor.</param>
        /// <returns>PooledObject&lt;ManagedCuda.CudaDNN.CudaDNNContext&gt;.</returns>
        public PooledObject <ManagedCuda.CudaDNN.CudaDNNContext> DNNForTensor(NDArray tensor)
        {
            var deviceId = CudaHelpers.GetDeviceId(tensor);

            return(devices[deviceId].DnnHandles.Get());
        }
Beispiel #3
0
 /// <summary>
 /// Blases for tensor.
 /// </summary>
 /// <param name="tensor">The tensor.</param>
 /// <returns>PooledObject&lt;CudaBlas&gt;.</returns>
 public PooledObject <CudaBlas> BlasForTensor(NDArray tensor)
 {
     return(BlasForDevice(CudaHelpers.GetDeviceId(tensor)));
 }
Beispiel #4
0
 /// <summary>
 /// Cudas the context for tensor.
 /// </summary>
 /// <param name="tensor">The tensor.</param>
 /// <returns>CudaContext.</returns>
 public CudaContext CudaContextForTensor(NDArray tensor)
 {
     return(CudaContextForDevice(CudaHelpers.GetDeviceId(tensor)));
 }