cumo 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/3rd_party/LICENSE.txt +60 -0
  4. data/3rd_party/mkmf-cu/lib/mkmf-cu/cli.rb +13 -1
  5. data/LICENSE.txt +1 -62
  6. data/README.md +33 -29
  7. data/bench/cumo_bench.rb +47 -25
  8. data/bench/numo_bench.rb +27 -25
  9. data/docs/src-tree.md +16 -0
  10. data/ext/cumo/cuda/cublas.c +69 -219
  11. data/ext/cumo/cuda/memory_pool_impl.hpp +1 -0
  12. data/ext/cumo/cuda/runtime.c +2 -14
  13. data/ext/cumo/cumo.c +16 -16
  14. data/ext/cumo/include/cumo.h +2 -2
  15. data/ext/cumo/include/cumo/cuda/cublas.h +6 -129
  16. data/ext/cumo/include/cumo/cuda/runtime.h +16 -0
  17. data/ext/cumo/include/cumo/indexer.h +46 -63
  18. data/ext/cumo/include/cumo/intern.h +58 -112
  19. data/ext/cumo/include/cumo/narray.h +214 -185
  20. data/ext/cumo/include/cumo/narray_kernel.h +66 -37
  21. data/ext/cumo/include/cumo/ndloop.h +42 -42
  22. data/ext/cumo/include/cumo/reduce_kernel.h +55 -71
  23. data/ext/cumo/include/cumo/template.h +56 -51
  24. data/ext/cumo/include/cumo/template_kernel.h +31 -31
  25. data/ext/cumo/include/cumo/types/bit.h +3 -3
  26. data/ext/cumo/include/cumo/types/bit_kernel.h +2 -2
  27. data/ext/cumo/include/cumo/types/complex.h +126 -126
  28. data/ext/cumo/include/cumo/types/complex_kernel.h +126 -126
  29. data/ext/cumo/include/cumo/types/complex_macro.h +28 -28
  30. data/ext/cumo/include/cumo/types/complex_macro_kernel.h +20 -20
  31. data/ext/cumo/include/cumo/types/dcomplex.h +5 -5
  32. data/ext/cumo/include/cumo/types/dcomplex_kernel.h +1 -1
  33. data/ext/cumo/include/cumo/types/int_macro.h +1 -1
  34. data/ext/cumo/include/cumo/types/int_macro_kernel.h +1 -1
  35. data/ext/cumo/include/cumo/types/robj_macro.h +30 -30
  36. data/ext/cumo/include/cumo/types/scomplex.h +5 -5
  37. data/ext/cumo/include/cumo/types/scomplex_kernel.h +1 -1
  38. data/ext/cumo/narray/array.c +143 -143
  39. data/ext/cumo/narray/data.c +184 -184
  40. data/ext/cumo/narray/gen/cogen.rb +5 -2
  41. data/ext/cumo/narray/gen/cogen_kernel.rb +5 -2
  42. data/ext/cumo/narray/gen/def/dcomplex.rb +1 -1
  43. data/ext/cumo/narray/gen/def/scomplex.rb +1 -1
  44. data/ext/cumo/narray/gen/erbln.rb +132 -0
  45. data/ext/cumo/narray/gen/erbpp2.rb +18 -13
  46. data/ext/cumo/narray/gen/narray_def.rb +3 -3
  47. data/ext/cumo/narray/gen/spec.rb +2 -2
  48. data/ext/cumo/narray/gen/tmpl/accum.c +15 -15
  49. data/ext/cumo/narray/gen/tmpl/accum_binary.c +22 -22
  50. data/ext/cumo/narray/gen/tmpl/accum_binary_kernel.cu +3 -3
  51. data/ext/cumo/narray/gen/tmpl/accum_index.c +30 -30
  52. data/ext/cumo/narray/gen/tmpl/accum_index_kernel.cu +2 -2
  53. data/ext/cumo/narray/gen/tmpl/accum_kernel.cu +3 -3
  54. data/ext/cumo/narray/gen/tmpl/alloc_func.c +14 -14
  55. data/ext/cumo/narray/gen/tmpl/allocate.c +11 -11
  56. data/ext/cumo/narray/gen/tmpl/aref.c +2 -2
  57. data/ext/cumo/narray/gen/tmpl/aref_cpu.c +4 -4
  58. data/ext/cumo/narray/gen/tmpl/aset.c +2 -2
  59. data/ext/cumo/narray/gen/tmpl/binary.c +28 -28
  60. data/ext/cumo/narray/gen/tmpl/binary2.c +18 -18
  61. data/ext/cumo/narray/gen/tmpl/binary2_kernel.cu +3 -3
  62. data/ext/cumo/narray/gen/tmpl/binary_kernel.cu +6 -6
  63. data/ext/cumo/narray/gen/tmpl/binary_s.c +13 -13
  64. data/ext/cumo/narray/gen/tmpl/binary_s_kernel.cu +3 -3
  65. data/ext/cumo/narray/gen/tmpl/bincount.c +23 -23
  66. data/ext/cumo/narray/gen/tmpl/cast.c +7 -7
  67. data/ext/cumo/narray/gen/tmpl/cast_array.c +3 -3
  68. data/ext/cumo/narray/gen/tmpl/clip.c +38 -38
  69. data/ext/cumo/narray/gen/tmpl/complex_accum_kernel.cu +2 -2
  70. data/ext/cumo/narray/gen/tmpl/cond_binary.c +19 -19
  71. data/ext/cumo/narray/gen/tmpl/cond_binary_kernel.cu +7 -7
  72. data/ext/cumo/narray/gen/tmpl/cond_unary.c +15 -15
  73. data/ext/cumo/narray/gen/tmpl/cum.c +15 -15
  74. data/ext/cumo/narray/gen/tmpl/each.c +9 -9
  75. data/ext/cumo/narray/gen/tmpl/each_with_index.c +9 -9
  76. data/ext/cumo/narray/gen/tmpl/ewcomp.c +15 -15
  77. data/ext/cumo/narray/gen/tmpl/ewcomp_kernel.cu +3 -3
  78. data/ext/cumo/narray/gen/tmpl/extract_cpu.c +5 -5
  79. data/ext/cumo/narray/gen/tmpl/extract_data.c +12 -12
  80. data/ext/cumo/narray/gen/tmpl/eye.c +9 -9
  81. data/ext/cumo/narray/gen/tmpl/eye_kernel.cu +3 -3
  82. data/ext/cumo/narray/gen/tmpl/fill.c +9 -9
  83. data/ext/cumo/narray/gen/tmpl/fill_kernel.cu +6 -6
  84. data/ext/cumo/narray/gen/tmpl/float_accum_kernel.cu +1 -1
  85. data/ext/cumo/narray/gen/tmpl/format.c +11 -11
  86. data/ext/cumo/narray/gen/tmpl/format_to_a.c +8 -8
  87. data/ext/cumo/narray/gen/tmpl/frexp.c +13 -13
  88. data/ext/cumo/narray/gen/tmpl/gemm.c +252 -108
  89. data/ext/cumo/narray/gen/tmpl/inspect.c +1 -1
  90. data/ext/cumo/narray/gen/tmpl/lib.c +2 -2
  91. data/ext/cumo/narray/gen/tmpl/logseq.c +7 -7
  92. data/ext/cumo/narray/gen/tmpl/logseq_kernel.cu +6 -6
  93. data/ext/cumo/narray/gen/tmpl/map_with_index.c +17 -17
  94. data/ext/cumo/narray/gen/tmpl/median.c +10 -10
  95. data/ext/cumo/narray/gen/tmpl/minmax.c +10 -10
  96. data/ext/cumo/narray/gen/tmpl/new_dim0.c +3 -3
  97. data/ext/cumo/narray/gen/tmpl/poly.c +6 -6
  98. data/ext/cumo/narray/gen/tmpl/pow.c +28 -28
  99. data/ext/cumo/narray/gen/tmpl/pow_kernel.cu +6 -6
  100. data/ext/cumo/narray/gen/tmpl/rand.c +10 -10
  101. data/ext/cumo/narray/gen/tmpl/rand_norm.c +7 -7
  102. data/ext/cumo/narray/gen/tmpl/real_accum_kernel.cu +6 -6
  103. data/ext/cumo/narray/gen/tmpl/seq.c +7 -7
  104. data/ext/cumo/narray/gen/tmpl/seq_kernel.cu +6 -6
  105. data/ext/cumo/narray/gen/tmpl/set2.c +20 -20
  106. data/ext/cumo/narray/gen/tmpl/sort.c +11 -11
  107. data/ext/cumo/narray/gen/tmpl/sort_index.c +18 -18
  108. data/ext/cumo/narray/gen/tmpl/store.c +6 -6
  109. data/ext/cumo/narray/gen/tmpl/store_array.c +19 -19
  110. data/ext/cumo/narray/gen/tmpl/store_array_kernel.cu +12 -12
  111. data/ext/cumo/narray/gen/tmpl/store_bit.c +23 -23
  112. data/ext/cumo/narray/gen/tmpl/store_bit_kernel.cu +28 -28
  113. data/ext/cumo/narray/gen/tmpl/store_from.c +16 -16
  114. data/ext/cumo/narray/gen/tmpl/store_from_kernel.cu +12 -12
  115. data/ext/cumo/narray/gen/tmpl/to_a.c +10 -10
  116. data/ext/cumo/narray/gen/tmpl/unary.c +25 -25
  117. data/ext/cumo/narray/gen/tmpl/unary2.c +17 -17
  118. data/ext/cumo/narray/gen/tmpl/unary_kernel.cu +15 -15
  119. data/ext/cumo/narray/gen/tmpl/unary_ret2.c +13 -13
  120. data/ext/cumo/narray/gen/tmpl/unary_s.c +17 -17
  121. data/ext/cumo/narray/gen/tmpl/unary_s_kernel.cu +12 -12
  122. data/ext/cumo/narray/gen/tmpl_bit/allocate.c +9 -9
  123. data/ext/cumo/narray/gen/tmpl_bit/aref.c +2 -2
  124. data/ext/cumo/narray/gen/tmpl_bit/aref_cpu.c +5 -5
  125. data/ext/cumo/narray/gen/tmpl_bit/aset.c +2 -2
  126. data/ext/cumo/narray/gen/tmpl_bit/binary.c +29 -29
  127. data/ext/cumo/narray/gen/tmpl_bit/bit_count.c +14 -14
  128. data/ext/cumo/narray/gen/tmpl_bit/bit_count_cpu.c +21 -21
  129. data/ext/cumo/narray/gen/tmpl_bit/bit_count_kernel.cu +28 -28
  130. data/ext/cumo/narray/gen/tmpl_bit/bit_reduce.c +29 -29
  131. data/ext/cumo/narray/gen/tmpl_bit/each.c +10 -10
  132. data/ext/cumo/narray/gen/tmpl_bit/each_with_index.c +10 -10
  133. data/ext/cumo/narray/gen/tmpl_bit/extract.c +8 -8
  134. data/ext/cumo/narray/gen/tmpl_bit/extract_cpu.c +8 -8
  135. data/ext/cumo/narray/gen/tmpl_bit/fill.c +17 -17
  136. data/ext/cumo/narray/gen/tmpl_bit/format.c +14 -14
  137. data/ext/cumo/narray/gen/tmpl_bit/format_to_a.c +11 -11
  138. data/ext/cumo/narray/gen/tmpl_bit/inspect.c +3 -3
  139. data/ext/cumo/narray/gen/tmpl_bit/mask.c +33 -33
  140. data/ext/cumo/narray/gen/tmpl_bit/store_array.c +19 -19
  141. data/ext/cumo/narray/gen/tmpl_bit/store_bit.c +22 -22
  142. data/ext/cumo/narray/gen/tmpl_bit/store_from.c +18 -18
  143. data/ext/cumo/narray/gen/tmpl_bit/to_a.c +12 -12
  144. data/ext/cumo/narray/gen/tmpl_bit/unary.c +24 -24
  145. data/ext/cumo/narray/gen/tmpl_bit/where.c +16 -16
  146. data/ext/cumo/narray/gen/tmpl_bit/where2.c +20 -20
  147. data/ext/cumo/narray/index.c +213 -213
  148. data/ext/cumo/narray/math.c +27 -27
  149. data/ext/cumo/narray/narray.c +484 -484
  150. data/ext/cumo/narray/ndloop.c +259 -258
  151. data/ext/cumo/narray/rand.c +3 -3
  152. data/ext/cumo/narray/step.c +70 -70
  153. data/ext/cumo/narray/struct.c +139 -139
  154. metadata +6 -7
  155. data/ext/cumo/include/cumo/intern_fwd.h +0 -38
  156. data/lib/erbpp.rb +0 -294
  157. data/lib/erbpp/line_number.rb +0 -137
  158. 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 "./narray_def"
