sgc-ruby-cuda 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/.yardopts +2 -0
  2. data/COPYING +674 -0
  3. data/README.rdoc +106 -0
  4. data/Rakefile +76 -0
  5. data/doc/devel.rdoc +77 -0
  6. data/doc/features.rdoc +55 -0
  7. data/lib/cuda/driver/context.rb +236 -0
  8. data/lib/cuda/driver/cu.rb +60 -0
  9. data/lib/cuda/driver/device.rb +155 -0
  10. data/lib/cuda/driver/deviceptr.rb +69 -0
  11. data/lib/cuda/driver/error.rb +182 -0
  12. data/lib/cuda/driver/event.rb +124 -0
  13. data/lib/cuda/driver/ffi-cu.rb +620 -0
  14. data/lib/cuda/driver/function.rb +293 -0
  15. data/lib/cuda/driver/init.rb +45 -0
  16. data/lib/cuda/driver/memory.rb +134 -0
  17. data/lib/cuda/driver/module.rb +142 -0
  18. data/lib/cuda/driver/rubycu.rb +37 -0
  19. data/lib/cuda/driver/stream.rb +128 -0
  20. data/lib/cuda/driver/version.rb +42 -0
  21. data/lib/cuda/runtime/cuda.rb +65 -0
  22. data/lib/cuda/runtime/device.rb +175 -0
  23. data/lib/cuda/runtime/error.rb +197 -0
  24. data/lib/cuda/runtime/event.rb +117 -0
  25. data/lib/cuda/runtime/ffi-cuda.rb +588 -0
  26. data/lib/cuda/runtime/function.rb +161 -0
  27. data/lib/cuda/runtime/memory.rb +110 -0
  28. data/lib/cuda/runtime/rubycuda.rb +34 -0
  29. data/lib/cuda/runtime/stream.rb +126 -0
  30. data/lib/cuda/runtime/thread.rb +81 -0
  31. data/lib/cuda/runtime/version.rb +51 -0
  32. data/lib/ffi/prettystruct.rb +32 -0
  33. data/lib/helpers/flags.rb +82 -0
  34. data/lib/helpers/interface/ienum.rb +45 -0
  35. data/lib/helpers/klass.rb +45 -0
  36. data/lib/memory/buffer.rb +125 -0
  37. data/lib/memory/interface/ibuffer.rb +63 -0
  38. data/lib/memory/pointer.rb +72 -0
  39. data/lib/rubycu.rb +1 -0
  40. data/lib/rubycuda.rb +1 -0
  41. data/test/bad.ptx +0 -0
  42. data/test/memory/test_buffer.rb +93 -0
  43. data/test/rubycu/test_cucontext.rb +148 -0
  44. data/test/rubycu/test_cudevice.rb +69 -0
  45. data/test/rubycu/test_cudeviceptr.rb +43 -0
  46. data/test/rubycu/test_cuevent.rb +81 -0
  47. data/test/rubycu/test_cufunction.rb +165 -0
  48. data/test/rubycu/test_cumemory.rb +113 -0
  49. data/test/rubycu/test_cumodule.rb +114 -0
  50. data/test/rubycu/test_custream.rb +77 -0
  51. data/test/rubycu/test_cuversion.rb +39 -0
  52. data/test/rubycu/testbase.rb +107 -0
  53. data/test/rubycuda/test_cudadevice.rb +125 -0
  54. data/test/rubycuda/test_cudaerror.rb +48 -0
  55. data/test/rubycuda/test_cudaevent.rb +78 -0
  56. data/test/rubycuda/test_cudafunction.rb +106 -0
  57. data/test/rubycuda/test_cudamemory.rb +90 -0
  58. data/test/rubycuda/test_cudastream.rb +72 -0
  59. data/test/rubycuda/test_cudathread.rb +69 -0
  60. data/test/rubycuda/test_cudaversion.rb +41 -0
  61. data/test/rubycuda/testbase.rb +67 -0
  62. data/test/vadd.cu +21 -0
  63. data/version.rb +1 -0
  64. metadata +180 -0
