cumo 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/3rd_party/LICENSE.txt +60 -0
- data/3rd_party/mkmf-cu/lib/mkmf-cu/cli.rb +13 -1
- data/LICENSE.txt +1 -62
- data/README.md +33 -29
- data/bench/cumo_bench.rb +47 -25
- data/bench/numo_bench.rb +27 -25
- data/docs/src-tree.md +16 -0
- data/ext/cumo/cuda/cublas.c +69 -219
- data/ext/cumo/cuda/memory_pool_impl.hpp +1 -0
- data/ext/cumo/cuda/runtime.c +2 -14
- data/ext/cumo/cumo.c +16 -16
- data/ext/cumo/include/cumo.h +2 -2
- data/ext/cumo/include/cumo/cuda/cublas.h +6 -129
- data/ext/cumo/include/cumo/cuda/runtime.h +16 -0
- data/ext/cumo/include/cumo/indexer.h +46 -63
- data/ext/cumo/include/cumo/intern.h +58 -112
- data/ext/cumo/include/cumo/narray.h +214 -185
- data/ext/cumo/include/cumo/narray_kernel.h +66 -37
- data/ext/cumo/include/cumo/ndloop.h +42 -42
- data/ext/cumo/include/cumo/reduce_kernel.h +55 -71
- data/ext/cumo/include/cumo/template.h +56 -51
- data/ext/cumo/include/cumo/template_kernel.h +31 -31
- data/ext/cumo/include/cumo/types/bit.h +3 -3
- data/ext/cumo/include/cumo/types/bit_kernel.h +2 -2
- data/ext/cumo/include/cumo/types/complex.h +126 -126
- data/ext/cumo/include/cumo/types/complex_kernel.h +126 -126
- data/ext/cumo/include/cumo/types/complex_macro.h +28 -28
- data/ext/cumo/include/cumo/types/complex_macro_kernel.h +20 -20
- data/ext/cumo/include/cumo/types/dcomplex.h +5 -5
- data/ext/cumo/include/cumo/types/dcomplex_kernel.h +1 -1
- data/ext/cumo/include/cumo/types/int_macro.h +1 -1
- data/ext/cumo/include/cumo/types/int_macro_kernel.h +1 -1
- data/ext/cumo/include/cumo/types/robj_macro.h +30 -30
- data/ext/cumo/include/cumo/types/scomplex.h +5 -5
- data/ext/cumo/include/cumo/types/scomplex_kernel.h +1 -1
- data/ext/cumo/narray/array.c +143 -143
- data/ext/cumo/narray/data.c +184 -184
- data/ext/cumo/narray/gen/cogen.rb +5 -2
- data/ext/cumo/narray/gen/cogen_kernel.rb +5 -2
- data/ext/cumo/narray/gen/def/dcomplex.rb +1 -1
- data/ext/cumo/narray/gen/def/scomplex.rb +1 -1
- data/ext/cumo/narray/gen/erbln.rb +132 -0
- data/ext/cumo/narray/gen/erbpp2.rb +18 -13
- data/ext/cumo/narray/gen/narray_def.rb +3 -3
- data/ext/cumo/narray/gen/spec.rb +2 -2
- data/ext/cumo/narray/gen/tmpl/accum.c +15 -15
- data/ext/cumo/narray/gen/tmpl/accum_binary.c +22 -22
- data/ext/cumo/narray/gen/tmpl/accum_binary_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/accum_index.c +30 -30
- data/ext/cumo/narray/gen/tmpl/accum_index_kernel.cu +2 -2
- data/ext/cumo/narray/gen/tmpl/accum_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/alloc_func.c +14 -14
- data/ext/cumo/narray/gen/tmpl/allocate.c +11 -11
- data/ext/cumo/narray/gen/tmpl/aref.c +2 -2
- data/ext/cumo/narray/gen/tmpl/aref_cpu.c +4 -4
- data/ext/cumo/narray/gen/tmpl/aset.c +2 -2
- data/ext/cumo/narray/gen/tmpl/binary.c +28 -28
- data/ext/cumo/narray/gen/tmpl/binary2.c +18 -18
- data/ext/cumo/narray/gen/tmpl/binary2_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/binary_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/binary_s.c +13 -13
- data/ext/cumo/narray/gen/tmpl/binary_s_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/bincount.c +23 -23
- data/ext/cumo/narray/gen/tmpl/cast.c +7 -7
- data/ext/cumo/narray/gen/tmpl/cast_array.c +3 -3
- data/ext/cumo/narray/gen/tmpl/clip.c +38 -38
- data/ext/cumo/narray/gen/tmpl/complex_accum_kernel.cu +2 -2
- data/ext/cumo/narray/gen/tmpl/cond_binary.c +19 -19
- data/ext/cumo/narray/gen/tmpl/cond_binary_kernel.cu +7 -7
- data/ext/cumo/narray/gen/tmpl/cond_unary.c +15 -15
- data/ext/cumo/narray/gen/tmpl/cum.c +15 -15
- data/ext/cumo/narray/gen/tmpl/each.c +9 -9
- data/ext/cumo/narray/gen/tmpl/each_with_index.c +9 -9
- data/ext/cumo/narray/gen/tmpl/ewcomp.c +15 -15
- data/ext/cumo/narray/gen/tmpl/ewcomp_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/extract_cpu.c +5 -5
- data/ext/cumo/narray/gen/tmpl/extract_data.c +12 -12
- data/ext/cumo/narray/gen/tmpl/eye.c +9 -9
- data/ext/cumo/narray/gen/tmpl/eye_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/fill.c +9 -9
- data/ext/cumo/narray/gen/tmpl/fill_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/float_accum_kernel.cu +1 -1
- data/ext/cumo/narray/gen/tmpl/format.c +11 -11
- data/ext/cumo/narray/gen/tmpl/format_to_a.c +8 -8
- data/ext/cumo/narray/gen/tmpl/frexp.c +13 -13
- data/ext/cumo/narray/gen/tmpl/gemm.c +252 -108
- data/ext/cumo/narray/gen/tmpl/inspect.c +1 -1
- data/ext/cumo/narray/gen/tmpl/lib.c +2 -2
- data/ext/cumo/narray/gen/tmpl/logseq.c +7 -7
- data/ext/cumo/narray/gen/tmpl/logseq_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/map_with_index.c +17 -17
- data/ext/cumo/narray/gen/tmpl/median.c +10 -10
- data/ext/cumo/narray/gen/tmpl/minmax.c +10 -10
- data/ext/cumo/narray/gen/tmpl/new_dim0.c +3 -3
- data/ext/cumo/narray/gen/tmpl/poly.c +6 -6
- data/ext/cumo/narray/gen/tmpl/pow.c +28 -28
- data/ext/cumo/narray/gen/tmpl/pow_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/rand.c +10 -10
- data/ext/cumo/narray/gen/tmpl/rand_norm.c +7 -7
- data/ext/cumo/narray/gen/tmpl/real_accum_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/seq.c +7 -7
- data/ext/cumo/narray/gen/tmpl/seq_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/set2.c +20 -20
- data/ext/cumo/narray/gen/tmpl/sort.c +11 -11
- data/ext/cumo/narray/gen/tmpl/sort_index.c +18 -18
- data/ext/cumo/narray/gen/tmpl/store.c +6 -6
- data/ext/cumo/narray/gen/tmpl/store_array.c +19 -19
- data/ext/cumo/narray/gen/tmpl/store_array_kernel.cu +12 -12
- data/ext/cumo/narray/gen/tmpl/store_bit.c +23 -23
- data/ext/cumo/narray/gen/tmpl/store_bit_kernel.cu +28 -28
- data/ext/cumo/narray/gen/tmpl/store_from.c +16 -16
- data/ext/cumo/narray/gen/tmpl/store_from_kernel.cu +12 -12
- data/ext/cumo/narray/gen/tmpl/to_a.c +10 -10
- data/ext/cumo/narray/gen/tmpl/unary.c +25 -25
- data/ext/cumo/narray/gen/tmpl/unary2.c +17 -17
- data/ext/cumo/narray/gen/tmpl/unary_kernel.cu +15 -15
- data/ext/cumo/narray/gen/tmpl/unary_ret2.c +13 -13
- data/ext/cumo/narray/gen/tmpl/unary_s.c +17 -17
- data/ext/cumo/narray/gen/tmpl/unary_s_kernel.cu +12 -12
- data/ext/cumo/narray/gen/tmpl_bit/allocate.c +9 -9
- data/ext/cumo/narray/gen/tmpl_bit/aref.c +2 -2
- data/ext/cumo/narray/gen/tmpl_bit/aref_cpu.c +5 -5
- data/ext/cumo/narray/gen/tmpl_bit/aset.c +2 -2
- data/ext/cumo/narray/gen/tmpl_bit/binary.c +29 -29
- data/ext/cumo/narray/gen/tmpl_bit/bit_count.c +14 -14
- data/ext/cumo/narray/gen/tmpl_bit/bit_count_cpu.c +21 -21
- data/ext/cumo/narray/gen/tmpl_bit/bit_count_kernel.cu +28 -28
- data/ext/cumo/narray/gen/tmpl_bit/bit_reduce.c +29 -29
- data/ext/cumo/narray/gen/tmpl_bit/each.c +10 -10
- data/ext/cumo/narray/gen/tmpl_bit/each_with_index.c +10 -10
- data/ext/cumo/narray/gen/tmpl_bit/extract.c +8 -8
- data/ext/cumo/narray/gen/tmpl_bit/extract_cpu.c +8 -8
- data/ext/cumo/narray/gen/tmpl_bit/fill.c +17 -17
- data/ext/cumo/narray/gen/tmpl_bit/format.c +14 -14
- data/ext/cumo/narray/gen/tmpl_bit/format_to_a.c +11 -11
- data/ext/cumo/narray/gen/tmpl_bit/inspect.c +3 -3
- data/ext/cumo/narray/gen/tmpl_bit/mask.c +33 -33
- data/ext/cumo/narray/gen/tmpl_bit/store_array.c +19 -19
- data/ext/cumo/narray/gen/tmpl_bit/store_bit.c +22 -22
- data/ext/cumo/narray/gen/tmpl_bit/store_from.c +18 -18
- data/ext/cumo/narray/gen/tmpl_bit/to_a.c +12 -12
- data/ext/cumo/narray/gen/tmpl_bit/unary.c +24 -24
- data/ext/cumo/narray/gen/tmpl_bit/where.c +16 -16
- data/ext/cumo/narray/gen/tmpl_bit/where2.c +20 -20
- data/ext/cumo/narray/index.c +213 -213
- data/ext/cumo/narray/math.c +27 -27
- data/ext/cumo/narray/narray.c +484 -484
- data/ext/cumo/narray/ndloop.c +259 -258
- data/ext/cumo/narray/rand.c +3 -3
- data/ext/cumo/narray/step.c +70 -70
- data/ext/cumo/narray/struct.c +139 -139
- metadata +6 -7
- data/ext/cumo/include/cumo/intern_fwd.h +0 -38
- data/lib/erbpp.rb +0 -294
- data/lib/erbpp/line_number.rb +0 -137
- data/lib/erbpp/narray_def.rb +0 -381
@@ -4,11 +4,13 @@ thisdir = File.dirname(__FILE__)
|
|
4
4
|
libpath = File.absolute_path(File.dirname(__FILE__))+"/../../../../lib"
|
5
5
|
$LOAD_PATH.unshift libpath
|
6
6
|
|
7
|
-
require_relative "
|
7
|
+
require_relative "narray_def"
|
8
|
+
|
9
|
+
$line_number = false
|
8
10
|
|
9
11
|
while true
|
10
12
|
if ARGV[0] == "-l"
|
11
|
-
|
13
|
+
$line_number = true
|
12
14
|
ARGV.shift
|
13
15
|
elsif ARGV[0] == "-o"
|
14
16
|
ARGV.shift
|
@@ -33,6 +35,7 @@ erb_dir.unshift("tmpl_bit") if (type_name == "bit")
|
|
33
35
|
erb_dir.map!{|d| File.join(thisdir,d)}
|
34
36
|
|
35
37
|
code = DefLib.new do
|
38
|
+
set line_number: $line_number
|
36
39
|
set erb_dir: erb_dir
|
37
40
|
set erb_suffix: ".c"
|
38
41
|
set ns_var: "mCumo"
|
@@ -4,11 +4,13 @@ thisdir = File.dirname(__FILE__)
|
|
4
4
|
libpath = File.absolute_path(File.dirname(__FILE__))+"/../../../../lib"
|
5
5
|
$LOAD_PATH.unshift libpath
|
6
6
|
|
7
|
-
require_relative "
|
7
|
+
require_relative "narray_def"
|
8
|
+
|
9
|
+
$line_number = false
|
8
10
|
|
9
11
|
while true
|
10
12
|
if ARGV[0] == "-l"
|
11
|
-
|
13
|
+
$line_number = true
|
12
14
|
ARGV.shift
|
13
15
|
elsif ARGV[0] == "-o"
|
14
16
|
ARGV.shift
|
@@ -33,6 +35,7 @@ erb_dir.unshift("tmpl_bit") if (type_name == "bit")
|
|
33
35
|
erb_dir.map!{|d| File.join(thisdir,d)}
|
34
36
|
|
35
37
|
code = DefLib.new do
|
38
|
+
set line_number: $line_number
|
36
39
|
set erb_dir: erb_dir
|
37
40
|
set erb_suffix: "_kernel.cu"
|
38
41
|
set ns_var: "mCumo"
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
class ErbPP
|
4
|
+
|
5
|
+
class CountLnString < String
|
6
|
+
|
7
|
+
def initialize(filename)
|
8
|
+
@filename = filename
|
9
|
+
@lnchar = "\n"
|
10
|
+
@buf = ""
|
11
|
+
@str = ""
|
12
|
+
@countln = 1
|
13
|
+
@current = 1
|
14
|
+
super("\n"+report_line)
|
15
|
+
end
|
16
|
+
|
17
|
+
def report_line
|
18
|
+
"#line #{@current} \"#{@filename}\"\n"
|
19
|
+
end
|
20
|
+
|
21
|
+
def concat0(s)
|
22
|
+
ln(caller[0])
|
23
|
+
@buf.concat(s)
|
24
|
+
@str.concat(s)
|
25
|
+
end
|
26
|
+
|
27
|
+
def concat1(s)
|
28
|
+
ln(caller[0])
|
29
|
+
@buf.concat(s)
|
30
|
+
end
|
31
|
+
|
32
|
+
def ln(status=nil)
|
33
|
+
case status
|
34
|
+
when /:(\d+):/
|
35
|
+
n = $1.to_i
|
36
|
+
else
|
37
|
+
n = status.to_i
|
38
|
+
end
|
39
|
+
return if n == @current
|
40
|
+
if @current != @countln || @postpone
|
41
|
+
if /\A\s*\z/ =~ @str || /\A#line / =~ @buf
|
42
|
+
@postpone = true
|
43
|
+
elsif @in_comment
|
44
|
+
@postpone = false
|
45
|
+
else
|
46
|
+
if self[-1] != "\n"
|
47
|
+
concat("\n")
|
48
|
+
end
|
49
|
+
concat(report_line)
|
50
|
+
@postpone = false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
concat(@buf)
|
54
|
+
|
55
|
+
b = @buf.gsub(/".*?(?<!\\)"/,'""')
|
56
|
+
/^.*(\/\*)(.*?)$/ =~ b
|
57
|
+
x = $2
|
58
|
+
/^.*(\*\/)(.*?)$/ =~ b
|
59
|
+
y = $2
|
60
|
+
if x
|
61
|
+
if y
|
62
|
+
if x.size < y.size
|
63
|
+
#:in_comment
|
64
|
+
@in_comment = true
|
65
|
+
else
|
66
|
+
#:out_comment
|
67
|
+
@in_comment = false
|
68
|
+
end
|
69
|
+
else
|
70
|
+
#:in_comment
|
71
|
+
@in_comment = true
|
72
|
+
end
|
73
|
+
else
|
74
|
+
if y
|
75
|
+
#:out_comment
|
76
|
+
@in_comment = false
|
77
|
+
else
|
78
|
+
#:keep
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
@countln = @current + @buf.count(@lnchar)
|
83
|
+
@current = n
|
84
|
+
@buf = ""
|
85
|
+
@str = ""
|
86
|
+
end
|
87
|
+
|
88
|
+
def d(s)
|
89
|
+
p [s, [x,y], r]
|
90
|
+
r
|
91
|
+
end
|
92
|
+
|
93
|
+
def final
|
94
|
+
ln(caller[0])
|
95
|
+
concat(@buf)
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
class ERBLN
|
101
|
+
|
102
|
+
def initialize(str, filename, trim_mode=nil, eoutvar='_erbout')
|
103
|
+
@filename = filename
|
104
|
+
compiler = ERB::Compiler.new(trim_mode)
|
105
|
+
set_eoutvar(compiler, eoutvar)
|
106
|
+
@src, @enc = *compiler.compile(str)
|
107
|
+
end
|
108
|
+
|
109
|
+
def set_eoutvar(compiler, eoutvar = '_erbout')
|
110
|
+
compiler.put_cmd = "#{eoutvar}.concat0"
|
111
|
+
compiler.insert_cmd = "#{eoutvar}.concat1"
|
112
|
+
compiler.pre_cmd = ["#{eoutvar} = CountLnString.new(#{@filename.inspect})"]
|
113
|
+
compiler.post_cmd = ["#{eoutvar}.final"]
|
114
|
+
end
|
115
|
+
|
116
|
+
def run(b)
|
117
|
+
print self.result(b)
|
118
|
+
end
|
119
|
+
|
120
|
+
def result(b)
|
121
|
+
#open("tmpout","a") do |f|
|
122
|
+
# f.puts "\n#file:#{@filename}"
|
123
|
+
# f.puts @src
|
124
|
+
#end
|
125
|
+
eval(@src, b, (@filename || '(erb)'), 0)
|
126
|
+
end
|
127
|
+
|
128
|
+
#require "fileutils"
|
129
|
+
#FileUtils.rm_f("tmpout")
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "erb"
|
2
|
+
require_relative "erbln"
|
2
3
|
|
3
4
|
class ErbPP
|
4
5
|
|
@@ -66,8 +67,12 @@ class ErbPP
|
|
66
67
|
Dir.glob(x).each do |dir|
|
67
68
|
path = File.join(dir,file)
|
68
69
|
if File.exist?(path)
|
69
|
-
|
70
|
-
|
70
|
+
if get(:line_number)
|
71
|
+
erb = ERBLN.new(File.read(path), path, trim_mode)
|
72
|
+
else
|
73
|
+
erb = ERB.new(File.read(path), safe_level, trim_mode)
|
74
|
+
erb.filename = path
|
75
|
+
end
|
71
76
|
return erb
|
72
77
|
end
|
73
78
|
end
|
@@ -119,15 +124,15 @@ class DefLib < ErbPP
|
|
119
124
|
opts[:include_files] ||= []
|
120
125
|
super(parent, **opts, &block)
|
121
126
|
end
|
122
|
-
def
|
127
|
+
def cumo_id_assign
|
123
128
|
ids = []
|
124
|
-
@children.each{|c| a=c.get(:
|
125
|
-
ids.sort.uniq.map{|x| "
|
129
|
+
@children.each{|c| a=c.get(:cumo_id_list); ids.concat(a) if a}
|
130
|
+
ids.sort.uniq.map{|x| "cumo_id_#{x[1]} = rb_intern(\"#{x[0]}\");"}
|
126
131
|
end
|
127
|
-
def
|
132
|
+
def cumo_id_decl
|
128
133
|
ids = []
|
129
|
-
@children.each{|c| a=c.get(:
|
130
|
-
ids.sort.uniq.map{|x| "static ID
|
134
|
+
@children.each{|c| a=c.get(:cumo_id_list); ids.concat(a) if a}
|
135
|
+
ids.sort.uniq.map{|x| "static ID cumo_id_#{x[1]};\n"}
|
131
136
|
end
|
132
137
|
def def_class(**opts, &block)
|
133
138
|
DefClass.new(self, **opts, &block)
|
@@ -173,12 +178,12 @@ class DefModule < ErbPP
|
|
173
178
|
eb = opts[:erb_base] || 'module'
|
174
179
|
super(parent, erb_base:eb, **opts, &block)
|
175
180
|
end
|
176
|
-
def
|
177
|
-
@
|
181
|
+
def cumo_id_list
|
182
|
+
@cumo_id_list ||= []
|
178
183
|
end
|
179
184
|
def def_id(name,var=nil)
|
180
185
|
var = name.gsub(/\?/,"_p").gsub(/\!/,"_bang") if var.nil?
|
181
|
-
|
186
|
+
cumo_id_list << [name,var]
|
182
187
|
end
|
183
188
|
def init_def
|
184
189
|
load_erb(init_erb).result(binding)
|
@@ -221,11 +226,11 @@ class DefMethod < ErbPP
|
|
221
226
|
set erb_base: erb_base
|
222
227
|
end
|
223
228
|
|
224
|
-
def
|
229
|
+
def cumo_id_op
|
225
230
|
if op.size == 1
|
226
231
|
"'#{op}'"
|
227
232
|
else
|
228
|
-
"
|
233
|
+
"cumo_id_#{c_name}"
|
229
234
|
end
|
230
235
|
end
|
231
236
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative 'erbpp2'
|
2
2
|
|
3
3
|
module NArrayMethod
|
4
4
|
|
@@ -232,11 +232,11 @@ class Store < DefMethod
|
|
232
232
|
def extract_data(ptr,pos,x)
|
233
233
|
case type_name
|
234
234
|
when "Bit"
|
235
|
-
"{BIT_DIGIT b;
|
235
|
+
"{BIT_DIGIT b; CUMO_LOAD_BIT(#{ptr},#{pos},b); x = m_from_sint(b);}"
|
236
236
|
when "RObject"
|
237
237
|
"#{x} = m_num_to_data(*(#{dtype}*)(#{ptr}+#{pos}))"
|
238
238
|
when /Complex/
|
239
|
-
"{#{dtype} *p = (#{dtype}*)(#{ptr}+#{pos}); #{x} = c_new(
|
239
|
+
"{#{dtype} *p = (#{dtype}*)(#{ptr}+#{pos}); #{x} = c_new(CUMO_REAL(*p),CUMO_IMAG(*p));}"
|
240
240
|
when /Float/
|
241
241
|
"#{x} = m_from_real(*(#{dtype}*)(#{ptr}+#{pos}))"
|
242
242
|
when /UInt64/
|
data/ext/cumo/narray/gen/spec.rb
CHANGED
@@ -108,8 +108,8 @@ def_method "store" do
|
|
108
108
|
store_numeric
|
109
109
|
store_from "Bit"
|
110
110
|
if is_complex
|
111
|
-
store_from "DComplex","
|
112
|
-
store_from "SComplex","
|
111
|
+
store_from "DComplex","cumo_dcomplex","m_from_dcomplex"
|
112
|
+
store_from "SComplex","cumo_scomplex","m_from_scomplex"
|
113
113
|
end
|
114
114
|
store_from "DFloat","double", "m_from_real"
|
115
115
|
store_from "SFloat","float", "m_from_real"
|
@@ -5,12 +5,12 @@
|
|
5
5
|
//<% unless indexer_ops.include?(name) %>
|
6
6
|
void cumo_<%=type_name%>_<%=name%><%=nan%>_kernel_launch(size_t n, char *p1, ssize_t s1, char *p2);
|
7
7
|
<% else %>
|
8
|
-
void cumo_<%=type_name%>_<%=name%><%=nan%>_kernel_launch(
|
8
|
+
void cumo_<%=type_name%>_<%=name%><%=nan%>_kernel_launch(cumo_na_reduction_arg_t* arg);
|
9
9
|
<% end %>
|
10
10
|
<% end %>
|
11
11
|
|
12
12
|
static void
|
13
|
-
<%=c_iter%><%=nan%>(
|
13
|
+
<%=c_iter%><%=nan%>(cumo_na_loop_t *const lp)
|
14
14
|
{
|
15
15
|
<% if type_name == 'robject' || name == 'kahan_sum' || nan == '_nan' %>
|
16
16
|
{
|
@@ -18,11 +18,11 @@ static void
|
|
18
18
|
char *p1, *p2;
|
19
19
|
ssize_t s1;
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
CUMO_INIT_COUNTER(lp, n);
|
22
|
+
CUMO_INIT_PTR(lp, 0, p1, s1);
|
23
23
|
p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
|
24
24
|
|
25
|
-
|
25
|
+
CUMO_SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%><%=nan%>", "<%=type_name%>");
|
26
26
|
*(<%=dtype%>*)p2 = f_<%=name%><%=nan%>(n,p1,s1);
|
27
27
|
}
|
28
28
|
//<% elsif !indexer_ops.include?(name) %>
|
@@ -31,8 +31,8 @@ static void
|
|
31
31
|
char *p1, *p2;
|
32
32
|
ssize_t s1;
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
CUMO_INIT_COUNTER(lp, n);
|
35
|
+
CUMO_INIT_PTR(lp, 0, p1, s1);
|
36
36
|
p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
|
37
37
|
|
38
38
|
cumo_<%=type_name%>_<%=name%><%=nan%>_kernel_launch(n,p1,s1,p2);
|
@@ -41,7 +41,7 @@ static void
|
|
41
41
|
{
|
42
42
|
// TODO(sonots): How to compute Kahan summation algorithm in parallel?
|
43
43
|
// TODO(sonots): Implement nan CUDA version
|
44
|
-
|
44
|
+
cumo_na_reduction_arg_t arg = cumo_na_make_reduction_arg(lp);
|
45
45
|
cumo_<%=type_name%>_<%=name%><%=nan%>_kernel_launch(&arg);
|
46
46
|
}
|
47
47
|
<% end %>
|
@@ -64,20 +64,20 @@ static VALUE
|
|
64
64
|
<%=c_func(-1)%>(int argc, VALUE *argv, VALUE self)
|
65
65
|
{
|
66
66
|
VALUE v, reduce;
|
67
|
-
|
68
|
-
|
67
|
+
cumo_ndfunc_arg_in_t ain[2] = {{cT,0},{cumo_sym_reduce,0}};
|
68
|
+
cumo_ndfunc_arg_out_t aout[1] = {{<%=result_class%>,0}};
|
69
69
|
//<% if type_name == 'robject' || !indexer_ops.include?(name) %>
|
70
|
-
|
70
|
+
cumo_ndfunc_t ndf = { <%=c_iter%>, CUMO_STRIDE_LOOP_NIP|CUMO_NDF_FLAT_REDUCE, 2, 1, ain, aout };
|
71
71
|
<% else %>
|
72
|
-
|
72
|
+
cumo_ndfunc_t ndf = { <%=c_iter%>, CUMO_STRIDE_LOOP_NIP|CUMO_NDF_FLAT_REDUCE|CUMO_NDF_INDEXER_LOOP, 2, 1, ain, aout };
|
73
73
|
<% end %>
|
74
74
|
|
75
75
|
<% if is_float %>
|
76
|
-
reduce =
|
76
|
+
reduce = cumo_na_reduce_dimension(argc, argv, 1, &self, &ndf, <%=c_iter%>_nan);
|
77
77
|
<% else %>
|
78
|
-
reduce =
|
78
|
+
reduce = cumo_na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
|
79
79
|
<% end %>
|
80
|
-
v =
|
80
|
+
v = cumo_na_ndloop(&ndf, 2, self, reduce);
|
81
81
|
<% if result_class == "cT" %>
|
82
82
|
return <%=type_name%>_extract(v);
|
83
83
|
<% else %>
|
@@ -6,41 +6,41 @@ void <%="cumo_#{type_name}_#{name}#{nan}_kernel_launch"%>(char *p1, char *p2, ch
|
|
6
6
|
<% end %>
|
7
7
|
|
8
8
|
static void
|
9
|
-
<%=c_iter%><%=nan%>(
|
9
|
+
<%=c_iter%><%=nan%>(cumo_na_loop_t *const lp)
|
10
10
|
{
|
11
11
|
size_t n;
|
12
12
|
char *p1, *p2, *p3;
|
13
13
|
ssize_t s1, s2, s3;
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
CUMO_INIT_COUNTER(lp, n);
|
16
|
+
CUMO_INIT_PTR(lp, 0, p1, s1);
|
17
|
+
CUMO_INIT_PTR(lp, 1, p2, s2);
|
18
|
+
CUMO_INIT_PTR(lp, 2, p3, s3);
|
19
19
|
|
20
20
|
<% if type_name == 'robject' %>
|
21
21
|
{
|
22
22
|
size_t i;
|
23
|
-
|
23
|
+
CUMO_SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%><%=nan%>", "<%=type_name%>");
|
24
24
|
if (s3==0) {
|
25
25
|
dtype z;
|
26
26
|
// Reduce loop
|
27
|
-
|
27
|
+
CUMO_GET_DATA(p3,dtype,z);
|
28
28
|
for (i=0; i<n; i++) {
|
29
29
|
dtype x, y;
|
30
|
-
|
31
|
-
|
30
|
+
CUMO_GET_DATA_STRIDE(p1,s1,dtype,x);
|
31
|
+
CUMO_GET_DATA_STRIDE(p2,s2,dtype,y);
|
32
32
|
m_<%=name%><%=nan%>(x,y,z);
|
33
33
|
}
|
34
|
-
|
34
|
+
CUMO_SET_DATA(p3,dtype,z);
|
35
35
|
return;
|
36
36
|
} else {
|
37
37
|
for (i=0; i<n; i++) {
|
38
38
|
dtype x, y, z;
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
CUMO_GET_DATA_STRIDE(p1,s1,dtype,x);
|
40
|
+
CUMO_GET_DATA_STRIDE(p2,s2,dtype,y);
|
41
|
+
CUMO_GET_DATA(p3,dtype,z);
|
42
42
|
m_<%=name%><%=nan%>(x,y,z);
|
43
|
-
|
43
|
+
CUMO_SET_DATA_STRIDE(p3,s3,dtype,z);
|
44
44
|
}
|
45
45
|
}
|
46
46
|
}
|
@@ -62,9 +62,9 @@ static VALUE
|
|
62
62
|
{
|
63
63
|
VALUE v, reduce;
|
64
64
|
VALUE naryv[2];
|
65
|
-
|
66
|
-
|
67
|
-
|
65
|
+
cumo_ndfunc_arg_in_t ain[4] = {{cT,0},{cT,0},{cumo_sym_reduce,0},{cumo_sym_init,0}};
|
66
|
+
cumo_ndfunc_arg_out_t aout[1] = {{cT,0}};
|
67
|
+
cumo_ndfunc_t ndf = { <%=c_iter%>, CUMO_STRIDE_LOOP_NIP, 4, 1, ain, aout };
|
68
68
|
|
69
69
|
if (argc < 1) {
|
70
70
|
rb_raise(rb_eArgError,"wrong number of arguments (%d for >=1)",argc);
|
@@ -73,12 +73,12 @@ static VALUE
|
|
73
73
|
naryv[0] = self;
|
74
74
|
naryv[1] = argv[0];
|
75
75
|
//<% if is_float %>
|
76
|
-
reduce =
|
76
|
+
reduce = cumo_na_reduce_dimension(argc-1, argv+1, 2, naryv, &ndf, <%=c_iter%>_nan);
|
77
77
|
//<% else %>
|
78
|
-
reduce =
|
78
|
+
reduce = cumo_na_reduce_dimension(argc-1, argv+1, 2, naryv, &ndf, 0);
|
79
79
|
//<% end %>
|
80
80
|
|
81
|
-
v =
|
81
|
+
v = cumo_na_ndloop(&ndf, 4, self, argv[0], reduce, m_<%=name%>_init);
|
82
82
|
return <%=type_name%>_extract(v);
|
83
83
|
}
|
84
84
|
|
@@ -110,11 +110,11 @@ static VALUE
|
|
110
110
|
//<% if is_object %>
|
111
111
|
return <%=c_func%>_self(argc, argv, self);
|
112
112
|
//<% else %>
|
113
|
-
klass =
|
113
|
+
klass = cumo_na_upcast(rb_obj_class(self),rb_obj_class(argv[0]));
|
114
114
|
if (klass==cT) {
|
115
115
|
return <%=c_func%>_self(argc, argv, self);
|
116
116
|
} else {
|
117
|
-
v = rb_funcall(klass,
|
117
|
+
v = rb_funcall(klass, cumo_id_cast, 1, self);
|
118
118
|
return rb_funcall2(v, rb_intern("<%=name%>"), argc, argv);
|
119
119
|
}
|
120
120
|
//<% end %>
|