Class: SGC::Cuda::CudaDevice

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

Class Method Summary collapse

Class Method Details

.cache_configCudaFunctionCache

Returns The cache config of the current CUDA device.

Returns:

Since:

  • CUDA 4.0



108
109
110
111
112
113
# File 'lib/cuda/runtime/device.rb', line 108

def self.cache_config
    p = FFI::MemoryPointer.new(:enum)
    status = API::cudaDeviceGetCacheConfig(p)
    Pvt::handle_error(status, "Failed to get the current CUDA device cache config.")
    CudaFunctionCache[API::read_enum(p)]
end

.cache_config=(conf) ⇒ Object

Set the cache config of the current CUDA device to conf.

Parameters:

  • conf (CudaFunctionCache)

    The cache config of the current CUDA device to set to.

Since:

  • CUDA 4.0



120
121
122
123
# File 'lib/cuda/runtime/device.rb', line 120

def self.cache_config=(conf)
    status = API::cudaDeviceSetCacheConfig(conf)
    Pvt::handle_error(status, "Failed to set the current CUDA device cache config.")
end

.can_access_peer?(devid = self.get, peer_devid) ⇒ Boolean

Returns True if device devid is capable of directly accessing memory from device peer_devid.

Parameters:

  • devid (Integer) (defaults to: self.get)

    The device’s ID which is to access the memory of the device peer_devid.

  • peer_devid (Integer)

    The device’s ID which its memory is to be accessed by the device devid.

Returns:

  • (Boolean)

    True if device devid is capable of directly accessing memory from device peer_devid.

Since:

  • CUDA 4.0



178
179
180
181
182
183
# File 'lib/cuda/runtime/device.rb', line 178

def self.can_access_peer?(devid = self.get, peer_devid)
    b = FFI::MemoryPointer.new(:int)
    status = API::cudaDeviceCanAccessPeer(b, devid, peer_devid)
    Pvt::handle_error(status, "Failed to query can access peer: devid = #{devid}, peer_devid = #{peer_devid}.")
    b.read_int == 1 ? true : false
end

.choose(prop) ⇒ Integer

Returns The index of the CUDA device best matches the criteria.

Parameters:

Returns:

  • (Integer)

    The index of the CUDA device best matches the criteria.



66
67
68
69
70
71
# File 'lib/cuda/runtime/device.rb', line 66

def self.choose(prop)
    pdev = FFI::MemoryPointer.new(:int)
    status = API::cudaChooseDevice(pdev, prop.to_ptr)
    Pvt::handle_error(status, "Failed to choose a device with criteria.")
    pdev.read_int
end

.countInteger

Returns The number of CUDA devices.

Returns:

  • (Integer)

    The number of CUDA devices.



35
36
37
38
39
40
# File 'lib/cuda/runtime/device.rb', line 35

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

.disable_peer_access(peer_devid) ⇒ Class

Disable the current device from accessing the memory of the peer device.

Parameters:

  • peer_devid (Integer)

    The peer device’s ID.

Returns:

  • (Class)

    This class.

Since:

  • CUDA 4.0



204
205
206
207
208
# File 'lib/cuda/runtime/device.rb', line 204

def self.disable_peer_access(peer_devid)
    status = API::cudaDeviceDisablePeerAccess(peer_devid)
    Pvt::handle_error(status, "Failed to disable peer access: peer_devid = #{peer_devid}.")
    self
end

.enable_peer_access(peer_devid, flags = 0) ⇒ Class

Enable the current device to access the memory of the peer device.

Parameters:

  • peer_devid (Integer)

    The peer device’s ID.

  • flags (Integer) (defaults to: 0)

    Currently flags must be set to zero.

Returns:

  • (Class)

    This class.

Since:

  • CUDA 4.0



192
193
194
195
196
# File 'lib/cuda/runtime/device.rb', line 192

def self.enable_peer_access(peer_devid, flags = 0)
    status = API::cudaDeviceEnablePeerAccess(peer_devid, flags)
    Pvt::handle_error(status, "Failed to enable peer access: peer_devid = #{peer_devid}, flags = #{flags}.")
    self
end

.flags=(flags) ⇒ Object

Set the flags to be used for device execution.

Parameters:



86
87
88
89
90
# File 'lib/cuda/runtime/device.rb', line 86