@@ -0,0 +1,142 @@
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
+ require 'cuda/driver/function'
29
+
30
+
31
+ module SGC
32
+ module CU
33
+
34
+ class CUModule
35
+
36
+ # Allocate a CUDA module.
37
+ def initialize
38
+ @pmod = FFI::MemoryPointer.new(:CUModule)
39
+ end
40
+
41
+
42
+ # Load a compute module from the file at _path_ into the current CUDA context.
43
+ # The file should be a cubin file or a PTX file.
44
+ #
45
+ # A PTX file may be obtained by compiling the .cu file using nvcc with -ptx option.
46
+ # $ nvcc -ptx vadd.cu
47
+ #
48
+ # @param [String] path The path of the file to load.
49
+ # @return [CUModule] This CUDA module.
50
+ def load(path)
51
+ status = API::cuModuleLoad(@pmod, path)
52
+ Pvt::handle_error(status, "Failed to load module: path = #{path}.")
53
+ self
54
+ end
55
+
56
+
57
+ # Load a compute module from the String _image_str_ into the current CUDA context.
58
+ # @param [String] image_str A string which contains a cubin or a PTX data.
59
+ # @return [CUModule] This CUDA module.
60
+ #
61
+ # @see #load
62
+ def load_data(image_str)
63
+ status = API::cuModuleLoadData(@pmod, image_str)
64
+ Pvt::handle_error(status, "Failed to load module data.")
65
+ self
66
+ end
67
+
68
+
69
+ # @note Not implemented yet.
70
+ #
71
+ # @see #load
72
+ def load_data_ex
73
+ raise NotImplementedError
74
+ end
75
+
76
+
77
+ # @note Not implemented yet.
78
+ #
79
+ # @see #load
80
+ def load_fat_binary
81
+ raise NotImplementedError
82
+ end
83
+
84
+
85
+ # Unload this CUDA module from the current CUDA context.
86
+ # @return [CUModule] This CUDA module.
87
+ def unload
88
+ status = API::cuModuleUnload(self.to_api)
89
+ Pvt::handle_error(status, "Failed to unload module.")
90
+ self
91
+ end
92
+
93
+
94
+ # Lookup for a CUDA function corresponds to the function name _name_ in the loaded compute module.
95
+ # A compute module was loaded with {CUModule#load} and alike methods.
96
+ # @param [String] name The name of the function to lookup in the loaded compute modules.
97
+ # @return [CUFunction] The CUDA function corresponds to _name_ in the loaded compute module.
98
+ def function(name)
99
+ p = FFI::MemoryPointer.new(:CUFunction)
100
+ status = API::cuModuleGetFunction(p, self.to_api, name)
101
+ Pvt::handle_error(status, "Failed to get module function: name = #{name}.")
102
+ CUFunction.send(:new, p)
103
+ end
104
+
105
+
106
+ # Lookup for the device pointer and the size of the global variable _name_ in the loaded compute modules.
107
+ # @param [String] name The name of the global variable to lookup in the loaded compute modules.
108
+ # @return [Array(CUDevicePtr, Integer)] An array with a device pointer to the global variable and its size in bytes.
109
+ def global(name)
110
+ pdevptr = FFI::MemoryPointer.new(:CUDevicePtr)
111
+ psize = FFI::MemoryPointer.new(:size_t)
112
+ status = API::cuModuleGetGlobal(pdevptr, psize, self.to_api, name)
113
+ Pvt::handle_error(status, "Failed to get module global: name = #{name}.")
114
+ [CUDevicePtr.send(:new, pdevptr), API::read_size_t(psize)]
115
+ end
116
+
117
+
118
+ # @return A texture reference corresponds to the texture _name_ in the loaded compute module.
119
+ #
120
+ # @note Not implemented yet.
121
+ def texref(name)
122
+ raise NotImplementedError
123
+ end
124
+
125
+
126
+ # @return A surface texture reference corresponds to the surface _name_ in the loaded compute module.
127
+ #
128
+ # @note Not implemented yet.
129
+ def surfref(name)
130
+ raise NotImplementedError
131
+ end
132
+
133
+
134
+ # @private
135
+ def to_api
136
+ API::read_cufunction(@pmod)
137
+ end
138
+
139
+ end
140
+
141
+ end # module
142
+ end # module
@@ -0,0 +1,37 @@
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
+ require 'cuda/driver/init'
29
+ require 'cuda/driver/version'
30
+ require 'cuda/driver/device'
31
+ require 'cuda/driver/context'
32
+ require 'cuda/driver/deviceptr'
33
+ require 'cuda/driver/function'
34
+ require 'cuda/driver/memory'
35
+ require 'cuda/driver/module'
36
+ require 'cuda/driver/stream'
37
+ require 'cuda/driver/event'
@@ -0,0 +1,128 @@
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 CUStream
33
+
34
+ # Create and return a stream with _flags_.
35
+ # @overload create
36
+ # @overload create(flags)
37
+ # @param [Integer] flags Currently _flags_ must be set to zero.
38
+ # @return [CUStream] A CUDA stream created with _flags_.
39
+ def self.create(flags = 0)
40
+ p = FFI::MemoryPointer.new(:CUStream)
41
+ status = API::cuStreamCreate(p, flags)
42
+ Pvt::handle_error(status, "Failed to create stream: flags = #{flags}.")
43
+ new(p)
44
+ end
45
+
46
+
47
+ # Destroy this CUDA stream.
48
+ def destroy
49
+ status = API::cuStreamDestroy(self.to_api)
50
+ Pvt::handle_error(status, "Failed to destroy stream.")
51
+ nil
52
+ end
53
+
54
+
55
+ # @return [Boolean] Return true if all operations in this CUDA stream have completed. Otherwise, return false.
56
+ def query
57
+ status = API::cuStreamQuery(self.to_api)
58
+ if status == Pvt::CUDA_SUCCESS
59
+ return true
60
+ elsif status == Pvt::CUDA_ERROR_NOT_READY
61
+ return false
62
+ end
63
+ Pvt::handle_error(status, "Failed to query stream.")
64
+ raise CUStandardError, "Error handling fails to catch this error."
65
+ end
66
+
67
+
68
+ # Block the calling CPU thread until all operations in this CUDA stream complete.
69
+ # @return [CUStream] This CUDA stream.
70
+ def synchronize
71
+ status = API::cuStreamSynchronize(self.to_api)
72
+ Pvt::handle_error(status, "Failed to synchronize stream.")
73
+ self
74
+ end
75
+
76
+
77
+ # Let all future operations submitted to this CUDA stream wait until _event_ (CUEvent) complete before beginning execution.
78
+ # @overload wait_event(event)
79
+ # @overload wait_event(event, flags)
80
+ # @param [CUEvent] event The event to wait for.
81
+ # @param [Integer] flags Currently _flags_ must be set to zero.
82
+ # @return [CUStream] This CUDA stream.
83
+ def wait_event(event, flags = 0)
84
+ status = API::cuStreamWaitEvent(self.to_api, event.to_api, flags)
85
+ Pvt::handle_error(status, "Failed to make stream's future operations to wait event: flags = #{flags}.")
86
+ self
87
+ end
88
+
89
+
90
+ # Let all future operations submitted to any stream in this context wait until _event_ (CUEvent) complete before beginning execution.
91
+ # @overload wait_event(event)
92
+ # @overload wait_event(event, flags)
93
+ # @param (see CUStream#wait_event)
94
+ def self.wait_event(event, flags = 0)
95
+ status = API::cuStreamWaitEvent(nil, event.to_api, flags)
96
+ Pvt::handle_error(status, "Failed to make any stream's future operations to wait event: flags = #{flags}.")
97
+ nil
98
+ end
99
+
100
+
101
+ # @private
102
+ def initialize(ptr)
103
+ @pstream = ptr
104
+ end
105
+ private_class_method :new
106
+
107
+
108
+ # @private
109
+ def to_api
110
+ API::read_custream(@pstream)
111
+ end
112
+
113
+ end
114
+
115
+ # @private
116
+ module Pvt
117
+
118
+ def self.parse_stream(stream)
119
+ if stream.kind_of?(CUStream)
120
+ return stream.to_api
121
+ end
122
+ nil
123
+ end
124
+
125
+ end
126
+
127
+ end # module
128
+ end # module
@@ -0,0 +1,42 @@
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
+ # @return [Integer] The CUDA driver version.
33
+ def driver_version
34
+ p = FFI::MemoryPointer.new(:int)
35
+ status = API::cuDriverGetVersion(p)
36
+ Pvt::handle_error(status, "Failed to get the CUDA driver version.")
37
+ p.read_int
38
+ end
39
+ module_function :driver_version
40
+
41
+ end # module
42
+ end # module
@@ -0,0 +1,65 @@
1
+ #
2
+ # Copyright (c) 2010-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/runtime/ffi-cuda'
26
+ require 'memory/buffer'
27
+
28
+
29
+ module SGC
30
+ module Cuda
31
+
32
+ include SGC::Memory
33
+
34
+ class CudaError < API::Enum; end # @see API::CudaError
35
+ class CudaDeviceFlags < API::Enum; end # @see API::CudaDeviceFlags
36
+ class CudaEventFlags < API::Enum; end # @see API::CudaEventFlags
37
+ class CudaHostAllocFlags < API::Enum; end # @see API::CudaHostAllocFlags
38
+ class CudaHostRegisterFlags < API::Enum; end # @see API::CudaHostRegisterFlags
39
+ class CudaArrayFlags < API::Enum; end # @see API::CudaArrayFlags
40
+ class CudaMemoryType < API::Enum; end # @see API::CudaMemoryType
41
+ class CudaMemcpyKind < API::Enum; end # @see API::CudaMemcpyKind
42
+ class CudaChannelFormatKind < API::Enum; end # @see API::CudaChannelFormatKind
43
+ class CudaFunctionCache < API::Enum; end # @see API::CudaFunctionCache
44
+ class CudaLimit < API::Enum; end # @see API::CudaLimit
45
+ class CudaOutputMode < API::Enum; end # @see API::CudaOutputMode
46
+ class CudaComputeMode < API::Enum; end # @see API::CudaComputeMode
47
+ class CudaSurfaceBoundaryMode < API::Enum; end # @see API::CudaSurfaceBoundaryMode
48
+ class CudaSurfaceFormatMode < API::Enum; end # @see API::CudaSurfaceFormatMode
49
+ class CudaTextureAddressMode < API::Enum; end # @see API::CudaTextureAddressMode
50
+ class CudaTextureFilterMode < API::Enum; end # @see API::CudaTextureFilterMode
51
+ class CudaTextureReadMode < API::Enum; end # @see API::CudaTextureReadMode
52
+
53
+ class Dim3 < API::Dim3; end
54
+ class CudaDeviceProp < API::CudaDeviceProp; end
55
+ class CudaFunctionAttributes < API::CudaFunctionAttributes; end
56
+ class CudaChannelFormatDesc < API::CudaChannelFormatDesc; end
57
+ class CudaPitchedPtr < API::CudaPitchedPtr; end
58
+ class CudaPos < API::CudaPos; end
59
+ class CudaExtent < API::CudaExtent; end
60
+ class CudaMemcpy3DParms < API::CudaMemcpy3DParms; end
61
+ class TextureReference < API::TextureReference; end
62
+ class SurfaceReference < API::SurfaceReference; end
63
+
64
+ end # module
65
+ end # module
@@ -0,0 +1,175 @@
1
+ #
2
+ # Copyright (c) 2010-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/runtime/ffi-cuda'
26
+ require 'cuda/runtime/error'
27
+
28
+
29
+ module SGC
30
+ module Cuda
31
+
32
+ class CudaDevice
33
+
34
+ # @return [Integer] The number of CUDA devices.
35
+ def self.count
36
+ p = FFI::MemoryPointer.new(:int)
37
+ status = API::cudaGetDeviceCount(p)
38
+ Pvt::handle_error(status, "Failed to get device count.")
39
+ p.read_int
40
+ end
41
+
42
+
43
+ # @return [Integer] The index of the current CUDA device in use.
44
+ def self.get
45
+ p = FFI::MemoryPointer.new(:int)
46
+ status = API::cudaGetDevice(p)
47
+ Pvt::handle_error(status, "Failed to get current device.")
48
+ p.read_int
49
+ end
50
+ class << self; alias_method :current, :get; end
51
+
52
+
53
+ # Set _devid_ as the current CUDA device.
54
+ # @param [Integer] devid The index (0..CudaDevice.count-1) of the CUDA device to set as current.
55
+ # @return [Class] This class.
56
+ def self.set(devid)
57
+ status = API::cudaSetDevice(devid)
58
+ Pvt::handle_error(status, "Failed to set current device: devid = #{devid}.")
59
+ self
60
+ end
61
+ class << self; alias_method :current=, :set; end
62
+
63
+
64
+ # @param [CudaDeviceProp] prop The criteria for choosing a CUDA device.
65
+ # @return [Integer] The index of the CUDA device best matches the criteria.
66
+ def self.choose(prop)
67
+ pdev = FFI::MemoryPointer.new(:int)
68
+ status = API::cudaChooseDevice(pdev, prop.to_ptr)
69
+ Pvt::handle_error(status, "Failed to choose a device with criteria.")
70
+ pdev.read_int
71
+ end
72
+
73
+
74
+ # @param [Integer] devid The index of the device to query.
75
+ # @return [CUDeviceProp] The properties of the device _devid_.
76
+ def self.properties(devid = self.get)
77
+ prop = CudaDeviceProp.new
78
+ status = API::cudaGetDeviceProperties(prop.to_ptr, devid)
79
+ Pvt::handle_error(status, "Failed to get device properties: devid = #{devid}.")
80
+ prop
81
+ end
82
+
83
+
84
+ # Set the flags to be used for device execution.
85
+ # @param [Integer, CudaDeviceFlags, Array<Integer, CudaDeviceFlags>] flags The flags for device execution.
86
+ def self.flags=(flags)
87
+ f = CudaDeviceFlags.value(flags)
88
+ status = API::cudaSetDeviceFlags(f)
89
+ Pvt::handle_error(status, "Failed to set device flags: flags = #{flags}.")
90
+ end
91
+
92
+
93
+ # Set the list of CUDA devices that can be used.
94
+ # @param [Array] devs The list of CUDA device indexes.
95
+ def self.valid_devices=(devs)
96
+ p = FFI::MemoryPointer.new(:int, devs.count)
97
+ devs.each_with_index do |devid, i|
98
+ p[i].write_int(devid)
99
+ end
100
+ status = API::cudaSetValidDevices(p, devs.count)
101
+ Pvt::handle_error(status, "Failed to set valid devices: devs = #{devs}.")
102
+ end
103
+
104
+
105
+ # @return [CudaFunctionCache] The cache config of the current CUDA device.
106
+ #
107
+ # @since CUDA 4.0
108
+ def self.cache_config
109
+ p = FFI::MemoryPointer.new(:enum)
110
+ status = API::cudaDeviceGetCacheConfig(p)
111
+ Pvt::handle_error(status, "Failed to get the current CUDA device cache config.")
112
+ CudaFunctionCache[API::read_enum(p)]
113
+ end
114
+
115
+
116
+ # Set the cache config of the current CUDA device to _conf_.
117
+ # @param [CudaFunctionCache] conf The cache config of the current CUDA device to set to.
118
+ #
119
+ # @since CUDA 4.0
120
+ def self.cache_config=(conf)
121
+ status = API::cudaDeviceSetCacheConfig(conf)
122
+ Pvt::handle_error(status, "Failed to set the current CUDA device cache config.")
123
+ end
124
+
125
+
126
+ # @param [CudaLimit] lim The particular limit attribute to query.
127
+ # @return [CudaLimit] The limit _lim_ of the current CUDA device.
128
+ #
129
+ # @since CUDA 4.0
130
+ def self.limit(lim)
131
+ p = FFI::MemoryPointer.new(:size_t)
132
+ status = API::cudaDeviceGetLimit(p, lim)
133
+ Pvt::handle_error(status, "Failed to get the current CUDA device limit: limit = #{lim}.")
134
+ API::read_size_t(p)
135
+ end
136
+
137
+
138
+ # Set the limit _lim_ of the current CUDA device.
139
+ # @param [CudaLimit] lim The particular limit attribute to set.
140
+ # @param [Integer] value The value to set the limit to.
141
+ #
142
+ # @since CUDA 4.0
143
+ def self.limit=(*lim_val_pair)
144
+ lim, val = lim_val_pair.flatten
145
+ lim != nil && val != nil or raise ArgumentError, "Invalid limit and value pair given: limit = #{lim}, value = #{val}."
146
+ status = API::cudaDeviceSetLimit(lim, val)
147
+ Pvt::handle_error(status, "Failed to set the current CUDA device limit: limit = #{lim}, value = #{val}")
148
+ end
149
+
150
+
151
+ # Destroy all allocations and reset all state on the current CUDA device.
152
+ # @return [Class] This class.
153
+ #
154
+ # @since CUDA 4.0
155
+ def self.reset
156
+ status = API::cudaDeviceReset()
157
+ Pvt::handle_error(status, "Failed to reset the current CUDA device.")
158
+ self
159
+ end
160
+
161
+
162
+ # Block until all the tasks of the current CUDA device complete.
163
+ # @return [Class] This class.
164
+ #
165
+ # @since CUDA 4.0
166
+ def self.synchronize
167
+ status = API::cudaDeviceSynchronize()
168
+ Pvt::handle_error(status, "Failed to synchronize the current CUDA device.")
169
+ self
170
+ end
171
+
172
+ end
173
+
174
+ end # module
175
+ end # module