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,39 @@
|
|
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 'test/unit'
|
26
|
+
require_relative 'testbase'
|
27
|
+
|
28
|
+
|
29
|
+
class TestCUVersion < Test::Unit::TestCase
|
30
|
+
|
31
|
+
include CUTestBase
|
32
|
+
|
33
|
+
|
34
|
+
def test_version
|
35
|
+
v = driver_version
|
36
|
+
assert_kind_of(Integer, v)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,107 @@
|
|
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 'rubycu'
|
26
|
+
|
27
|
+
include SGC::CU
|
28
|
+
include SGC::CU::Error
|
29
|
+
|
30
|
+
CUInit.init
|
31
|
+
|
32
|
+
|
33
|
+
module CUTestBase
|
34
|
+
|
35
|
+
def setup
|
36
|
+
@dev = CUDevice.get(ENV['DEVID'].to_i)
|
37
|
+
@ctx = CUContext.create(@dev)
|
38
|
+
@mod = prepare_loaded_module
|
39
|
+
@func = @mod.function("vadd")
|
40
|
+
end
|
41
|
+
|
42
|
+
def teardown
|
43
|
+
@func = nil
|
44
|
+
@mod.unload
|
45
|
+
@mod = nil
|
46
|
+
@ctx.destroy
|
47
|
+
@ctx = nil
|
48
|
+
@dev = nil
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def prepare_ptx
|
53
|
+
if File.exists?('test/vadd.ptx') == false || File.mtime('test/vadd.cu') > File.mtime('test/vadd.ptx')
|
54
|
+
system %{cd test; nvcc --ptx vadd.cu}
|
55
|
+
end
|
56
|
+
'test/vadd.ptx'
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
def prepare_loaded_module
|
61
|
+
path = prepare_ptx
|
62
|
+
m = CUModule.new
|
63
|
+
m.load(path)
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
def assert_device(dev)
|
68
|
+
assert_device_name(dev)
|
69
|
+
assert_device_memory_size(dev)
|
70
|
+
assert_device_capability(dev)
|
71
|
+
assert_device_properties(dev)
|
72
|
+
end
|
73
|
+
|
74
|
+
def assert_device_name(dev)
|
75
|
+
assert(dev.name.size > 0, "Device name failed.")
|
76
|
+
end
|
77
|
+
|
78
|
+
def assert_device_memory_size(dev)
|
79
|
+
assert(dev.total_mem > 0, "Device total memory size failed.")
|
80
|
+
end
|
81
|
+
|
82
|
+
def assert_device_capability(dev)
|
83
|
+
cap = dev.compute_capability
|
84
|
+
assert(cap[:major] > 0 && cap[:minor] >= 0, "Device compute capability failed.")
|
85
|
+
end
|
86
|
+
|
87
|
+
def assert_device_properties(dev)
|
88
|
+
p = dev.properties
|
89
|
+
assert(p[:clock_rate] > 0)
|
90
|
+
assert(p[:max_threads_per_block] > 0)
|
91
|
+
assert(p[:mem_pitch] > 0)
|
92
|
+
assert(p[:regs_per_block] > 0)
|
93
|
+
assert(p[:shared_mem_per_block] > 0)
|
94
|
+
assert(p[:simd_width] > 0)
|
95
|
+
assert(p[:texture_align] > 0)
|
96
|
+
assert(p[:total_constant_memory] > 0)
|
97
|
+
assert_equal(3, p[:max_grid_size].count)
|
98
|
+
assert_kind_of(Integer, p[:max_grid_size][0])
|
99
|
+
assert_kind_of(Integer, p[:max_grid_size][1])
|
100
|
+
assert_kind_of(Integer, p[:max_grid_size][2])
|
101
|
+
assert_equal(3, p[:max_threads_dim].count)
|
102
|
+
assert_kind_of(Integer, p[:max_threads_dim][0])
|
103
|
+
assert_kind_of(Integer, p[:max_threads_dim][1])
|
104
|
+
assert_kind_of(Integer, p[:max_threads_dim][2])
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
@@ -0,0 +1,125 @@
|
|
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 'test/unit'
|
26
|
+
require_relative 'testbase'
|
27
|
+
|
28
|
+
|
29
|
+
class TestCudaDevice < Test::Unit::TestCase
|
30
|
+
|
31
|
+
include CudaTestBase
|
32
|
+
|
33
|
+
|
34
|
+
def test_device_count
|
35
|
+
count = CudaDevice.count
|
36
|
+
assert(count > 0, "Device count failed.")
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def test_device_get_set
|
41
|
+
count = CudaDevice.count
|
42
|
+
(0...count).each do |devid|
|
43
|
+
r = CudaDevice.set(devid)
|
44
|
+
assert_equal(CudaDevice, r)
|
45
|
+
d = CudaDevice.get
|
46
|
+
assert_equal(devid, d)
|
47
|
+
end
|
48
|
+
|
49
|
+
count = CudaDevice.count
|
50
|
+
(0...count).each do |devid|
|
51
|
+
CudaDevice.current = devid
|
52
|
+
d = CudaDevice.current
|
53
|
+
assert_equal(devid, d)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
def test_device_choose
|
59
|
+
count = CudaDevice.count
|
60
|
+
prop = CudaDeviceProp.new
|
61
|
+
devid = CudaDevice.choose(prop)
|
62
|
+
assert(devid >= 0 && devid < count)
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
def test_device_properties
|
67
|
+
prop = CudaDevice.properties
|
68
|
+
assert_instance_of(CudaDeviceProp, prop)
|
69
|
+
# TODO: assert the content of the _prop_.
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
def test_device_flags
|
74
|
+
CudaDeviceFlags.symbols.each do |k|
|
75
|
+
CudaDevice.flags = k
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
def test_device_valid_devices
|
81
|
+
count = CudaDevice.count
|
82
|
+
devs = []
|
83
|
+
(0...count).each do |devid|
|
84
|
+
devs << devid
|
85
|
+
end
|
86
|
+
CudaDevice.valid_devices = devs
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
def test_device_cache_config
|
91
|
+
if CudaDevice.properties.major >= 2
|
92
|
+
CudaFunctionCache.symbols.each do |k|
|
93
|
+
CudaDevice.cache_config = k
|
94
|
+
c = CudaDevice.cache_config
|
95
|
+
assert_equal(k, c)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
def test_device_limit
|
102
|
+
CudaLimit.symbols.each do |k|
|
103
|
+
begin
|
104
|
+
u = CudaDevice.limit(k)
|
105
|
+
CudaDevice.limit = [k, u]
|
106
|
+
v = CudaDevice.limit(k)
|
107
|
+
assert_equal(u, v)
|
108
|
+
rescue CudaUnsupportedLimitError
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
def test_device_reset
|
115
|
+
r = CudaDevice.reset
|
116
|
+
assert_equal(CudaDevice, r)
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
def test_device_synchronize
|
121
|
+
r = CudaDevice.synchronize
|
122
|
+
assert_equal(CudaDevice, r)
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
@@ -0,0 +1,48 @@
|
|
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 'test/unit'
|
26
|
+
require_relative 'testbase'
|
27
|
+
|
28
|
+
|
29
|
+
class TestCudaError < Test::Unit::TestCase
|
30
|
+
|
31
|
+
include CudaTestBase
|
32
|
+
|
33
|
+
|
34
|
+
def test_error
|
35
|
+
CudaError.symbols.each do |k|
|
36
|
+
s = get_error_string(k)
|
37
|
+
assert(s.size > 0)
|
38
|
+
end
|
39
|
+
e = get_last_error
|
40
|
+
s = get_error_string(e)
|
41
|
+
assert(s.size > 0)
|
42
|
+
|
43
|
+
e = peek_at_last_error
|
44
|
+
s = get_error_string(e)
|
45
|
+
assert(s.size > 0)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,78 @@
|
|
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 'test/unit'
|
26
|
+
require_relative 'testbase'
|
27
|
+
|
28
|
+
|
29
|
+
class TestCudaEvent < Test::Unit::TestCase
|
30
|
+
|
31
|
+
include CudaTestBase
|
32
|
+
|
33
|
+
|
34
|
+
def test_event_create_destroy
|
35
|
+
e = CudaEvent.create
|
36
|
+
assert_instance_of(CudaEvent, e)
|
37
|
+
r = e.destroy
|
38
|
+
assert_nil(r)
|
39
|
+
|
40
|
+
e = CudaEvent.create(CudaEventFlags.value(:DEFAULT, :BLOCKING_SYNC))
|
41
|
+
assert_instance_of(CudaEvent, e)
|
42
|
+
r = e.destroy
|
43
|
+
assert_nil(r)
|
44
|
+
|
45
|
+
e = CudaEvent.create(:DEFAULT, :BLOCKING_SYNC)
|
46
|
+
assert_instance_of(CudaEvent, e)
|
47
|
+
r = e.destroy
|
48
|
+
assert_nil(r)
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def test_event_record_synchronize_query
|
53
|
+
e = CudaEvent.create
|
54
|
+
e = e.record
|
55
|
+
assert_instance_of(CudaEvent, e)
|
56
|
+
e = e.synchronize
|
57
|
+
assert_instance_of(CudaEvent, e)
|
58
|
+
b = e.query
|
59
|
+
assert(b)
|
60
|
+
e.destroy
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
def test_event_elapsed_time
|
65
|
+
e1 = CudaEvent.create
|
66
|
+
e2 = CudaEvent.create
|
67
|
+
|
68
|
+
e1.record
|
69
|
+
e2.record
|
70
|
+
e2.synchronize
|
71
|
+
t = CudaEvent.elapsed_time(e1, e2)
|
72
|
+
assert_kind_of(Numeric, t)
|
73
|
+
|
74
|
+
e1.destroy
|
75
|
+
e2.destroy
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,106 @@
|
|
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 'test/unit'
|
26
|
+
require_relative 'testbase'
|
27
|
+
|
28
|
+
|
29
|
+
class TestCudaFunction < Test::Unit::TestCase
|
30
|
+
|
31
|
+
include CudaTestBase
|
32
|
+
|
33
|
+
|
34
|
+
def test_function_name
|
35
|
+
f = CudaFunction.new("vadd")
|
36
|
+
assert_equal("vadd", f.name)
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def test_function_attributes
|
41
|
+
path = prepare_kernel_lib
|
42
|
+
CudaFunction.load_lib_file(path)
|
43
|
+
f = CudaFunction.new("vadd")
|
44
|
+
a = f.attributes
|
45
|
+
assert_instance_of(CudaFunctionAttributes, a)
|
46
|
+
CudaFunction.unload_all_libs
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def test_function_cache_config
|
51
|
+
path = prepare_kernel_lib
|
52
|
+
CudaFunction.load_lib_file(path)
|
53
|
+
f = CudaFunction.new("vadd")
|
54
|
+
CudaFunctionCache.symbols.each do |k|
|
55
|
+
f.cache_config = k
|
56
|
+
end
|
57
|
+
CudaFunction.unload_all_libs
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
def test_function_launch
|
62
|
+
type = :int
|
63
|
+
size = 10
|
64
|
+
nbytes = size*4
|
65
|
+
|
66
|
+
a = Buffer.new(type, size)
|
67
|
+
b = Buffer.new(type, size)
|
68
|
+
c = Buffer.new(type, size)
|
69
|
+
|
70
|
+
p = CudaDeviceMemory.malloc(nbytes)
|
71
|
+
q = CudaDeviceMemory.malloc(nbytes)
|
72
|
+
r = CudaDeviceMemory.malloc(nbytes)
|
73
|
+
|
74
|
+
(0...size).each do |i|
|
75
|
+
a[i] = i
|
76
|
+
b[i] = 2
|
77
|
+
c[i] = 0
|
78
|
+
end
|
79
|
+
|
80
|
+
CudaMemory.memcpy_htod(p, a, nbytes)
|
81
|
+
CudaMemory.memcpy_htod(q, b, nbytes)
|
82
|
+
CudaMemory.memcpy_htod(r, c, nbytes)
|
83
|
+
|
84
|
+
path = prepare_kernel_lib
|
85
|
+
CudaFunction.load_lib_file(path)
|
86
|
+
|
87
|
+
CudaFunction.configure(Dim3.new(1, 1, 1), Dim3.new(size, 1, 1))
|
88
|
+
CudaFunction.setup(p, q, r, size)
|
89
|
+
|
90
|
+
f = CudaFunction.new("vadd")
|
91
|
+
f.launch
|
92
|
+
|
93
|
+
CudaMemory.memcpy_dtoh(c, r, nbytes)
|
94
|
+
|
95
|
+
(0...size).each do |i|
|
96
|
+
assert_equal(a[i] + b[i], c[i])
|
97
|
+
end
|
98
|
+
|
99
|
+
CudaFunction.unload_all_libs
|
100
|
+
|
101
|
+
CudaDeviceMemory.free(p)
|
102
|
+
CudaDeviceMemory.free(q)
|
103
|
+
CudaDeviceMemory.free(r)
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|