def self.flags=(flags)
    f = CudaDeviceFlags.value(flags)
    status = API::cudaSetDeviceFlags(f)
    Pvt::handle_error(status, "Failed to set device flags: flags = #{flags}.")
end

.getInteger Also known as: current

Returns The index of the current CUDA device in use.

Returns:

  • (Integer)

    The index of the current CUDA device in use.



44
45
46
47
48
49
# File 'lib/cuda/runtime/device.rb', line 44

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

.limit(lim) ⇒ CudaLimit

Returns The limit lim of the current CUDA device.

Parameters:

  • lim (CudaLimit)

    The particular limit attribute to query.

Returns:

  • (CudaLimit)

    The limit lim of the current CUDA device.

Since:

  • CUDA 4.0



130
131
132
133
134
135
# File 'lib/cuda/runtime/device.rb', line 130

def self.limit(lim)
    p = FFI::MemoryPointer.new(:size_t)
    status = API::cudaDeviceGetLimit(p, lim)
    Pvt::handle_error(status, "Failed to get the current CUDA device limit: limit = #{lim}.")
    API::read_size_t(p)
end

.limit=(*lim_val_pair) ⇒ Object

Set the limit lim of the current CUDA device.

Parameters:

  • lim (CudaLimit)

    The particular limit attribute to set.

  • value (Integer)

    The value to set the limit to.

Since:

  • CUDA 4.0



143
144
145
146
147
148
# File 'lib/cuda/runtime/device.rb', line 143

def self.limit=(*lim_val_pair)
    lim, val = lim_val_pair.flatten
    lim != nil && val != nil or raise ArgumentError, "Invalid limit and value pair given: limit = #{lim}, value = #{val}."
    status = API::cudaDeviceSetLimit(lim, val)
    Pvt::handle_error(status, "Failed to set the current CUDA device limit: limit = #{lim}, value = #{val}")
end

.properties(devid = self.get) ⇒ CudaDeviceProp

Returns The properties of the device devid.

Parameters:

  • devid (Integer) (defaults to: self.get)

    The index of the device to query.

Returns:



76
77
78
79
80
81
# File 'lib/cuda/runtime/device.rb', line 76

def self.properties(devid = self.get)
    prop = CudaDeviceProp.new
    status = API::cudaGetDeviceProperties(prop.to_ptr, devid)
    Pvt::handle_error(status, "Failed to get device properties: devid = #{devid}.")
    prop
end

.resetClass

Destroy all allocations and reset all state on the current CUDA device.

Returns:

  • (Class)

    This class.

Since:

  • CUDA 4.0



155
156
157
158
159
# File 'lib/cuda/runtime/device.rb', line 155

def self.reset
    status = API::cudaDeviceReset()
    Pvt::handle_error(status, "Failed to reset the current CUDA device.")
    self
end

.set(devid) ⇒ Class Also known as: current=

Set devid as the current CUDA device.

Parameters:

  • devid (Integer)

    The index (0..CudaDevice.count-1) of the CUDA device to set as current.

Returns:

  • (Class)

    This class.



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

def self.set(devid)
    status = API::cudaSetDevice(devid)
    Pvt::handle_error(status, "Failed to set current device: devid = #{devid}.")
    self
end

.synchronizeClass

Block until all the tasks of the current CUDA device complete.

Returns:

  • (Class)

    This class.

Since:

  • CUDA 4.0



166
167
168
169
170
# File 'lib/cuda/runtime/device.rb', line 166

def self.synchronize
    status = API::cudaDeviceSynchronize()
    Pvt::handle_error(status, "Failed to synchronize the current CUDA device.")
    self
end

.valid_devices=(devs) ⇒ Object

Set the list of CUDA devices that can be used.

Parameters:

  • devs (Array)

    The list of CUDA device indexes.



95
96
97
98
99
100
101
102
# File 'lib/cuda/runtime/device.rb', line 95

def self.valid_devices=(devs)
    p = FFI::MemoryPointer.new(:int, devs.count)
    devs.each_with_index do |devid, i|
        p[i].write_int(devid)
    end
    status = API::cudaSetValidDevices(p, devs.count)
    Pvt::handle_error(status, "Failed to set valid devices: devs = #{devs}.")
end