Class: Cumo::CUDA::Device
- Inherits:
-
Object
- Object
- Cumo::CUDA::Device
- Defined in:
- lib/cumo/cuda/device.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
- #compute_capability ⇒ Object
-
#initialize(device_id = nil) ⇒ Device
constructor
A new instance of Device.
- #synchronize ⇒ Object
- #use ⇒ Object
- #with ⇒ Object
Constructor Details
#initialize(device_id = nil) ⇒ Device
Returns a new instance of Device.
11 12 13 14 15 16 17 18 |
# File 'lib/cumo/cuda/device.rb', line 11 def initialize(device_id = nil) if device_id @id = device_id else @id = Runtime.cudaGetDevice end @_device_stack = [] end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/cumo/cuda/device.rb', line 5 def id @id end |
Class Method Details
.get_currend_id ⇒ Object
7 8 9 |
# File 'lib/cumo/cuda/device.rb', line 7 def self.get_currend_id Runtime.cudaGetDevice end |
Instance Method Details
#compute_capability ⇒ Object
41 42 43 44 45 |
# File 'lib/cumo/cuda/device.rb', line 41 def compute_capability major = Runtime.cudaDeviceGetAttributes(75, @id) minor = Runtime.cudaDeviceGetAttributes(76, @id) "#{major}#{minor}" end |
#synchronize ⇒ Object
37 38 39 |
# File 'lib/cumo/cuda/device.rb', line 37 def synchronize Runtime.cudaDeviceSynchronize end |
#use ⇒ Object
20 21 22 |
# File 'lib/cumo/cuda/device.rb', line 20 def use Runtime.cudaSetDevice(@id) end |
#with ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/cumo/cuda/device.rb', line 24 def with raise unless block_given? prev_id = Runtime.cudaGetDevice @_device_stack << prev_id begin Runtime.cudaSetDevice(@id) unless prev_id != @id yield ensure prev_id = @_device_stack.pop Runtime.cudaSetDevice(prev_id) end end |