7
+ require_relative "narray_def"
8
+
9
+ $line_number = false
8
10
 
9
11
  while true
10
12
  if ARGV[0] == "-l"
11
- require "erbpp/line_number"
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 "./narray_def"
7
+ require_relative "narray_def"
8
+
9
+ $line_number = false
8
10
 
9
11
  while true
10
12
  if ARGV[0] == "-l"
11
- require "erbpp/line_number"
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"
@@ -4,7 +4,7 @@ set full_class_name: "Cumo::DComplex"
4
4
  set class_name: "DComplex"
5
5
  set class_alias: "Complex64"
6
6
  set class_var: "cT"
7
- set ctype: "dcomplex"
7
+ set ctype: "cumo_dcomplex"
8
8
  set real_class_name: "DFloat"
9
9
  set real_ctype: "double"
10
10
 
@@ -4,7 +4,7 @@ set full_class_name: "Cumo::SComplex"
4
4
  set class_name: "SComplex"
5
5
  set class_alias: "Complex32"
6
6
  set class_var: "cT"
7
- set ctype: "Scomplex"
7
+ set ctype: "cumo_scomplex"
8
8
  set real_class_name: "SFloat"
9
9
  set real_ctype: "float"
10
10
 
@@ -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
- erb = ERB.new(File.read(path), safe_level, trim_mode)
70
- erb.filename = path
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 id_assign
127
+ def cumo_id_assign
123
128
  ids = []
