sgc-ruby-cuda 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,72 @@
|
|
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 'ffi'
|
26
|
+
|
27
|
+
|
28
|
+
module SGC
|
29
|
+
module Memory
|
30
|
+
|
31
|
+
# A memory pointer class.
|
32
|
+
class MemoryPointer
|
33
|
+
|
34
|
+
# @param [Integer] addr Memory address _addr_ to initialize to.
|
35
|
+
# @return A memory pointer pointing to address _addr_.
|
36
|
+
def initialize(addr = nil)
|
37
|
+
@p = FFI::MemoryPointer.new(:pointer)
|
38
|
+
@p.write_long(addr.to_i)
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
# @return The internal pointer representation.
|
43
|
+
def ptr
|
44
|
+
@p.read_pointer
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
# Set this pointer to point to memory address _addr_.
|
49
|
+
# @param [Integer] addr Memory address to set to.
|
50
|
+
# @return _addr_.
|
51
|
+
def ptr=(addr)
|
52
|
+
@p.write_pointer(addr)
|
53
|
+
addr
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
# @param [Integer] index Index to a memory offset.
|
58
|
+
# @return [MemoryPointer] A memory pointer pointing to the _index_ byte.
|
59
|
+
def offset(index)
|
60
|
+
MemoryPointer.new(@p.read_pointer.to_i + index)
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
# @return The internal representation of a pointer pointing to this memory pointer.
|
65
|
+
def ref
|
66
|
+
@p
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end # module
|
72
|
+
end # module
|
data/lib/rubycu.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'cuda/driver/rubycu'
|
data/lib/rubycuda.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'cuda/runtime/rubycuda'
|
data/test/bad.ptx
ADDED
File without changes
|
@@ -0,0 +1,93 @@
|
|
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 'memory/buffer'
|
27
|
+
|
28
|
+
include SGC::Memory
|
29
|
+
|
30
|
+
|
31
|
+
class TestMemoryBuffer < Test::Unit::TestCase
|
32
|
+
|
33
|
+
def test_buffer_initialize
|
34
|
+
b = Buffer.new(:int, 10)
|
35
|
+
assert_instance_of(Buffer, b)
|
36
|
+
assert_equal(10, b.size)
|
37
|
+
|
38
|
+
b = Buffer.new(:long, 20)
|
39
|
+
assert_instance_of(Buffer, b)
|
40
|
+
assert_equal(20, b.size)
|
41
|
+
|
42
|
+
b = Buffer.new(:float, 30)
|
43
|
+
assert_instance_of(Buffer, b)
|
44
|
+
assert_equal(30, b.size)
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def test_buffer_element_size
|
49
|
+
assert_equal(4, Buffer.element_size(:int))
|
50
|
+
assert_equal(4, Buffer.element_size(:float))
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
def test_buffer_offset
|
55
|
+
b = Buffer.new(:int, 16)
|
56
|
+
c = b.offset(4)
|
57
|
+
assert_kind_of(MemoryPointer, c)
|
58
|
+
|
59
|
+
b = Buffer.new(:int, 10)
|
60
|
+
c = b.offset(5)
|
61
|
+
assert_kind_of(MemoryPointer, c)
|
62
|
+
|
63
|
+
b = Buffer.new(:long, 10)
|
64
|
+
c = b.offset(3)
|
65
|
+
assert_kind_of(MemoryPointer, c)
|
66
|
+
|
67
|
+
b = Buffer.new(:float, 10)
|
68
|
+
c = b.offset(4)
|
69
|
+
assert_kind_of(MemoryPointer, c)
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
def test_buffer_access
|
74
|
+
b = Buffer.new(:int, 10)
|
75
|
+
b[0] = 10
|
76
|
+
assert_equal(10, b[0])
|
77
|
+
b[9] = 20
|
78
|
+
assert_equal(20, b[9])
|
79
|
+
|
80
|
+
b = Buffer.new(:long, 10)
|
81
|
+
b[3] = 2**40
|
82
|
+
assert_equal(2**40, b[3])
|
83
|
+
b[7] = 2**50
|
84
|
+
assert_equal(2**50, b[7])
|
85
|
+
|
86
|
+
b = Buffer.new(:float, 10)
|
87
|
+
b[2] = 3.14
|
88
|
+
assert_in_delta(3.14, b[2])
|
89
|
+
b[8] = 9.33
|
90
|
+
assert_in_delta(9.33, b[8])
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
@@ -0,0 +1,148 @@
|
|
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 TestCUContext < Test::Unit::TestCase
|
30
|
+
|
31
|
+
include CUTestBase
|
32
|
+
|
33
|
+
|
34
|
+
def test_context_create_destroy
|
35
|
+
c = CUContext.create(@dev)
|
36
|
+
assert_instance_of(CUContext, c)
|
37
|
+
c = c.destroy
|
38
|
+
assert_nil(c)
|
39
|
+
c = CUContext.create(0, @dev)
|
40
|
+
assert_instance_of(CUContext, c)
|
41
|
+
c = c.destroy
|
42
|
+
assert_nil(c)
|
43
|
+
CUContextFlags.symbols.each do |k|
|
44
|
+
c = CUContext.create(k, @dev)
|
45
|
+
assert_instance_of(CUContext, c)
|
46
|
+
c = c.destroy
|
47
|
+
assert_nil(c)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def test_context_current
|
53
|
+
c = CUContext.current
|
54
|
+
assert_instance_of(CUContext, c)
|
55
|
+
CUContext.current = c
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def test_context_attach_detach
|
60
|
+
c1 = @ctx.attach(0)
|
61
|
+
assert_instance_of(CUContext, c1)
|
62
|
+
c2 = @ctx.detach
|
63
|
+
assert_nil(c2)
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
def test_context_attach_nonzero_flags_detach
|
68
|
+
assert_raise(CUInvalidValueError) do
|
69
|
+
c1 = @ctx.attach(999)
|
70
|
+
assert_instance_of(CUContext, c1)
|
71
|
+
c2 = @ctx.detach
|
72
|
+
assert_nil(c2)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
def test_context_push_pop_current
|
78
|
+
c1 = CUContext.pop_current
|
79
|
+
assert_instance_of(CUContext, c1)
|
80
|
+
c2 = @ctx.push_current
|
81
|
+
assert_instance_of(CUContext, c2)
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
def test_context_get_device
|
86
|
+
d = CUContext.device
|
87
|
+
assert_device(d)
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
def test_context_get_set_limit
|
92
|
+
if @dev.compute_capability[:major] >= 2
|
93
|
+
assert_limit = Proc.new { |&b| assert_nothing_raised(&b) }
|
94
|
+
else
|
95
|
+
assert_limit = Proc.new { |&b| assert_raise(CUUnsupportedLimitError, &b) }
|
96
|
+
end
|
97
|
+
assert_limit.call do
|
98
|
+
stack_size = CUContext.limit(:STACK_SIZE)
|
99
|
+
assert_kind_of(Integer, stack_size)
|
100
|
+
fifo_size = CUContext.limit(:PRINTF_FIFO_SIZE)
|
101
|
+
assert_kind_of(Integer, fifo_size)
|
102
|
+
heap_size = CUContext.limit(:MALLOC_HEAP_SIZE)
|
103
|
+
assert_kind_of(Integer, heap_size)
|
104
|
+
CUContext.limit = [:STACK_SIZE, stack_size]
|
105
|
+
s = CUContext.limit(:STACK_SIZE)
|
106
|
+
assert_equal(stack_size, s)
|
107
|
+
CUContext.limit = [:PRINTF_FIFO_SIZE, fifo_size]
|
108
|
+
s = CUContext.limit(:PRINTF_FIFO_SIZE)
|
109
|
+
assert_equal(fifo_size, s)
|
110
|
+
CUContext.limit = :MALLOC_HEAP_SIZE, heap_size
|
111
|
+
s = CUContext.limit(:MALLOC_HEAP_SIZE)
|
112
|
+
assert_equal(heap_size, s)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
def test_context_get_set_cache_config
|
118
|
+
if @dev.compute_capability[:major] >= 2
|
119
|
+
config = CUContext.cache_config
|
120
|
+
assert_not_nil(CUFunctionCache[config])
|
121
|
+
CUContext.cache_config = config
|
122
|
+
c = CUContext.cache_config
|
123
|
+
assert_equal(config, c)
|
124
|
+
else
|
125
|
+
config = CUContext.cache_config
|
126
|
+
assert_equal(:PREFER_NONE, config)
|
127
|
+
CUContext.cache_config = config
|
128
|
+
c = CUContext.cache_config
|
129
|
+
assert_equal(:PREFER_NONE, c)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
def test_context_get_api_version
|
135
|
+
v1 = @ctx.api_version
|
136
|
+
v2 = CUContext.api_version
|
137
|
+
assert_kind_of(Integer, v1)
|
138
|
+
assert_kind_of(Integer, v2)
|
139
|
+
assert(v1 == v2)
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
def test_context_synchronize
|
144
|
+
s = CUContext.synchronize
|
145
|
+
assert_nil(s)
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
@@ -0,0 +1,69 @@
|
|
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 TestCUDevice < Test::Unit::TestCase
|
30
|
+
|
31
|
+
include CUTestBase
|
32
|
+
|
33
|
+
|
34
|
+
def test_device_count
|
35
|
+
count = CUDevice.count
|
36
|
+
assert(count > 0, "Device count failed.")
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def test_device_query
|
41
|
+
d = @dev
|
42
|
+
assert_instance_of(CUDevice, d)
|
43
|
+
assert_device_name(d)
|
44
|
+
assert_device_memory_size(d)
|
45
|
+
assert_device_capability(d)
|
46
|
+
assert_device_properties(d)
|
47
|
+
CUDeviceAttribute.symbols.each do |k|
|
48
|
+
v = d.attribute(k)
|
49
|
+
assert_instance_of(Fixnum, v)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
def test_device_malloc_free
|
55
|
+
p = CUDevice.malloc(1024)
|
56
|
+
assert_instance_of(CUDevicePtr, p)
|
57
|
+
r = p.free
|
58
|
+
assert_nil(r)
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
def test_device_malloc_with_huge_mem
|
63
|
+
assert_raise(CUOutOfMemoryError) do
|
64
|
+
size = @dev.total_mem + 1
|
65
|
+
CUDevice.malloc(size)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,43 @@
|
|
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 TestCUDevicePtr < Test::Unit::TestCase
|
30
|
+
|
31
|
+
include CUTestBase
|
32
|
+
|
33
|
+
|
34
|
+
def test_device_ptr_offset
|
35
|
+
devptr = CUDevice.malloc(1024)
|
36
|
+
p = devptr.offset(1024)
|
37
|
+
assert_instance_of(CUDevicePtr, p)
|
38
|
+
p = devptr.offset(-1024)
|
39
|
+
assert_instance_of(CUDevicePtr, p)
|
40
|
+
devptr.free
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,81 @@
|
|
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 TestCUEvent < Test::Unit::TestCase
|
30
|
+
|
31
|
+
include CUTestBase
|
32
|
+
|
33
|
+
|
34
|
+
def test_event_create_destroy
|
35
|
+
e = CUEvent.create
|
36
|
+
assert_instance_of(CUEvent, e)
|
37
|
+
e = e.destroy
|
38
|
+
assert_nil(e)
|
39
|
+
|
40
|
+
e = CUEvent.create(:DEFAULT)
|
41
|
+
assert_instance_of(CUEvent, e)
|
42
|
+
e = e.destroy
|
43
|
+
assert_nil(e)
|
44
|
+
|
45
|
+
e = CUEvent.create(:DEFAULT, :BLOCKING_SYNC)
|
46
|
+
assert_instance_of(CUEvent, e)
|
47
|
+
e = e.destroy
|
48
|
+
assert_nil(e)
|
49
|
+
|
50
|
+
e = CUEvent.create([:BLOCKING_SYNC, :DISABLE_TIMING])
|
51
|
+
assert_instance_of(CUEvent, e)
|
52
|
+
e = e.destroy
|
53
|
+
assert_nil(e)
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
def test_event_record_synchronize_query
|
58
|
+
e = CUEvent.create(:DEFAULT)
|
59
|
+
e = e.record(0)
|
60
|
+
assert_instance_of(CUEvent, e)
|
61
|
+
e = e.synchronize
|
62
|
+
assert_instance_of(CUEvent, e)
|
63
|
+
b = e.query
|
64
|
+
assert(b)
|
65
|
+
e.destroy
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
def test_event_elapsed_time
|
70
|
+
e1 = CUEvent.create(:DEFAULT)
|
71
|
+
e2 = CUEvent.create(:DEFAULT)
|
72
|
+
e1.record(0)
|
73
|
+
e2.record(0)
|
74
|
+
e2.synchronize
|
75
|
+
elapsed = CUEvent.elapsed_time(e1, e2)
|
76
|
+
assert_instance_of(Float, elapsed)
|
77
|
+
e1.destroy
|
78
|
+
e2.destroy
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|