Class: SGC::CU::CUDevice

Inherits:
Object
  • Object
show all
Defined in:
lib/cuda/driver/device.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.can_access_peer?(dev, peer_dev = nil) ⇒ Boolean

Returns True if device dev may directly access the memory of device peer_dev.

Since:

  • CUDA 4.0



146
147
148
149
150
151
152
153
154
155
156
# File 'lib/cuda/driver/device.rb', line 146

def self.can_access_peer?(dev, peer_dev = nil)
    # TODO: Remove the following workaround for JRuby when the default argument bug is fixed.
    if peer_dev.nil?
        peer_dev = dev
        dev = CUContext.device
    end
    b = FFI::MemoryPointer.new(:int)
    status = API::cuDeviceCanAccessPeer(b, dev.to_api, peer_dev.to_api)
    Pvt::handle_error(status, "Failed to query can access peer.")
    b.read_int == 1 ? true : false
end

.countInteger



37
38
39
40
41
42
# File 'lib/cuda/driver/device.rb', line 37

def self.count
    p = FFI::MemoryPointer.new(:int)
    status = API::cuDeviceGetCount(p)
    Pvt::handle_error(status, "Failed to get device count.")
    p.read_int
end

.get(index) ⇒ CUDevice



47
48
49
50
51
52
# File 'lib/cuda/driver/device.rb', line 47

def self.get(index)
    p = FFI::MemoryPointer.new(:CUDevice)
    status = API::cuDeviceGet(p, index)
    Pvt::handle_error(status, "Failed to get device #{index}.")
    new(p)
end

.malloc(nbytes) ⇒ CUDevicePtr

Allocate nbytes of device memory from the current device.



133
134
135
136
137
138
# File 'lib/cuda/driver/device.rb', line 133

def self.malloc(nbytes)
    p = FFI::MemoryPointer.new(:CUDevicePtr)
    status = API::cuMemAlloc(p, nbytes)
    Pvt::handle_error(status, "Failed to allocate device memory: size = #{nbytes}.")
    CUDevicePtr.send(:new, p)
end

Instance Method Details

#attribute(attrib) ⇒ Integer

Returns The attribute attrib of this device.

Examples:

dev.attribute(:MAX_THREADS_PER_BLOCK)        #=> 512
dev.attribute(:MULTIPROCESSOR_COUNT)         #=> 30
dev.attribute(:MAX_SHARED_MEMORY_PER_BLOCK)  #=> 16384


83
84
85
86
87
88
# File 'lib/cuda/driver/device.rb', line 83

def attribute(attrib)
    p = FFI::MemoryPointer.new(:int)
    status = API::cuDeviceGetAttribute(p, attrib, self.to_api)
    Pvt::handle_error(status, "Failed to query device attribute #{attrib}.")
    p.read_int
end

#compute_capabilityHash{ :major, :minor }

Returns The compute capability of this device.

Examples:

For a device with compute capability 1.3:

dev.compute_capability    #=> { major: 1, minor: 3 }


68
69
70
71
72
73
# File 'lib/cuda/driver/device.rb', line 68

def compute_capability
    cap = FFI::MemoryPointer.new(:int, 2)
    status = API::cuDeviceComputeCapability(cap[0], cap[1], self.to_api)
    Pvt::handle_error(status, "Failed to query device compute capability.")
    { major: cap[0].read_int, minor: cap[1].read_int }
end

#nameString



56
57
58
59
60
61
# File 'lib/cuda/driver/device.rb', line 56

def name
    s = FFI::MemoryPointer.new(:char, 256)
    status = API::cuDeviceGetName(s, 256, self.to_api)
    Pvt::handle_error(status, "Failed to get device name.")
    s.read_string
end

#propertiesHash



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/cuda/driver/device.rb', line 102

def properties
    prop = API::CUDevProp.new
    status = API::cuDeviceGetProperties(prop.to_ptr, self.to_api)
    Pvt::handle_error(status, "Failed to get device properties.")
    h = {}
    h[:clock_rate] = prop[:clockRate]
    h[:max_grid_size] = prop[:maxGridSize]
    h[:max_threads_dim] = prop[:maxThreadsDim]
    h[:max_threads_per_block] = prop[:maxThreadsPerBlock]
    h[:mem_pitch] = prop[:memPitch]
    h[:regs_per_block] = prop[:regsPerBlock]
    h[:shared_mem_per_block] = prop[:sharedMemPerBlock]
    h[:simd_width] = prop[:SIMDWidth]
    h[:texture_align] = prop[:textureAlign]
    h[:total_constant_memory] = prop[:totalConstantMemory]
    h
end

#total_memInteger



122
123
124
125
126
127
# File 'lib/cuda/driver/device.rb', line 122

def total_mem
    p = FFI::MemoryPointer.new(:size_t)
    status = API::cuDeviceTotalMem(p, self.to_api)
    Pvt::handle_error(status, "Failed to get device total amount of memory available.")
    API::read_size_t(p)
end