module Chainer::CUDA

Public Class Methods

available?(id = nil) click to toggle source

Returns whether CUDA is available.

@param [Integer or nil] id If a non negative integer is given, check availability of GPU ID. @return [Boolean]

# File lib/chainer/cuda.rb, line 20
def available?(id = nil)
  return false unless $chainer_cuda_available
  if id
    raise 'id must be non negative' if id < 0
    @device_count ||= Cumo::CUDA::Runtime.cudaGetDeviceCount
    return @device_count > id
  end
  true
end
check_available(id = nil) click to toggle source

Checks if CUDA is available.

@param [Integer or nil] id If a non negative integer is given, check availability of GPU ID. @raise [RuntimeError] if not available

# File lib/chainer/cuda.rb, line 35
def check_available(id = nil)
  raise 'CUDA is not available' unless available?(id)
end

Private Instance Methods

available?(id = nil) click to toggle source

Returns whether CUDA is available.

@param [Integer or nil] id If a non negative integer is given, check availability of GPU ID. @return [Boolean]

# File lib/chainer/cuda.rb, line 20
def available?(id = nil)
  return false unless $chainer_cuda_available
  if id
    raise 'id must be non negative' if id < 0
    @device_count ||= Cumo::CUDA::Runtime.cudaGetDeviceCount
    return @device_count > id
  end
  true
end
check_available(id = nil) click to toggle source

Checks if CUDA is available.

@param [Integer or nil] id If a non negative integer is given, check availability of GPU ID. @raise [RuntimeError] if not available

# File lib/chainer/cuda.rb, line 35
def check_available(id = nil)
  raise 'CUDA is not available' unless available?(id)
end