Module: CooCoo::CUDA::Runtime
- Extended by:
- FFI::Library
- Defined in:
- lib/coo-coo/cuda/runtime.rb
Defined Under Namespace
Classes: DeviceProperties
Class Method Summary
collapse
Class Method Details
.device_count ⇒ Object
117
118
119
120
121
|
# File 'lib/coo-coo/cuda/runtime.rb', line 117
def self.device_count
n = ::FFI::MemoryPointer.new(:int, 1)
cudaGetDeviceCount(n)
n.read_int
end
|
.get_device ⇒ Object
105
106
107
108
109
|
# File 'lib/coo-coo/cuda/runtime.rb', line 105
def self.get_device
dev = ::FFI::MemoryPointer.new(:int, 1)
cudaGetDevice(dev)
dev.read_int
end
|
.get_device_props(dev = nil) ⇒ Object
123
124
125
126
127
|
# File 'lib/coo-coo/cuda/runtime.rb', line 123
def self.get_device_props(dev = nil)
props = DeviceProperties.new
cudaGetDeviceProperties(props, dev || get_device)
props
end
|
.memory_info ⇒ Object
144
145
146
147
148
149
150
|
# File 'lib/coo-coo/cuda/runtime.rb', line 144
def self.memory_info
free = ::FFI::MemoryPointer.new(:size_t, 1)
total = ::FFI::MemoryPointer.new(:size_t, 1)
err = cudaMemGetInfo(free, total)
raise APIError.new(err) if err != 0
[ read_size_t(free), read_size_t(total) ]
end
|
.read_size_t(pointer) ⇒ Object
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/coo-coo/cuda/runtime.rb', line 129
def self.read_size_t(pointer)
if @size_t_reader == nil
type = ::FFI.find_type(:size_t)
@size_t_reader = case type.size
when 8 then :read_ulong_long
when 4 then :read_ulong
when 2 then :read_ushort
when 1 then :read_ubyte
else raise ArgumentError.new("size_t type not found")
end
end
pointer.send(@size_t_reader)
end
|
.set_device(dev) ⇒ Object
111
112
113
114
115
|
# File 'lib/coo-coo/cuda/runtime.rb', line 111
def self.set_device(dev)
err = cudaSetDevice(dev)
raise APIError.new(err) if err != 0
dev
end
|
.total_global_mem ⇒ Object
152
153
154
|
# File 'lib/coo-coo/cuda/runtime.rb', line 152
def self.total_global_mem
memory_info[1]
end
|