module CooCoo::CUDA::Runtime

Public Class Methods

device_count() click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/coo-coo/cuda/runtime.rb, line 152
def self.total_global_mem
  memory_info[1]
end