Class: Chainer::GpuDevice

Inherits:
AbstractDevice show all
Defined in:
lib/chainer/device.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id = nil) ⇒ GpuDevice

Returns a new instance of GpuDevice.

Parameters:

  • id (Integer) (defaults to: nil)

    GPU Device ID. If not given, CUDA current device id is used.



65
66
67
68
69
70
71
72
# File 'lib/chainer/device.rb', line 65

def initialize(id = nil)
  Chainer::CUDA.check_available
  id ||= Cumo::CUDA::Runtime.cudaGetDevice
  if id < 0
    raise 'GPU Device ID must not be negative'
  end
  @id = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



62
63
64
# File 'lib/chainer/device.rb', line 62

def id
  @id
end

Instance Method Details

#==(other) ⇒ Object



78
79
80
81
# File 'lib/chainer/device.rb', line 78

def ==(other)
  return false unless other.is_a?(GpuDevice)
  id == other.id
end

#useObject

Sets CUDA current device with owned GPU Device ID



84
85
86
# File 'lib/chainer/device.rb', line 84

def use
  Cumo::CUDA::Runtime.cudaSetDevice(@id)
end

#xmObject



74
75
76
# File 'lib/chainer/device.rb', line 74

def xm
  Cumo
end