sgc-ruby-cuda 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.yardopts +2 -0
- data/COPYING +674 -0
- data/README.rdoc +106 -0
- data/Rakefile +76 -0
- data/doc/devel.rdoc +77 -0
- data/doc/features.rdoc +55 -0
- data/lib/cuda/driver/context.rb +236 -0
- data/lib/cuda/driver/cu.rb +60 -0
- data/lib/cuda/driver/device.rb +155 -0
- data/lib/cuda/driver/deviceptr.rb +69 -0
- data/lib/cuda/driver/error.rb +182 -0
- data/lib/cuda/driver/event.rb +124 -0
- data/lib/cuda/driver/ffi-cu.rb +620 -0
- data/lib/cuda/driver/function.rb +293 -0
- data/lib/cuda/driver/init.rb +45 -0
- data/lib/cuda/driver/memory.rb +134 -0
- data/lib/cuda/driver/module.rb +142 -0
- data/lib/cuda/driver/rubycu.rb +37 -0
- data/lib/cuda/driver/stream.rb +128 -0
- data/lib/cuda/driver/version.rb +42 -0
- data/lib/cuda/runtime/cuda.rb +65 -0
- data/lib/cuda/runtime/device.rb +175 -0
- data/lib/cuda/runtime/error.rb +197 -0
- data/lib/cuda/runtime/event.rb +117 -0
- data/lib/cuda/runtime/ffi-cuda.rb +588 -0
- data/lib/cuda/runtime/function.rb +161 -0
- data/lib/cuda/runtime/memory.rb +110 -0
- data/lib/cuda/runtime/rubycuda.rb +34 -0
- data/lib/cuda/runtime/stream.rb +126 -0
- data/lib/cuda/runtime/thread.rb +81 -0
- data/lib/cuda/runtime/version.rb +51 -0
- data/lib/ffi/prettystruct.rb +32 -0
- data/lib/helpers/flags.rb +82 -0
- data/lib/helpers/interface/ienum.rb +45 -0
- data/lib/helpers/klass.rb +45 -0
- data/lib/memory/buffer.rb +125 -0
- data/lib/memory/interface/ibuffer.rb +63 -0
- data/lib/memory/pointer.rb +72 -0
- data/lib/rubycu.rb +1 -0
- data/lib/rubycuda.rb +1 -0
- data/test/bad.ptx +0 -0
- data/test/memory/test_buffer.rb +93 -0
- data/test/rubycu/test_cucontext.rb +148 -0
- data/test/rubycu/test_cudevice.rb +69 -0
- data/test/rubycu/test_cudeviceptr.rb +43 -0
- data/test/rubycu/test_cuevent.rb +81 -0
- data/test/rubycu/test_cufunction.rb +165 -0
- data/test/rubycu/test_cumemory.rb +113 -0
- data/test/rubycu/test_cumodule.rb +114 -0
- data/test/rubycu/test_custream.rb +77 -0
- data/test/rubycu/test_cuversion.rb +39 -0
- data/test/rubycu/testbase.rb +107 -0
- data/test/rubycuda/test_cudadevice.rb +125 -0
- data/test/rubycuda/test_cudaerror.rb +48 -0
- data/test/rubycuda/test_cudaevent.rb +78 -0
- data/test/rubycuda/test_cudafunction.rb +106 -0
- data/test/rubycuda/test_cudamemory.rb +90 -0
- data/test/rubycuda/test_cudastream.rb +72 -0
- data/test/rubycuda/test_cudathread.rb +69 -0
- data/test/rubycuda/test_cudaversion.rb +41 -0
- data/test/rubycuda/testbase.rb +67 -0
- data/test/vadd.cu +21 -0
- data/version.rb +1 -0
- metadata +180 -0
@@ -0,0 +1,60 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2011 Chung Shin Yee
|
3
|
+
#
|
4
|
+
# shinyee@speedgocomputing.com
|
5
|
+
# http://www.speedgocomputing.com
|
6
|
+
# http://github.com/xman/sgc-ruby-cuda
|
7
|
+
# http://rubyforge.org/projects/rubycuda
|
8
|
+
#
|
9
|
+
# This file is part of SGC-Ruby-CUDA.
|
10
|
+
#
|
11
|
+
# SGC-Ruby-CUDA is free software: you can redistribute it and/or modify
|
12
|
+
# it under the terms of the GNU General Public License as published by
|
13
|
+
# the Free Software Foundation, either version 3 of the License, or
|
14
|
+
# (at your option) any later version.
|
15
|
+
#
|
16
|
+
# SGC-Ruby-CUDA is distributed in the hope that it will be useful,
|
17
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19
|
+
# GNU General Public License for more details.
|
20
|
+
#
|
21
|
+
# You should have received a copy of the GNU General Public License
|
22
|
+
# along with SGC-Ruby-CUDA. If not, see <http://www.gnu.org/licenses/>.
|
23
|
+
#
|
24
|
+
|
25
|
+
require 'cuda/driver/ffi-cu'
|
26
|
+
require 'memory/buffer'
|
27
|
+
|
28
|
+
|
29
|
+
module SGC
|
30
|
+
module CU
|
31
|
+
|
32
|
+
include SGC::Memory
|
33
|
+
|
34
|
+
class CUResult < API::Enum; end # @see API::CUResult
|
35
|
+
class CUComputeMode < API::Enum; end # @see API::CUComputeMode
|
36
|
+
class CUDeviceAttribute < API::Enum; end # @see API::CUDeviceAttribute
|
37
|
+
class CUContextFlags < API::Enum; end # @see API::CUContextFlags
|
38
|
+
class CULimit < API::Enum; end # @see API::CULimit
|
39
|
+
class CUFunctionAttribute < API::Enum; end # @see API::CUFunctionAttribute
|
40
|
+
class CUFunctionCache < API::Enum; end # @see API::CUFunctionCache
|
41
|
+
class CUEventFlags < API::Enum; end # @see API::CUEventFlags
|
42
|
+
class CUAddressMode < API::Enum; end # @see API::CUAddressMode
|
43
|
+
class CUFilterMode < API::Enum; end # @see API::CUFilterMode
|
44
|
+
class CUTexRefFlags < API::Enum; end # @see API::CUTexRefFlags
|
45
|
+
class CUArrayFormat < API::Enum; end # @see API::CUArrayFormat
|
46
|
+
class CUMemoryType < API::Enum; end # @see API::CUMemoryType
|
47
|
+
class CUPointerAttribute < API::Enum; end # @see API::CUPointerAttribute
|
48
|
+
class CUJitOption < API::Enum; end # @see API::CUJitOption
|
49
|
+
class CUJitFallBack < API::Enum; end # @see API::CUJitFallBack
|
50
|
+
class CUJitTarget < API::Enum; end # @see API::CUJitTarget
|
51
|
+
|
52
|
+
class CUDevProp < API::CUDevProp; end
|
53
|
+
class CudaMemcpy2D < API::CudaMemcpy2D; end
|
54
|
+
class CudaMemcpy3D < API::CudaMemcpy3D; end
|
55
|
+
class CudaMemcpy3DPeer < API::CudaMemcpy3DPeer; end
|
56
|
+
class CudaArrayDescriptor < API::CudaArrayDescriptor; end
|
57
|
+
class CudaArray3DDescriptor < API::CudaArray3DDescriptor; end
|
58
|
+
|
59
|
+
end # module
|
60
|
+
end # module
|
@@ -0,0 +1,155 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2011 Chung Shin Yee
|
3
|
+
#
|
4
|
+
# shinyee@speedgocomputing.com
|
5
|
+
# http://www.speedgocomputing.com
|
6
|
+
# http://github.com/xman/sgc-ruby-cuda
|
7
|
+
# http://rubyforge.org/projects/rubycuda
|
8
|
+
#
|
9
|
+
# This file is part of SGC-Ruby-CUDA.
|
10
|
+
#
|
11
|
+
# SGC-Ruby-CUDA is free software: you can redistribute it and/or modify
|
12
|
+
# it under the terms of the GNU General Public License as published by
|
13
|
+
# the Free Software Foundation, either version 3 of the License, or
|
14
|
+
# (at your option) any later version.
|
15
|
+
#
|
16
|
+
# SGC-Ruby-CUDA is distributed in the hope that it will be useful,
|
17
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19
|
+
# GNU General Public License for more details.
|
20
|
+
#
|
21
|
+
# You should have received a copy of the GNU General Public License
|
22
|
+
# along with SGC-Ruby-CUDA. If not, see <http://www.gnu.org/licenses/>.
|
23
|
+
#
|
24
|
+
|
25
|
+
require 'cuda/driver/ffi-cu'
|
26
|
+
require 'cuda/driver/cu'
|
27
|
+
require 'cuda/driver/error'
|
28
|
+
|
29
|
+
|
30
|
+
module SGC
|
31
|
+
module CU
|
32
|
+
|
33
|
+
class CUDevice
|
34
|
+
|
35
|
+
# @return [Integer] The number of CUDA devices.
|
36
|
+
def self.count
|
37
|
+
p = FFI::MemoryPointer.new(:int)
|
38
|
+
status = API::cuDeviceGetCount(p)
|
39
|
+
Pvt::handle_error(status, "Failed to get device count.")
|
40
|
+
p.read_int
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
# @param [Integer] index The index (0..CUDevice.count-1) of the device to get.
|
45
|
+
# @return [CUDevice] The device corresponding to CUDA device _index_.
|
46
|
+
def self.get(index)
|
47
|
+
p = FFI::MemoryPointer.new(:CUDevice)
|
48
|
+
status = API::cuDeviceGet(p, index)
|
49
|
+
Pvt::handle_error(status, "Failed to get device #{index}.")
|
50
|
+
new(p)
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
# @return [String] The name of this device with a maximum of 255 characters.
|
55
|
+
def name
|
56
|
+
s = FFI::MemoryPointer.new(:char, 256)
|
57
|
+
status = API::cuDeviceGetName(s, 256, self.to_api)
|
58
|
+
Pvt::handle_error(status, "Failed to get device name.")
|
59
|
+
s.read_string
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
# @return [Hash{ :major, :minor }] The compute capability of this device.
|
64
|
+
#
|
65
|
+
# @example For a device with compute capability 1.3:
|
66
|
+
# dev.compute_capability #=> { major: 1, minor: 3 }
|
67
|
+
def compute_capability
|
68
|
+
cap = FFI::MemoryPointer.new(:int, 2)
|
69
|
+
status = API::cuDeviceComputeCapability(cap[0], cap[1], self.to_api)
|
70
|
+
Pvt::handle_error(status, "Failed to query device compute capability.")
|
71
|
+
{ major: cap[0].read_int, minor: cap[1].read_int }
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
# @param [CUDeviceAttribute] attrib The particular attribute of this device to query.
|
76
|
+
# @return [Integer] The attribute _attrib_ of this device.
|
77
|
+
#
|
78
|
+
# @example
|
79
|
+
# dev.attribute(:MAX_THREADS_PER_BLOCK) #=> 512
|
80
|
+
# dev.attribute(:MULTIPROCESSOR_COUNT) #=> 30
|
81
|
+
# dev.attribute(:MAX_SHARED_MEMORY_PER_BLOCK) #=> 16384
|
82
|
+
def attribute(attrib)
|
83
|
+
p = FFI::MemoryPointer.new(:int)
|
84
|
+
status = API::cuDeviceGetAttribute(p, attrib, self.to_api)
|
85
|
+
Pvt::handle_error(status, "Failed to query device attribute #{attrib}.")
|
86
|
+
p.read_int
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
# @return [Hash] The properties of this device in a hash with the following keys:
|
91
|
+
# * :clock_rate
|
92
|
+
# * :max_grid_size
|
93
|
+
# * :max_threads_dim
|
94
|
+
# * :max_threads_per_block
|
95
|
+
# * :mem_pitch
|
96
|
+
# * :regs_per_block
|
97
|
+
# * :shared_mem_per_block
|
98
|
+
# * :simd_width
|
99
|
+
# * :texture_align
|
100
|
+
# * :total_constant_memory
|
101
|
+
def properties
|
102
|
+
prop = CUDevProp.new
|
103
|
+
status = API::cuDeviceGetProperties(prop.to_ptr, self.to_api)
|
104
|
+
Pvt::handle_error(status, "Failed to get device properties.")
|
105
|
+
h = {}
|
106
|
+
h[:clock_rate] = prop[:clockRate]
|
107
|
+
h[:max_grid_size] = prop[:maxGridSize]
|
108
|
+
h[:max_threads_dim] = prop[:maxThreadsDim]
|
109
|
+
h[:max_threads_per_block] = prop[:maxThreadsPerBlock]
|
110
|
+
h[:mem_pitch] = prop[:memPitch]
|
111
|
+
h[:regs_per_block] = prop[:regsPerBlock]
|
112
|
+
h[:shared_mem_per_block] = prop[:sharedMemPerBlock]
|
113
|
+
h[:simd_width] = prop[:SIMDWidth]
|
114
|
+
h[:texture_align] = prop[:textureAlign]
|
115
|
+
h[:total_constant_memory] = prop[:totalConstantMemory]
|
116
|
+
h
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
# @return [Integer] The total amount of device memory in bytes.
|
121
|
+
def total_mem
|
122
|
+
p = FFI::MemoryPointer.new(:size_t)
|
123
|
+
status = API::cuDeviceTotalMem(p, self.to_api)
|
124
|
+
Pvt::handle_error(status, "Failed to get device total amount of memory available.")
|
125
|
+
API::read_size_t(p)
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
# Allocate _nbytes_ of device memory from the current device.
|
130
|
+
# @param [Integer] nbytes The number of bytes to allocate.
|
131
|
+
# @return [CUDevicePtr] A device pointer to the allocated memory.
|
132
|
+
def self.malloc(nbytes)
|
133
|
+
p = FFI::MemoryPointer.new(:CUDevicePtr)
|
134
|
+
status = API::cuMemAlloc(p, nbytes)
|
135
|
+
Pvt::handle_error(status, "Failed to allocate device memory: size = #{nbytes}.")
|
136
|
+
CUDevicePtr.send(:new, p)
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
# @private
|
141
|
+
def initialize(ptr)
|
142
|
+
@pdev = ptr
|
143
|
+
end
|
144
|
+
private_class_method :new
|
145
|
+
|
146
|
+
|
147
|
+
# @private
|
148
|
+
def to_api
|
149
|
+
API::read_cudevice(@pdev)
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
end # module
|
155
|
+
end # module
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2011 Chung Shin Yee
|
3
|
+
#
|
4
|
+
# shinyee@speedgocomputing.com
|
5
|
+
# http://www.speedgocomputing.com
|
6
|
+
# http://github.com/xman/sgc-ruby-cuda
|
7
|
+
# http://rubyforge.org/projects/rubycuda
|
8
|
+
#
|
9
|
+
# This file is part of SGC-Ruby-CUDA.
|
10
|
+
#
|
11
|
+
# SGC-Ruby-CUDA is free software: you can redistribute it and/or modify
|
12
|
+
# it under the terms of the GNU General Public License as published by
|
13
|
+
# the Free Software Foundation, either version 3 of the License, or
|
14
|
+
# (at your option) any later version.
|
15
|
+
#
|
16
|
+
# SGC-Ruby-CUDA is distributed in the hope that it will be useful,
|
17
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19
|
+
# GNU General Public License for more details.
|
20
|
+
#
|
21
|
+
# You should have received a copy of the GNU General Public License
|
22
|
+
# along with SGC-Ruby-CUDA. If not, see <http://www.gnu.org/licenses/>.
|
23
|
+
#
|
24
|
+
|
25
|
+
require 'cuda/driver/ffi-cu'
|
26
|
+
require 'cuda/driver/error'
|
27
|
+
|
28
|
+
|
29
|
+
module SGC
|
30
|
+
module CU
|
31
|
+
|
32
|
+
class CUDevicePtr
|
33
|
+
|
34
|
+
# Free the allocated device memory that this pointer pointing to.
|
35
|
+
def free
|
36
|
+
status = API::cuMemFree(API::read_cudeviceptr(@pdevptr))
|
37
|
+
Pvt::handle_error(status, "Failed to free device memory.")
|
38
|
+
API::write_cudeviceptr(@pdevptr, 0)
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
# @param [Integer] index Number of bytes to offset from this pointer address.
|
44
|
+
# @return [CUDevicePtr] A pointer pointing to the memory location _index_ (bytes)
|
45
|
+
# from this pointer address.
|
46
|
+
def offset(index)
|
47
|
+
p = FFI::MemoryPointer.new(:CUDevicePtr)
|
48
|
+
addr = API::read_cudeviceptr(@pdevptr).to_i + index
|
49
|
+
API::write_cudeviceptr(p, addr)
|
50
|
+
CUDevicePtr.send(:new, p)
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
# @private
|
55
|
+
def initialize(ptr)
|
56
|
+
@pdevptr = ptr
|
57
|
+
end
|
58
|
+
private_class_method :new
|
59
|
+
|
60
|
+
|
61
|
+
# @private
|
62
|
+
def to_api
|
63
|
+
API::read_cudeviceptr(@pdevptr)
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end # module
|
69
|
+
end # module
|
@@ -0,0 +1,182 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2011 Chung Shin Yee
|
3
|
+
#
|
4
|
+
# shinyee@speedgocomputing.com
|
5
|
+
# http://www.speedgocomputing.com
|
6
|
+
# http://github.com/xman/sgc-ruby-cuda
|
7
|
+
# http://rubyforge.org/projects/rubycuda
|
8
|
+
#
|
9
|
+
# This file is part of SGC-Ruby-CUDA.
|
10
|
+
#
|
11
|
+
# SGC-Ruby-CUDA is free software: you can redistribute it and/or modify
|
12
|
+
# it under the terms of the GNU General Public License as published by
|
13
|
+
# the Free Software Foundation, either version 3 of the License, or
|
14
|
+
# (at your option) any later version.
|
15
|
+
#
|
16
|
+
# SGC-Ruby-CUDA is distributed in the hope that it will be useful,
|
17
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19
|
+
# GNU General Public License for more details.
|
20
|
+
#
|
21
|
+
# You should have received a copy of the GNU General Public License
|
22
|
+
# along with SGC-Ruby-CUDA. If not, see <http://www.gnu.org/licenses/>.
|
23
|
+
#
|
24
|
+
|
25
|
+
require 'cuda/driver/ffi-cu'
|
26
|
+
|
27
|
+
|
28
|
+
module SGC
|
29
|
+
module CU
|
30
|
+
|
31
|
+
module Error
|
32
|
+
|
33
|
+
class CUStandardError < RuntimeError; end
|
34
|
+
|
35
|
+
class CUDeviceError < CUStandardError; end
|
36
|
+
class CUDeviceNotInitializedError < CUDeviceError; end
|
37
|
+
class CUDeviceDeinitializedError < CUDeviceError; end
|
38
|
+
class CUNoDeviceError < CUDeviceError; end
|
39
|
+
class CUInvalidDeviceError < CUDeviceError; end
|
40
|
+
|
41
|
+
class CUMapError < CUStandardError; end
|
42
|
+
class CUMapFailedError < CUMapError; end
|
43
|
+
class CUUnMapFailedError < CUMapError; end
|
44
|
+
class CUArrayIsMappedError < CUMapError; end
|
45
|
+
class CUAlreadyMappedError < CUMapError; end
|
46
|
+
class CUNotMappedError < CUMapError; end
|
47
|
+
class CUNotMappedAsArrayError < CUMapError; end
|
48
|
+
class CUNotMappedAsPointerError < CUMapError; end
|
49
|
+
|
50
|
+
class CUContextError < CUStandardError; end
|
51
|
+
class CUInvalidContextError < CUContextError; end
|
52
|
+
class CUContextAlreadyCurrentError < CUContextError; end # @deprecated
|
53
|
+
class CUContextAlreadyInUseError < CUContextError; end
|
54
|
+
class CUUnsupportedLimitError < CUContextError; end
|
55
|
+
class CUPrimaryContextActiveError < CUContextError; end
|
56
|
+
class CUContextIsDestroyedError < CUContextError; end
|
57
|
+
|
58
|
+
class CULaunchError < CUStandardError; end
|
59
|
+
class CULaunchFailedError < CULaunchError; end
|
60
|
+
class CULaunchOutOfResourcesError < CULaunchError; end
|
61
|
+
class CULaunchTimeoutError < CULaunchError; end
|
62
|
+
class CULaunchIncompatibleTexturingError < CULaunchError; end
|
63
|
+
|
64
|
+
class CUParameterError < CUStandardError; end
|
65
|
+
class CUInvalidValueError < CUParameterError; end
|
66
|
+
class CUInvalidHandleError < CUParameterError; end
|
67
|
+
|
68
|
+
class CUMemoryError < CUStandardError; end
|
69
|
+
class CUOutOfMemoryError < CUMemoryError; end
|
70
|
+
|
71
|
+
class CUPeerAccessError < CUStandardError; end
|
72
|
+
class CUPeerAccessAlreadyEnabledError < CUPeerAccessError; end
|
73
|
+
class CUPeerAccessNotEnabledError < CUPeerAccessError; end
|
74
|
+
|
75
|
+
class CULibraryError < CUStandardError; end
|
76
|
+
class CUSharedObjectSymbolNotFoundError < CULibraryError; end
|
77
|
+
class CUSharedObjectInitFailedError < CULibraryError; end
|
78
|
+
|
79
|
+
class CUHardwareError < CUStandardError; end
|
80
|
+
class CUECCUncorrectableError < CUHardwareError; end
|
81
|
+
|
82
|
+
class CUFileError < CUStandardError; end
|
83
|
+
class CUNoBinaryForGPUError < CUFileError; end
|
84
|
+
class CUFileNotFoundError < CUFileError; end
|
85
|
+
class CUInvalidSourceError < CUFileError; end
|
86
|
+
class CUInvalidImageError < CUFileError; end
|
87
|
+
|
88
|
+
class CUReferenceError < CUStandardError; end
|
89
|
+
class CUReferenceNotFoundError < CUReferenceError; end
|
90
|
+
|
91
|
+
class CUProfilerError < CUStandardError; end
|
92
|
+
class CUProfilerDisabledError < CUProfilerError; end
|
93
|
+
class CUProfilerNotInitializedError < CUProfilerError; end
|
94
|
+
class CUProfilerAlreadyStartedError < CUProfilerError; end
|
95
|
+
class CUProfilerAlreadyStoppedError < CUProfilerError; end
|
96
|
+
|
97
|
+
class CUOtherError < CUStandardError; end
|
98
|
+
class CUAlreadyAcquiredError < CUOtherError; end
|
99
|
+
class CUNotReadyError < CUOtherError; end
|
100
|
+
class CUOperatingSystemError < CUOtherError; end
|
101
|
+
|
102
|
+
class CUUnknownError < CUStandardError; end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
# @private
|
108
|
+
module Pvt
|
109
|
+
|
110
|
+
include Error
|
111
|
+
|
112
|
+
def self.handle_error(status, msg = nil)
|
113
|
+
status == CUDA_SUCCESS or raise @error_class_by_enum[API::CUResult[status]], msg
|
114
|
+
nil
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
CUDA_SUCCESS = API::CUResult[:SUCCESS]
|
119
|
+
CUDA_ERROR_NOT_READY = API::CUResult[:ERROR_NOT_READY]
|
120
|
+
|
121
|
+
@error_class_by_enum = {
|
122
|
+
ERROR_NOT_INITIALIZED: CUDeviceNotInitializedError,
|
123
|
+
ERROR_DEINITIALIZED: CUDeviceDeinitializedError,
|
124
|
+
ERROR_NO_DEVICE: CUNoDeviceError,
|
125
|
+
ERROR_INVALID_DEVICE: CUInvalidDeviceError,
|
126
|
+
|
127
|
+
ERROR_MAP_FAILED: CUMapFailedError,
|
128
|
+
ERROR_UNMAP_FAILED: CUUnMapFailedError,
|
129
|
+
ERROR_ARRAY_IS_MAPPED: CUArrayIsMappedError,
|
130
|
+
ERROR_ALREADY_MAPPED: CUAlreadyMappedError,
|
131
|
+
ERROR_NOT_MAPPED: CUNotMappedError,
|
132
|
+
ERROR_NOT_MAPPED_AS_ARRAY: CUNotMappedAsArrayError,
|
133
|
+
ERROR_NOT_MAPPED_AS_POINTER: CUNotMappedAsPointerError,
|
134
|
+
|
135
|
+
ERROR_INVALID_CONTEXT: CUInvalidContextError,
|
136
|
+
ERROR_CONTEXT_ALREADY_CURRENT: CUContextAlreadyCurrentError,
|
137
|
+
ERROR_CONTEXT_ALREADY_IN_USE: CUContextAlreadyInUseError,
|
138
|
+
ERROR_UNSUPPORTED_LIMIT: CUUnsupportedLimitError,
|
139
|
+
ERROR_PRIMARY_CONTEXT_ACTIVE: CUPrimaryContextActiveError,
|
140
|
+
ERROR_CONTEXT_IS_DESTROYED: CUContextIsDestroyedError,
|
141
|
+
|
142
|
+
ERROR_LAUNCH_FAILED: CULaunchFailedError,
|
143
|
+
ERROR_LAUNCH_OUT_OF_RESOURCES: CULaunchOutOfResourcesError,
|
144
|
+
ERROR_LAUNCH_TIMEOUT: CULaunchTimeoutError,
|
145
|
+
ERROR_LAUNCH_INCOMPATIBLE_TEXTURING: CULaunchIncompatibleTexturingError,
|
146
|
+
|
147
|
+
ERROR_INVALID_VALUE: CUInvalidValueError,
|
148
|
+
ERROR_INVALID_HANDLE: CUInvalidHandleError,
|
149
|
+
|
150
|
+
ERROR_OUT_OF_MEMORY: CUOutOfMemoryError,
|
151
|
+
|
152
|
+
ERROR_PEER_ACCESS_ALREADY_ENABLED: CUPeerAccessAlreadyEnabledError,
|
153
|
+
ERROR_PEER_ACCESS_NOT_ENABLED: CUPeerAccessNotEnabledError,
|
154
|
+
|
155
|
+
ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND: CUSharedObjectSymbolNotFoundError,
|
156
|
+
ERROR_SHARED_OBJECT_INIT_FAILED: CUSharedObjectInitFailedError,
|
157
|
+
|
158
|
+
ERROR_ECC_UNCORRECTABLE: CUECCUncorrectableError,
|
159
|
+
|
160
|
+
ERROR_NO_BINARY_FOR_GPU: CUNoBinaryForGPUError,
|
161
|
+
ERROR_FILE_NOT_FOUND: CUFileNotFoundError,
|
162
|
+
ERROR_INVALID_SOURCE: CUInvalidSourceError,
|
163
|
+
ERROR_INVALID_IMAGE: CUInvalidImageError,
|
164
|
+
|
165
|
+
ERROR_NOT_FOUND: CUReferenceNotFoundError,
|
166
|
+
|
167
|
+
ERROR_PROFILER_DISABLED: CUProfilerDisabledError,
|
168
|
+
ERROR_PROFILER_NOT_INITIALIZED: CUProfilerNotInitializedError,
|
169
|
+
ERROR_PROFILER_ALREADY_STARTED: CUProfilerAlreadyStartedError,
|
170
|
+
ERROR_PROFILER_ALREADY_STOPPED: CUProfilerAlreadyStoppedError,
|
171
|
+
|
172
|
+
ERROR_ALREADY_ACQUIRED: CUAlreadyAcquiredError,
|
173
|
+
ERROR_NOT_READY: CUNotReadyError,
|
174
|
+
ERROR_OPERATING_SYSTEM: CUOperatingSystemError,
|
175
|
+
|
176
|
+
ERROR_UNKNOWN: CUUnknownError,
|
177
|
+
}
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
end # module
|
182
|
+
end # module
|