Class: SGC::CU::CUContext
- Inherits:
-
Object
- Object
- SGC::CU::CUContext
- Defined in:
- lib/cuda/driver/context.rb
Class Method Summary collapse
-
.api_version ⇒ Integer
The API version used to create the current CUDA context.
-
.cache_config ⇒ CUFunctionCache
The cache config of the current CUDA context.
-
.cache_config=(conf) ⇒ Object
Set the cache to conf (CUFunctionCache) for the current CUDA context.
-
.create(arg1, arg2 = nil) ⇒ CUContext
Create a new CUDA context with flags (CUContextFlags) and device (CUDevice), then associate it with the calling thread, and return the context.
-
.current ⇒ CUContext
The CUDA context bound to the calling CPU thread.
-
.current=(context) ⇒ Object
Set the current CUDA context to context.
-
.device ⇒ CUDevice
The device associated to the current CUDA context.
-
.disable_peer_access(peer_context) ⇒ Class
Disable the current context from accessing the memory of the peer context.
-
.enable_peer_access(peer_context, flags = 0) ⇒ Class
Enable the current context to access the memory of the peer context.
-
.limit(lim) ⇒ Integer
The limit lim (CULimit) of the current CUDA context.
-
.limit=(*lim_val_pair) ⇒ Object
Set the limit lim (CULimit) of the current CUDA context to value.
-
.pop_current ⇒ Object
Pop the current CUDA context from the CUDA context stack, which becomes inactive.
-
.synchronize ⇒ Object
Block until all the tasks of the current CUDA context complete.
Instance Method Summary collapse
-
#api_version ⇒ Integer
The API version used to create this CUDA context.
- #attach(flags = 0) ⇒ CUContext deprecated Deprecated.
-
#destroy ⇒ Object
Destroy this CUDA context.
- #detach ⇒ Object deprecated Deprecated.
-
#push_current ⇒ CUContext
Push this CUDA context onto the CUDA context stack, which becomes currently active CUDA context.
Class Method Details
.api_version ⇒ Integer
Returns The API version used to create the current CUDA context.
137 138 139 140 141 142 |
# File 'lib/cuda/driver/context.rb', line 137 def self.api_version p = FFI::MemoryPointer.new(:uint) status = API::cuCtxGetApiVersion(nil, p) Pvt::handle_error(status, "Failed to get the API version of the current CUDA context.") p.get_uint(0) end |
.cache_config ⇒ CUFunctionCache
Returns The cache config of the current CUDA context.
186 187 188 189 190 191 |
# File 'lib/cuda/driver/context.rb', line 186 def self.cache_config p = FFI::MemoryPointer.new(:enum) status = API::cuCtxGetCacheConfig(p) Pvt::handle_error(status, "Failed to get the current CUDA context cache config.") CUFunctionCache[API::read_enum(p)] end |
.cache_config=(conf) ⇒ Object
Set the cache to conf (CUFunctionCache) for the current CUDA context.
198 199 200 201 |
# File 'lib/cuda/driver/context.rb', line 198 def self.cache_config=(conf) status = API::cuCtxSetCacheConfig(conf) Pvt::handle_error(status, "Failed to set the current CUDA context cache config: config = #{conf}") end |
.create(device) ⇒ CUContext .create(flags, device) ⇒ CUContext
Create a new CUDA context with flags (CUContextFlags) and device (CUDevice), then associate it with the calling thread, and return the context.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/cuda/driver/context.rb', line 53 def self.create(arg1, arg2 = nil) if arg2 != nil flags, dev = arg1, arg2 flags = CUContextFlags.value(flags) else flags = 0 dev = arg1 end p = FFI::MemoryPointer.new(:CUContext) status = API::cuCtxCreate(p, flags, dev.to_api) Pvt::handle_error(status, "Failed to create CUDA context: flags = #{flags}.") new(p) end |
.current ⇒ CUContext
Returns The CUDA context bound to the calling CPU thread.
102 103 104 105 106 107 |
# File 'lib/cuda/driver/context.rb', line 102 def self.current p = FFI::MemoryPointer.new(:CUContext) status = API::cuCtxGetCurrent(p) Pvt::handle_error(status, "Failed to get the current CUDA context.") new(p) end |
.current=(context) ⇒ Object
Set the current CUDA context to context.
112 113 114 115 |
# File 'lib/cuda/driver/context.rb', line 112 def self.current=(context) status = API::cuCtxSetCurrent(context.to_api) Pvt::handle_error(status, "Failed to set the current CUDA context.") end |
.device ⇒ CUDevice
Returns The device associated to the current CUDA context.
146 147 148 149 150 151 |
# File 'lib/cuda/driver/context.rb', line 146 def self.device p = FFI::MemoryPointer.new(:CUDevice) status = API::cuCtxGetDevice(p) Pvt::handle_error(status, "Failed to get the current CUDA context's device.") CUDevice.send(:new, p) end |
.disable_peer_access(peer_context) ⇒ Class
Disable the current context from accessing the memory of the peer context.
239 240 241 242 243 |
# File 'lib/cuda/driver/context.rb', line 239 def self.disable_peer_access(peer_context) status = API::cuCtxDisablePeerAccess(peer_context.to_api) Pvt::handle_error(status, "Failed to disable peer access.") self end |
.enable_peer_access(peer_context, flags = 0) ⇒ Class
Enable the current context to access the memory of the peer context.
227 228 229 230 231 |
# File 'lib/cuda/driver/context.rb', line 227 def self.enable_peer_access(peer_context, flags = 0) status = API::cuCtxEnablePeerAccess(peer_context.to_api, flags) Pvt::handle_error(status, "Failed to enable peer access: flags = #{flags}.") self end |
.limit(lim) ⇒ Integer
Returns The limit lim (CULimit) of the current CUDA context.
159 160 161 162 163 164 |
# File 'lib/cuda/driver/context.rb', line 159 def self.limit(lim) p = FFI::MemoryPointer.new(:size_t) status = API::cuCtxGetLimit(p, lim) Pvt::handle_error(status, "Failed to get the current CUDA context limit: limit = #{lim}") API::read_size_t(p) end |
.limit=(*lim_val_pair) ⇒ Object
Set the limit lim (CULimit) of the current CUDA context to value.
174 175 176 177 178 179 |
# File 'lib/cuda/driver/context.rb', line 174 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::cuCtxSetLimit(lim, val) Pvt::handle_error(status, "Failed to set the current CUDA context limit: limit = #{lim}, value = #{val}") end |
.pop_current ⇒ Object
Pop the current CUDA context from the CUDA context stack, which becomes inactive.
205 206 207 208 209 210 |
# File 'lib/cuda/driver/context.rb', line 205 def self.pop_current p = FFI::MemoryPointer.new(:CUContext) status = API::cuCtxPopCurrent(p) Pvt::handle_error(status, "Failed to pop current context.") new(p) end |
.synchronize ⇒ Object
Block until all the tasks of the current CUDA context complete.
214 215 216 217 218 |
# File 'lib/cuda/driver/context.rb', line 214 def self.synchronize status = API::cuCtxSynchronize Pvt::handle_error(status, "Failed to synchronize the current context.") nil end |
Instance Method Details
#api_version ⇒ Integer
Returns The API version used to create this CUDA context.
128 129 130 131 132 133 |
# File 'lib/cuda/driver/context.rb', line 128 def api_version p = FFI::MemoryPointer.new(:uint) status = API::cuCtxGetApiVersion(self.to_api, p) Pvt::handle_error(status, "Failed to get the API version of this CUDA context.") p.get_uint(0) end |
#attach ⇒ CUContext #attach(flags) ⇒ CUContext
Increment the reference count on this CUDA context.
84 85 86 87 88 |
# File 'lib/cuda/driver/context.rb', line 84 def attach(flags = 0) status = API::cuCtxAttach(@pcontext, flags) Pvt::handle_error(status, "Failed to attach CUDA context: flags = #{flags}.") self end |
#destroy ⇒ Object
Destroy this CUDA context.
70 71 72 73 74 |
# File 'lib/cuda/driver/context.rb', line 70 def destroy status = API::cuCtxDestroy(self.to_api) Pvt::handle_error(status, "Failed to destroy CUDA context.") nil end |
#detach ⇒ Object
Decrement the reference count on this CUDA context.
94 95 96 97 98 |
# File 'lib/cuda/driver/context.rb', line 94 def detach status = API::cuCtxDetach(self.to_api) Pvt::handle_error(status, "Failed to detach CUDA context.") nil end |
#push_current ⇒ CUContext
Push this CUDA context onto the CUDA context stack, which becomes currently active CUDA context.
120 121 122 123 124 |
# File 'lib/cuda/driver/context.rb', line 120 def push_current status = API::cuCtxPushCurrent(self.to_api) Pvt::handle_error(status, "Failed to push this CUDA context.") self end |