124
- @children.each{|c| a=c.get(:id_list); ids.concat(a) if a}
125
- ids.sort.uniq.map{|x| "id_#{x[1]} = rb_intern(\"#{x[0]}\");"}
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 id_decl
132
+ def cumo_id_decl
128
133
  ids = []
129
- @children.each{|c| a=c.get(:id_list); ids.concat(a) if a}
130
- ids.sort.uniq.map{|x| "static ID id_#{x[1]};\n"}
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 id_list
177
- @id_list ||= []
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
- id_list << [name,var]
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 id_op
229
+ def cumo_id_op
225
230
  if op.size == 1
226
231
  "'#{op}'"
227
232
  else
228
- "id_#{c_name}"
233
+ "cumo_id_#{c_name}"
229
234
  end
230
235
  end
231
236
 
@@ -1,4 +1,4 @@
1
- require_relative './erbpp2'
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; LOAD_BIT(#{ptr},#{pos},b); x = m_from_sint(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(REAL(*p),IMAG(*p));}"
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/
@@ -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","dcomplex","m_from_dcomplex"
112
- store_from "SComplex","scomplex","m_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(na_reduction_arg_t* arg);
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%>(na_loop_t *const lp)
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
- INIT_COUNTER(lp, n);
22
- INIT_PTR(lp, 0, p1, s1);
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
- SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%><%=nan%>", "<%=type_name%>");
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
- INIT_COUNTER(lp, n);
35
- INIT_PTR(lp, 0, p1, s1);
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
- na_reduction_arg_t arg = na_make_reduction_arg(lp);
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
- ndfunc_arg_in_t ain[2] = {{cT,0},{sym_reduce,0}};
68
- ndfunc_arg_out_t aout[1] = {{<%=result_class%>,0}};
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
- ndfunc_t ndf = { <%=c_iter%>, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE, 2, 1, ain, aout };
70
+ cumo_ndfunc_t ndf = { <%=c_iter%>, CUMO_STRIDE_LOOP_NIP|CUMO_NDF_FLAT_REDUCE, 2, 1, ain, aout };
71
71
  <% else %>
72
- ndfunc_t ndf = { <%=c_iter%>, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE|NDF_INDEXER_LOOP, 2, 1, ain, aout };
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 = na_reduce_dimension(argc, argv, 1, &self, &ndf, <%=c_iter%>_nan);
76
+ reduce = cumo_na_reduce_dimension(argc, argv, 1, &self, &ndf, <%=c_iter%>_nan);
77
77
  <% else %>
78
- reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
78
+ reduce = cumo_na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
79
79
  <% end %>
80
- v = na_ndloop(&ndf, 2, self, reduce);
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%>(na_loop_t *const lp)
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
- INIT_COUNTER(lp, n);
16
- INIT_PTR(lp, 0, p1, s1);
17
- INIT_PTR(lp, 1, p2, s2);
18
- INIT_PTR(lp, 2, p3, s3);
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
- SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%><%=nan%>", "<%=type_name%>");
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
- GET_DATA(p3,dtype,z);
27
+ CUMO_GET_DATA(p3,dtype,z);
28
28
  for (i=0; i<n; i++) {
29
29
  dtype x, y;
30
- GET_DATA_STRIDE(p1,s1,dtype,x);
31
- GET_DATA_STRIDE(p2,s2,dtype,y);
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
- SET_DATA(p3,dtype,z);
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
- GET_DATA_STRIDE(p1,s1,dtype,x);
40
- GET_DATA_STRIDE(p2,s2,dtype,y);
41
- GET_DATA(p3,dtype,z);
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
- SET_DATA_STRIDE(p3,s3,dtype,z);
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
- ndfunc_arg_in_t ain[4] = {{cT,0},{cT,0},{sym_reduce,0},{sym_init,0}};
66
- ndfunc_arg_out_t aout[1] = {{cT,0}};
67
- ndfunc_t ndf = { <%=c_iter%>, STRIDE_LOOP_NIP, 4, 1, ain, aout };
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 = na_reduce_dimension(argc-1, argv+1, 2, naryv, &ndf, <%=c_iter%>_nan);
76
+ reduce = cumo_na_reduce_dimension(argc-1, argv+1, 2, naryv, &ndf, <%=c_iter%>_nan);
77
77
  //<% else %>
78
- reduce = na_reduce_dimension(argc-1, argv+1, 2, naryv, &ndf, 0);
78
+ reduce = cumo_na_reduce_dimension(argc-1, argv+1, 2, naryv, &ndf, 0);
79
79
  //<% end %>
80
80
 
81
- v = na_ndloop(&ndf, 4, self, argv[0], reduce, m_<%=name%>_init);
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 = na_upcast(CLASS_OF(self),CLASS_OF(argv[0]));
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, id_cast, 1, self);
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 %>