cumo 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (266) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +27 -0
  3. data/.travis.yml +5 -0
  4. data/3rd_party/mkmf-cu/.gitignore +36 -0
  5. data/3rd_party/mkmf-cu/Gemfile +3 -0
  6. data/3rd_party/mkmf-cu/LICENSE +21 -0
  7. data/3rd_party/mkmf-cu/README.md +36 -0
  8. data/3rd_party/mkmf-cu/Rakefile +11 -0
  9. data/3rd_party/mkmf-cu/bin/mkmf-cu-nvcc +4 -0
  10. data/3rd_party/mkmf-cu/lib/mkmf-cu.rb +32 -0
  11. data/3rd_party/mkmf-cu/lib/mkmf-cu/cli.rb +80 -0
  12. data/3rd_party/mkmf-cu/lib/mkmf-cu/nvcc.rb +157 -0
  13. data/3rd_party/mkmf-cu/mkmf-cu.gemspec +16 -0
  14. data/3rd_party/mkmf-cu/test/test_mkmf-cu.rb +67 -0
  15. data/CODE_OF_CONDUCT.md +46 -0
  16. data/Gemfile +8 -0
  17. data/LICENSE.txt +82 -0
  18. data/README.md +252 -0
  19. data/Rakefile +43 -0
  20. data/bench/broadcast_fp32.rb +138 -0
  21. data/bench/cumo_bench.rb +193 -0
  22. data/bench/numo_bench.rb +138 -0
  23. data/bench/reduction_fp32.rb +117 -0
  24. data/bin/console +14 -0
  25. data/bin/setup +8 -0
  26. data/cumo.gemspec +32 -0
  27. data/ext/cumo/cuda/cublas.c +278 -0
  28. data/ext/cumo/cuda/driver.c +421 -0
  29. data/ext/cumo/cuda/memory_pool.cpp +185 -0
  30. data/ext/cumo/cuda/memory_pool_impl.cpp +308 -0
  31. data/ext/cumo/cuda/memory_pool_impl.hpp +370 -0
  32. data/ext/cumo/cuda/memory_pool_impl_test.cpp +554 -0
  33. data/ext/cumo/cuda/nvrtc.c +207 -0
  34. data/ext/cumo/cuda/runtime.c +167 -0
  35. data/ext/cumo/cumo.c +148 -0
  36. data/ext/cumo/depend.erb +58 -0
  37. data/ext/cumo/extconf.rb +179 -0
  38. data/ext/cumo/include/cumo.h +25 -0
  39. data/ext/cumo/include/cumo/compat.h +23 -0
  40. data/ext/cumo/include/cumo/cuda/cublas.h +153 -0
  41. data/ext/cumo/include/cumo/cuda/cumo_thrust.hpp +187 -0
  42. data/ext/cumo/include/cumo/cuda/cumo_thrust_complex.hpp +79 -0
  43. data/ext/cumo/include/cumo/cuda/driver.h +22 -0
  44. data/ext/cumo/include/cumo/cuda/memory_pool.h +28 -0
  45. data/ext/cumo/include/cumo/cuda/nvrtc.h +22 -0
  46. data/ext/cumo/include/cumo/cuda/runtime.h +40 -0
  47. data/ext/cumo/include/cumo/indexer.h +238 -0
  48. data/ext/cumo/include/cumo/intern.h +142 -0
  49. data/ext/cumo/include/cumo/intern_fwd.h +38 -0
  50. data/ext/cumo/include/cumo/intern_kernel.h +6 -0
  51. data/ext/cumo/include/cumo/narray.h +429 -0
  52. data/ext/cumo/include/cumo/narray_kernel.h +149 -0
  53. data/ext/cumo/include/cumo/ndloop.h +95 -0
  54. data/ext/cumo/include/cumo/reduce_kernel.h +126 -0
  55. data/ext/cumo/include/cumo/template.h +158 -0
  56. data/ext/cumo/include/cumo/template_kernel.h +77 -0
  57. data/ext/cumo/include/cumo/types/bit.h +40 -0
  58. data/ext/cumo/include/cumo/types/bit_kernel.h +34 -0
  59. data/ext/cumo/include/cumo/types/complex.h +402 -0
  60. data/ext/cumo/include/cumo/types/complex_kernel.h +414 -0
  61. data/ext/cumo/include/cumo/types/complex_macro.h +382 -0
  62. data/ext/cumo/include/cumo/types/complex_macro_kernel.h +186 -0
  63. data/ext/cumo/include/cumo/types/dcomplex.h +46 -0
  64. data/ext/cumo/include/cumo/types/dcomplex_kernel.h +13 -0
  65. data/ext/cumo/include/cumo/types/dfloat.h +47 -0
  66. data/ext/cumo/include/cumo/types/dfloat_kernel.h +14 -0
  67. data/ext/cumo/include/cumo/types/float_def.h +34 -0
  68. data/ext/cumo/include/cumo/types/float_def_kernel.h +39 -0
  69. data/ext/cumo/include/cumo/types/float_macro.h +191 -0
  70. data/ext/cumo/include/cumo/types/float_macro_kernel.h +158 -0
  71. data/ext/cumo/include/cumo/types/int16.h +24 -0
  72. data/ext/cumo/include/cumo/types/int16_kernel.h +23 -0
  73. data/ext/cumo/include/cumo/types/int32.h +24 -0
  74. data/ext/cumo/include/cumo/types/int32_kernel.h +19 -0
  75. data/ext/cumo/include/cumo/types/int64.h +24 -0
  76. data/ext/cumo/include/cumo/types/int64_kernel.h +19 -0
  77. data/ext/cumo/include/cumo/types/int8.h +24 -0
  78. data/ext/cumo/include/cumo/types/int8_kernel.h +19 -0
  79. data/ext/cumo/include/cumo/types/int_macro.h +67 -0
  80. data/ext/cumo/include/cumo/types/int_macro_kernel.h +48 -0
  81. data/ext/cumo/include/cumo/types/real_accum.h +486 -0
  82. data/ext/cumo/include/cumo/types/real_accum_kernel.h +101 -0
  83. data/ext/cumo/include/cumo/types/robj_macro.h +80 -0
  84. data/ext/cumo/include/cumo/types/robj_macro_kernel.h +0 -0
  85. data/ext/cumo/include/cumo/types/robject.h +27 -0
  86. data/ext/cumo/include/cumo/types/robject_kernel.h +7 -0
  87. data/ext/cumo/include/cumo/types/scomplex.h +46 -0
  88. data/ext/cumo/include/cumo/types/scomplex_kernel.h +13 -0
  89. data/ext/cumo/include/cumo/types/sfloat.h +48 -0
  90. data/ext/cumo/include/cumo/types/sfloat_kernel.h +14 -0
  91. data/ext/cumo/include/cumo/types/uint16.h +25 -0
  92. data/ext/cumo/include/cumo/types/uint16_kernel.h +20 -0
  93. data/ext/cumo/include/cumo/types/uint32.h +25 -0
  94. data/ext/cumo/include/cumo/types/uint32_kernel.h +20 -0
  95. data/ext/cumo/include/cumo/types/uint64.h +25 -0
  96. data/ext/cumo/include/cumo/types/uint64_kernel.h +20 -0
  97. data/ext/cumo/include/cumo/types/uint8.h +25 -0
  98. data/ext/cumo/include/cumo/types/uint8_kernel.h +20 -0
  99. data/ext/cumo/include/cumo/types/uint_macro.h +58 -0
  100. data/ext/cumo/include/cumo/types/uint_macro_kernel.h +38 -0
  101. data/ext/cumo/include/cumo/types/xint_macro.h +169 -0
  102. data/ext/cumo/include/cumo/types/xint_macro_kernel.h +88 -0
  103. data/ext/cumo/narray/SFMT-params.h +97 -0
  104. data/ext/cumo/narray/SFMT-params19937.h +46 -0
  105. data/ext/cumo/narray/SFMT.c +620 -0
  106. data/ext/cumo/narray/SFMT.h +167 -0
  107. data/ext/cumo/narray/array.c +638 -0
  108. data/ext/cumo/narray/data.c +961 -0
  109. data/ext/cumo/narray/gen/cogen.rb +56 -0
  110. data/ext/cumo/narray/gen/cogen_kernel.rb +58 -0
  111. data/ext/cumo/narray/gen/def/bit.rb +37 -0
  112. data/ext/cumo/narray/gen/def/dcomplex.rb +39 -0
  113. data/ext/cumo/narray/gen/def/dfloat.rb +37 -0
  114. data/ext/cumo/narray/gen/def/int16.rb +36 -0
  115. data/ext/cumo/narray/gen/def/int32.rb +36 -0
  116. data/ext/cumo/narray/gen/def/int64.rb +36 -0
  117. data/ext/cumo/narray/gen/def/int8.rb +36 -0
  118. data/ext/cumo/narray/gen/def/robject.rb +37 -0
  119. data/ext/cumo/narray/gen/def/scomplex.rb +39 -0
  120. data/ext/cumo/narray/gen/def/sfloat.rb +37 -0
  121. data/ext/cumo/narray/gen/def/uint16.rb +36 -0
  122. data/ext/cumo/narray/gen/def/uint32.rb +36 -0
  123. data/ext/cumo/narray/gen/def/uint64.rb +36 -0
  124. data/ext/cumo/narray/gen/def/uint8.rb +36 -0
  125. data/ext/cumo/narray/gen/erbpp2.rb +346 -0
  126. data/ext/cumo/narray/gen/narray_def.rb +268 -0
  127. data/ext/cumo/narray/gen/spec.rb +425 -0
  128. data/ext/cumo/narray/gen/tmpl/accum.c +86 -0
  129. data/ext/cumo/narray/gen/tmpl/accum_binary.c +121 -0
  130. data/ext/cumo/narray/gen/tmpl/accum_binary_kernel.cu +61 -0
  131. data/ext/cumo/narray/gen/tmpl/accum_index.c +119 -0
  132. data/ext/cumo/narray/gen/tmpl/accum_index_kernel.cu +66 -0
  133. data/ext/cumo/narray/gen/tmpl/accum_kernel.cu +12 -0
  134. data/ext/cumo/narray/gen/tmpl/alloc_func.c +107 -0
  135. data/ext/cumo/narray/gen/tmpl/allocate.c +37 -0
  136. data/ext/cumo/narray/gen/tmpl/aref.c +66 -0
  137. data/ext/cumo/narray/gen/tmpl/aref_cpu.c +50 -0
  138. data/ext/cumo/narray/gen/tmpl/aset.c +56 -0
  139. data/ext/cumo/narray/gen/tmpl/binary.c +162 -0
  140. data/ext/cumo/narray/gen/tmpl/binary2.c +70 -0
  141. data/ext/cumo/narray/gen/tmpl/binary2_kernel.cu +15 -0
  142. data/ext/cumo/narray/gen/tmpl/binary_kernel.cu +31 -0
  143. data/ext/cumo/narray/gen/tmpl/binary_s.c +45 -0
  144. data/ext/cumo/narray/gen/tmpl/binary_s_kernel.cu +15 -0
  145. data/ext/cumo/narray/gen/tmpl/bincount.c +181 -0
  146. data/ext/cumo/narray/gen/tmpl/cast.c +44 -0
  147. data/ext/cumo/narray/gen/tmpl/cast_array.c +13 -0
  148. data/ext/cumo/narray/gen/tmpl/class.c +9 -0
  149. data/ext/cumo/narray/gen/tmpl/class_kernel.cu +6 -0
  150. data/ext/cumo/narray/gen/tmpl/clip.c +121 -0
  151. data/ext/cumo/narray/gen/tmpl/coerce_cast.c +10 -0
  152. data/ext/cumo/narray/gen/tmpl/complex_accum_kernel.cu +129 -0
  153. data/ext/cumo/narray/gen/tmpl/cond_binary.c +68 -0
  154. data/ext/cumo/narray/gen/tmpl/cond_binary_kernel.cu +18 -0
  155. data/ext/cumo/narray/gen/tmpl/cond_unary.c +46 -0
  156. data/ext/cumo/narray/gen/tmpl/cum.c +50 -0
  157. data/ext/cumo/narray/gen/tmpl/each.c +47 -0
  158. data/ext/cumo/narray/gen/tmpl/each_with_index.c +70 -0
  159. data/ext/cumo/narray/gen/tmpl/ewcomp.c +79 -0
  160. data/ext/cumo/narray/gen/tmpl/ewcomp_kernel.cu +19 -0
  161. data/ext/cumo/narray/gen/tmpl/extract.c +22 -0
  162. data/ext/cumo/narray/gen/tmpl/extract_cpu.c +26 -0
  163. data/ext/cumo/narray/gen/tmpl/extract_data.c +53 -0
  164. data/ext/cumo/narray/gen/tmpl/eye.c +105 -0
  165. data/ext/cumo/narray/gen/tmpl/eye_kernel.cu +19 -0
  166. data/ext/cumo/narray/gen/tmpl/fill.c +52 -0
  167. data/ext/cumo/narray/gen/tmpl/fill_kernel.cu +29 -0
  168. data/ext/cumo/narray/gen/tmpl/float_accum_kernel.cu +106 -0
  169. data/ext/cumo/narray/gen/tmpl/format.c +62 -0
  170. data/ext/cumo/narray/gen/tmpl/format_to_a.c +49 -0
  171. data/ext/cumo/narray/gen/tmpl/frexp.c +38 -0
  172. data/ext/cumo/narray/gen/tmpl/gemm.c +203 -0
  173. data/ext/cumo/narray/gen/tmpl/init_class.c +20 -0
  174. data/ext/cumo/narray/gen/tmpl/init_module.c +12 -0
  175. data/ext/cumo/narray/gen/tmpl/inspect.c +21 -0
  176. data/ext/cumo/narray/gen/tmpl/lib.c +50 -0
  177. data/ext/cumo/narray/gen/tmpl/lib_kernel.cu +24 -0
  178. data/ext/cumo/narray/gen/tmpl/logseq.c +102 -0
  179. data/ext/cumo/narray/gen/tmpl/logseq_kernel.cu +31 -0
  180. data/ext/cumo/narray/gen/tmpl/map_with_index.c +98 -0
  181. data/ext/cumo/narray/gen/tmpl/median.c +66 -0
  182. data/ext/cumo/narray/gen/tmpl/minmax.c +47 -0
  183. data/ext/cumo/narray/gen/tmpl/module.c +9 -0
  184. data/ext/cumo/narray/gen/tmpl/module_kernel.cu +1 -0
  185. data/ext/cumo/narray/gen/tmpl/new_dim0.c +15 -0
  186. data/ext/cumo/narray/gen/tmpl/new_dim0_kernel.cu +8 -0
  187. data/ext/cumo/narray/gen/tmpl/poly.c +50 -0
  188. data/ext/cumo/narray/gen/tmpl/pow.c +97 -0
  189. data/ext/cumo/narray/gen/tmpl/pow_kernel.cu +29 -0
  190. data/ext/cumo/narray/gen/tmpl/powint.c +17 -0
  191. data/ext/cumo/narray/gen/tmpl/qsort.c +212 -0
  192. data/ext/cumo/narray/gen/tmpl/rand.c +168 -0
  193. data/ext/cumo/narray/gen/tmpl/rand_norm.c +121 -0
  194. data/ext/cumo/narray/gen/tmpl/real_accum_kernel.cu +75 -0
  195. data/ext/cumo/narray/gen/tmpl/seq.c +112 -0
  196. data/ext/cumo/narray/gen/tmpl/seq_kernel.cu +43 -0
  197. data/ext/cumo/narray/gen/tmpl/set2.c +57 -0
  198. data/ext/cumo/narray/gen/tmpl/sort.c +48 -0
  199. data/ext/cumo/narray/gen/tmpl/sort_index.c +111 -0
  200. data/ext/cumo/narray/gen/tmpl/store.c +41 -0
  201. data/ext/cumo/narray/gen/tmpl/store_array.c +187 -0
  202. data/ext/cumo/narray/gen/tmpl/store_array_kernel.cu +58 -0
  203. data/ext/cumo/narray/gen/tmpl/store_bit.c +86 -0
  204. data/ext/cumo/narray/gen/tmpl/store_bit_kernel.cu +66 -0
  205. data/ext/cumo/narray/gen/tmpl/store_from.c +81 -0
  206. data/ext/cumo/narray/gen/tmpl/store_from_kernel.cu +58 -0
  207. data/ext/cumo/narray/gen/tmpl/store_kernel.cu +3 -0
  208. data/ext/cumo/narray/gen/tmpl/store_numeric.c +9 -0
  209. data/ext/cumo/narray/gen/tmpl/to_a.c +43 -0
  210. data/ext/cumo/narray/gen/tmpl/unary.c +132 -0
  211. data/ext/cumo/narray/gen/tmpl/unary2.c +60 -0
  212. data/ext/cumo/narray/gen/tmpl/unary_kernel.cu +72 -0
  213. data/ext/cumo/narray/gen/tmpl/unary_ret2.c +34 -0
  214. data/ext/cumo/narray/gen/tmpl/unary_s.c +86 -0
  215. data/ext/cumo/narray/gen/tmpl/unary_s_kernel.cu +58 -0
  216. data/ext/cumo/narray/gen/tmpl_bit/allocate.c +24 -0
  217. data/ext/cumo/narray/gen/tmpl_bit/aref.c +54 -0
  218. data/ext/cumo/narray/gen/tmpl_bit/aref_cpu.c +57 -0
  219. data/ext/cumo/narray/gen/tmpl_bit/aset.c +56 -0
  220. data/ext/cumo/narray/gen/tmpl_bit/binary.c +98 -0
  221. data/ext/cumo/narray/gen/tmpl_bit/bit_count.c +64 -0
  222. data/ext/cumo/narray/gen/tmpl_bit/bit_count_cpu.c +88 -0
  223. data/ext/cumo/narray/gen/tmpl_bit/bit_count_kernel.cu +76 -0
  224. data/ext/cumo/narray/gen/tmpl_bit/bit_reduce.c +133 -0
  225. data/ext/cumo/narray/gen/tmpl_bit/each.c +48 -0
  226. data/ext/cumo/narray/gen/tmpl_bit/each_with_index.c +70 -0
  227. data/ext/cumo/narray/gen/tmpl_bit/extract.c +30 -0
  228. data/ext/cumo/narray/gen/tmpl_bit/extract_cpu.c +29 -0
  229. data/ext/cumo/narray/gen/tmpl_bit/fill.c +69 -0
  230. data/ext/cumo/narray/gen/tmpl_bit/format.c +64 -0
  231. data/ext/cumo/narray/gen/tmpl_bit/format_to_a.c +51 -0
  232. data/ext/cumo/narray/gen/tmpl_bit/inspect.c +21 -0
  233. data/ext/cumo/narray/gen/tmpl_bit/mask.c +136 -0
  234. data/ext/cumo/narray/gen/tmpl_bit/none_p.c +14 -0
  235. data/ext/cumo/narray/gen/tmpl_bit/store_array.c +108 -0
  236. data/ext/cumo/narray/gen/tmpl_bit/store_bit.c +70 -0
  237. data/ext/cumo/narray/gen/tmpl_bit/store_from.c +60 -0
  238. data/ext/cumo/narray/gen/tmpl_bit/to_a.c +47 -0
  239. data/ext/cumo/narray/gen/tmpl_bit/unary.c +81 -0
  240. data/ext/cumo/narray/gen/tmpl_bit/where.c +90 -0
  241. data/ext/cumo/narray/gen/tmpl_bit/where2.c +95 -0
  242. data/ext/cumo/narray/index.c +880 -0
  243. data/ext/cumo/narray/kwargs.c +153 -0
  244. data/ext/cumo/narray/math.c +142 -0
  245. data/ext/cumo/narray/narray.c +1948 -0
  246. data/ext/cumo/narray/ndloop.c +2105 -0
  247. data/ext/cumo/narray/rand.c +45 -0
  248. data/ext/cumo/narray/step.c +474 -0
  249. data/ext/cumo/narray/struct.c +886 -0
  250. data/lib/cumo.rb +3 -0
  251. data/lib/cumo/cuda.rb +11 -0
  252. data/lib/cumo/cuda/compile_error.rb +36 -0
  253. data/lib/cumo/cuda/compiler.rb +161 -0
  254. data/lib/cumo/cuda/device.rb +47 -0
  255. data/lib/cumo/cuda/link_state.rb +31 -0
  256. data/lib/cumo/cuda/module.rb +40 -0
  257. data/lib/cumo/cuda/nvrtc_program.rb +27 -0
  258. data/lib/cumo/linalg.rb +12 -0
  259. data/lib/cumo/narray.rb +2 -0
  260. data/lib/cumo/narray/extra.rb +1278 -0
  261. data/lib/erbpp.rb +294 -0
  262. data/lib/erbpp/line_number.rb +137 -0
  263. data/lib/erbpp/narray_def.rb +381 -0
  264. data/numo-narray-version +1 -0
  265. data/run.gdb +7 -0
  266. metadata +353 -0
@@ -0,0 +1,121 @@
1
+ typedef struct {
2
+ dtype mu;
3
+ rtype sigma;
4
+ } randn_opt_t;
5
+
6
+ static void
7
+ <%=c_iter%>(na_loop_t *const lp)
8
+ {
9
+ size_t i;
10
+ char *p1;
11
+ ssize_t s1;
12
+ size_t *idx1;
13
+ <% if is_complex %>
14
+ dtype *a0;
15
+ <% else %>
16
+ dtype *a0, *a1;
17
+ <% end %>
18
+ dtype mu;
19
+ rtype sigma;
20
+ randn_opt_t *g;
21
+
22
+ INIT_COUNTER(lp, i);
23
+ INIT_PTR_IDX(lp, 0, p1, s1, idx1);
24
+ g = (randn_opt_t*)(lp->opt_ptr);
25
+ mu = g->mu;
26
+ sigma = g->sigma;
27
+
28
+ SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%>", "<%=type_name%>");
29
+ cumo_cuda_runtime_check_status(cudaDeviceSynchronize());
30
+ if (idx1) {
31
+ <% if is_complex %>
32
+ for (; i--;) {
33
+ a0 = (dtype*)(p1+*idx1);
34
+ m_rand_norm(mu,sigma,a0);
35
+ idx1 += 1;
36
+ }
37
+ <% else %>
38
+ for (; i>1; i-=2) {
39
+ a0 = (dtype*)(p1+*idx1);
40
+ a1 = (dtype*)(p1+*(idx1+1));
41
+ m_rand_norm(mu,sigma,a0,a1);
42
+ idx1 += 2;
43
+ }
44
+ if (i>0) {
45
+ a0 = (dtype*)(p1+*idx1);
46
+ m_rand_norm(mu,sigma,a0,0);
47
+ }
48
+ <% end %>
49
+ } else {
50
+ <% if is_complex %>
51
+ for (; i--;) {
52
+ a0 = (dtype*)(p1);
53
+ m_rand_norm(mu,sigma,a0);
54
+ p1 += s1;
55
+ }
56
+ <% else %>
57
+ for (; i>1; i-=2) {
58
+ a0 = (dtype*)(p1);
59
+ a1 = (dtype*)(p1+s1);
60
+ m_rand_norm(mu,sigma,a0,a1);
61
+ p1 += s1*2;
62
+ }
63
+ if (i>0) {
64
+ a0 = (dtype*)(p1);
65
+ m_rand_norm(mu,sigma,a0,0);
66
+ }
67
+ <% end %>
68
+ }
69
+ }
70
+
71
+ /*
72
+ Generates random numbers from the normal distribution on self narray
73
+ using Box-Muller Transformation.
74
+ @overload rand_norm([mu,[sigma]])
75
+ @param [Numeric] mu mean of normal distribution. (default=0)
76
+ @param [Numeric] sigma standard deviation of normal distribution. (default=1)
77
+ @return [Cumo::<%=class_name%>] self.
78
+ @example
79
+ Cumo::DFloat.new(5,5).rand_norm
80
+ => Cumo::DFloat#shape=[5,5]
81
+ [[-0.581255, -0.168354, 0.586895, -0.595142, -0.802802],
82
+ [-0.326106, 0.282922, 1.68427, 0.918499, -0.0485384],
83
+ [-0.464453, -0.992194, 0.413794, -0.60717, -0.699695],
84
+ [-1.64168, 0.48676, -0.875871, -1.43275, 0.812172],
85
+ [-0.209975, -0.103612, -0.878617, -1.42495, 1.0968]]
86
+ Cumo::DFloat.new(5,5).rand_norm(10,0.1)
87
+ => Cumo::DFloat#shape=[5,5]
88
+ [[9.9019, 9.90339, 10.0826, 9.98384, 9.72861],
89
+ [9.81507, 10.0272, 9.91445, 10.0568, 9.88923],
90
+ [10.0234, 9.97874, 9.96011, 9.9006, 9.99964],
91
+ [10.0186, 9.94598, 9.92236, 9.99811, 9.97003],
92
+ [9.79266, 9.95044, 9.95212, 9.93692, 10.2027]]
93
+ Cumo::DComplex.new(3,3).rand_norm(5+5i)
94
+ => Cumo::DComplex#shape=[3,3]
95
+ [[5.84303+4.40052i, 4.00984+6.08982i, 5.10979+5.13215i],
96
+ [4.26477+3.99655i, 4.90052+5.00763i, 4.46607+2.3444i],
97
+ [4.5528+7.11003i, 5.62117+6.69094i, 5.05443+5.35133i]]
98
+ */
99
+ static VALUE
100
+ <%=c_func(-1)%>(int argc, VALUE *args, VALUE self)
101
+ {
102
+ int n;
103
+ randn_opt_t g;
104
+ VALUE v1=Qnil, v2=Qnil;
105
+ ndfunc_arg_in_t ain[1] = {{OVERWRITE,0}};
106
+ ndfunc_t ndf = {<%=c_iter%>, FULL_LOOP, 1,0, ain,0};
107
+
108
+ n = rb_scan_args(argc, args, "02", &v1, &v2);
109
+ if (n == 0) {
110
+ g.mu = m_zero;
111
+ } else {
112
+ g.mu = m_num_to_data(v1);
113
+ }
114
+ if (n == 2) {
115
+ g.sigma = NUM2DBL(v2);
116
+ } else {
117
+ g.sigma = 1;
118
+ }
119
+ na_ndloop3(&ndf, &g, 1, self);
120
+ return self;
121
+ }
@@ -0,0 +1,75 @@
1
+ #if defined(__cplusplus)
2
+ #if 0
3
+ { /* satisfy cc-mode */
4
+ #endif
5
+ } /* extern "C" { */
6
+ #endif
7
+
8
+ struct cumo_<%=type_name%>_sum_impl {
9
+ __device__ <%=dtype%> Identity() { return m_zero; }
10
+ __device__ dtype MapIn(dtype in, int64_t /*index*/) { return in; }
11
+ __device__ void Reduce(dtype next, <%=dtype%>& accum) { accum += next; }
12
+ __device__ <%=dtype%> MapOut(<%=dtype%> accum) { return accum; }
13
+ };
14
+
15
+ struct cumo_<%=type_name%>_prod_impl {
16
+ __device__ <%=dtype%> Identity() { return m_one; }
17
+ __device__ dtype MapIn(dtype in, int64_t /*index*/) { return in; }
18
+ __device__ void Reduce(dtype next, <%=dtype%>& accum) { accum *= next; }
19
+ __device__ <%=dtype%> MapOut(<%=dtype%> accum) { return accum; }
20
+ };
21
+
22
+ struct cumo_<%=type_name%>_min_impl {
23
+ __device__ dtype Identity() { return DATA_MAX; }
24
+ __device__ dtype MapIn(dtype in, int64_t /*index*/) { return in; }
25
+ __device__ void Reduce(dtype next, dtype& accum) { accum = next < accum ? next : accum; }
26
+ __device__ dtype MapOut(dtype accum) { return accum; }
27
+ };
28
+
29
+ struct cumo_<%=type_name%>_max_impl {
30
+ __device__ dtype Identity() { return DATA_MIN; }
31
+ __device__ dtype MapIn(dtype in, int64_t /*index*/) { return in; }
32
+ __device__ void Reduce(dtype next, dtype& accum) { accum = next < accum ? accum : next; }
33
+ __device__ dtype MapOut(dtype accum) { return accum; }
34
+ };
35
+
36
+ // TODO(sonots): Implement minmax
37
+ __global__ void cumo_<%=type_name%>_ptp_kernel(na_reduction_arg_t arg)
38
+ {
39
+ dtype min=0,max=1;
40
+ //<%=type_name%>_minmax_kernel<<<1,1>>>(n,p1,s1,&min,&max);
41
+ char* p2 = arg.out.ptr;
42
+ *(dtype*)p2 = m_sub(max,min);
43
+ }
44
+
45
+ #if defined(__cplusplus)
46
+ extern "C" {
47
+ #if 0
48
+ } /* satisfy cc-mode */
49
+ #endif
50
+ #endif
51
+
52
+ void cumo_<%=type_name%>_sum_kernel_launch(na_reduction_arg_t* arg)
53
+ {
54
+ cumo_reduce<dtype, <%=dtype%>, cumo_<%=type_name%>_sum_impl>(*arg, cumo_<%=type_name%>_sum_impl{});
55
+ }
56
+
57
+ void cumo_<%=type_name%>_prod_kernel_launch(na_reduction_arg_t* arg)
58
+ {
59
+ cumo_reduce<dtype, <%=dtype%>, cumo_<%=type_name%>_prod_impl>(*arg, cumo_<%=type_name%>_prod_impl{});
60
+ }
61
+
62
+ void cumo_<%=type_name%>_min_kernel_launch(na_reduction_arg_t* arg)
63
+ {
64
+ cumo_reduce<dtype, dtype, cumo_<%=type_name%>_min_impl>(*arg, cumo_<%=type_name%>_min_impl{});
65
+ }
66
+
67
+ void cumo_<%=type_name%>_max_kernel_launch(na_reduction_arg_t* arg)
68
+ {
69
+ cumo_reduce<dtype, dtype, cumo_<%=type_name%>_max_impl>(*arg, cumo_<%=type_name%>_max_impl{});
70
+ }
71
+
72
+ void cumo_<%=type_name%>_ptp_kernel_launch(na_reduction_arg_t* arg)
73
+ {
74
+ cumo_<%=type_name%>_ptp_kernel<<<1,1>>>(*arg);
75
+ }
@@ -0,0 +1,112 @@
1
+ <% if is_int && !is_object %>
2
+ typedef double seq_data_t;
3
+ <% else %>
4
+ typedef dtype seq_data_t;
5
+ <% end %>
6
+
7
+ <% if is_object %>
8
+ typedef size_t seq_count_t;
9
+ <% else %>
10
+ typedef double seq_count_t;
11
+ <% end %>
12
+
13
+ typedef struct {
14
+ seq_data_t beg;
15
+ seq_data_t step;
16
+ seq_count_t count;
17
+ } seq_opt_t;
18
+
19
+ <% unless is_object %>
20
+ void <%="cumo_#{c_iter}_index_kernel_launch"%>(char *p1, size_t* idx1, seq_data_t beg, seq_data_t step, seq_count_t c, uint64_t n);
21
+ void <%="cumo_#{c_iter}_stride_kernel_launch"%>(char *p1, ssize_t s1, seq_data_t beg, seq_data_t step, seq_count_t c, uint64_t n);
22
+ <% end %>
23
+
24
+ static void
25
+ <%=c_iter%>(na_loop_t *const lp)
26
+ {
27
+ size_t i;
28
+ char *p1;
29
+ ssize_t s1;
30
+ size_t *idx1;
31
+ seq_data_t beg, step;
32
+ seq_count_t c;
33
+ seq_opt_t *g;
34
+
35
+ INIT_COUNTER(lp, i);
36
+ INIT_PTR_IDX(lp, 0, p1, s1, idx1);
37
+ g = (seq_opt_t*)(lp->opt_ptr);
38
+ beg = g->beg;
39
+ step = g->step;
40
+ c = g->count;
41
+ <% if is_object %>
42
+ {
43
+ dtype x;
44
+ SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%>", "<%=type_name%>");
45
+ if (idx1) {
46
+ for (; i--;) {
47
+ x = f_seq(beg,step,c++);
48
+ *(dtype*)(p1+*idx1) = x;
49
+ idx1++;
50
+ }
51
+ } else {
52
+ for (; i--;) {
53
+ x = f_seq(beg,step,c++);
54
+ *(dtype*)(p1) = x;
55
+ p1 += s1;
56
+ }
57
+ }
58
+ g->count = c;
59
+ }
60
+ <% else %>
61
+ {
62
+ size_t n = i;
63
+ if (idx1) {
64
+ <%="cumo_#{c_iter}_index_kernel_launch"%>(p1,idx1,beg,step,c,n);
65
+ } else {
66
+ <%="cumo_#{c_iter}_stride_kernel_launch"%>(p1,s1,beg,step,c,n);
67
+ }
68
+ g->count += n;
69
+ }
70
+ <% end %>
71
+ }
72
+
73
+ /*
74
+ Set linear sequence of numbers to self. The sequence is obtained from
75
+ beg+i*step
76
+ where i is 1-dimensional index.
77
+ @overload seq([beg,[step]])
78
+ @param [Numeric] beg begining of sequence. (default=0)
79
+ @param [Numeric] step step of sequence. (default=1)
80
+ @return [Cumo::<%=class_name%>] self.
81
+ @example
82
+ Cumo::DFloat.new(6).seq(1,-0.2)
83
+ => Cumo::DFloat#shape=[6]
84
+ [1, 0.8, 0.6, 0.4, 0.2, 0]
85
+ Cumo::DComplex.new(6).seq(1,-0.2+0.2i)
86
+ => Cumo::DComplex#shape=[6]
87
+ [1+0i, 0.8+0.2i, 0.6+0.4i, 0.4+0.6i, 0.2+0.8i, 0+1i]
88
+ */
89
+ static VALUE
90
+ <%=c_func(-1)%>(int argc, VALUE *args, VALUE self)
91
+ {
92
+ seq_opt_t *g;
93
+ VALUE vbeg=Qnil, vstep=Qnil;
94
+ ndfunc_arg_in_t ain[1] = {{OVERWRITE,0}};
95
+ ndfunc_t ndf = {<%=c_iter%>, FULL_LOOP, 1,0, ain,0};
96
+
97
+ g = ALLOCA_N(seq_opt_t,1);
98
+ g->beg = m_zero;
99
+ g->step = m_one;
100
+ g->count = 0;
101
+ rb_scan_args(argc, args, "02", &vbeg, &vstep);
102
+ <% if is_int && !is_object %>
103
+ if (vbeg!=Qnil) {g->beg = NUM2DBL(vbeg);}
104
+ if (vstep!=Qnil) {g->step = NUM2DBL(vstep);}
105
+ <% else %>
106
+ if (vbeg!=Qnil) {g->beg = m_num_to_data(vbeg);}
107
+ if (vstep!=Qnil) {g->step = m_num_to_data(vstep);}
108
+ <% end %>
109
+
110
+ na_ndloop3(&ndf, g, 1, self);
111
+ return self;
112
+ }
@@ -0,0 +1,43 @@
1
+ <% if is_int && !is_object %>
2
+ typedef double seq_data_t;
3
+ <% else %>
4
+ typedef dtype seq_data_t;
5
+ <% end %>
6
+
7
+ <% if is_object %>
8
+ typedef size_t seq_count_t;
9
+ <% else %>
10
+ typedef double seq_count_t;
11
+ <% end %>
12
+
13
+ <% unless is_object %>
14
+ __global__ void <%="cumo_#{c_iter}_index_kernel"%>(char *p1, size_t* idx1, seq_data_t beg, seq_data_t step, seq_count_t c, uint64_t n)
15
+ {
16
+ for (uint64_t i = blockIdx.x * blockDim.x + threadIdx.x; i < n; i += blockDim.x * gridDim.x) {
17
+ dtype x = f_seq(beg,step,c+i);
18
+ *(dtype*)(p1+idx1[i]) = x;
19
+ }
20
+ }
21
+
22
+ __global__ void <%="cumo_#{c_iter}_stride_kernel"%>(char *p1, size_t s1, seq_data_t beg, seq_data_t step, seq_count_t c, uint64_t n)
23
+ {
24
+ for (uint64_t i = blockIdx.x * blockDim.x + threadIdx.x; i < n; i += blockDim.x * gridDim.x) {
25
+ dtype x = f_seq(beg,step,c+i);
26
+ *(dtype*)(p1+(i*s1)) = x;
27
+ }
28
+ }
29
+
30
+ void <%="cumo_#{c_iter}_index_kernel_launch"%>(char *p1, size_t* idx1, seq_data_t beg, seq_data_t step, seq_count_t c, uint64_t n)
31
+ {
32
+ size_t gridDim = get_gridDim(n);
33
+ size_t blockDim = get_blockDim(n);
34
+ <%="cumo_#{c_iter}_index_kernel"%><<<gridDim, blockDim>>>(p1,idx1,beg,step,c,n);
35
+ }
36
+
37
+ void <%="cumo_#{c_iter}_stride_kernel_launch"%>(char *p1, ssize_t s1, seq_data_t beg, seq_data_t step, seq_count_t c, uint64_t n)
38
+ {
39
+ size_t gridDim = get_gridDim(n);
40
+ size_t blockDim = get_blockDim(n);
41
+ <%="cumo_#{c_iter}_stride_kernel"%><<<gridDim, blockDim>>>(p1,s1,beg,step,c,n);
42
+ }
43
+ <% end %>
@@ -0,0 +1,57 @@
1
+ static void
2
+ <%=c_iter%>(na_loop_t *const lp)
3
+ {
4
+ size_t i;
5
+ char *p1, *p2;
6
+ ssize_t s1, s2;
7
+ size_t *idx1, *idx2;
8
+ dtype x;
9
+ <%=dtype%> y;
10
+ INIT_COUNTER(lp, i);
11
+ INIT_PTR_IDX(lp, 0, p1, s1, idx1);
12
+ INIT_PTR_IDX(lp, 1, p2, s2, idx2);
13
+ SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%>", "<%=type_name%>");
14
+ if (idx1) {
15
+ if (idx2) {
16
+ for (; i--;) {
17
+ GET_DATA(p1+*idx1,dtype,x);
18
+ GET_DATA_INDEX(p2,idx2,<%=dtype%>,y);
19
+ x = m_<%=name%>(x,y);
20
+ SET_DATA_INDEX(p1,idx1,dtype,x);
21
+ }
22
+ } else {
23
+ for (; i--;) {
24
+ GET_DATA(p1+*idx1,dtype,x);
25
+ GET_DATA_STRIDE(p2,s2,<%=dtype%>,y);
26
+ x = m_<%=name%>(x,y);
27
+ SET_DATA_INDEX(p1,idx1,dtype,x);
28
+ }
29
+ }
30
+ } else {
31
+ if (idx2) {
32
+ for (; i--;) {
33
+ GET_DATA(p1,dtype,x);
34
+ GET_DATA_INDEX(p2,idx2,<%=dtype%>,y);
35
+ x = m_<%=name%>(x,y);
36
+ SET_DATA_STRIDE(p1,s1,dtype,x);
37
+ }
38
+ } else {
39
+ for (; i--;) {
40
+ GET_DATA(p1,dtype,x);
41
+ GET_DATA_STRIDE(p2,s2,<%=dtype%>,y);
42
+ x = m_<%=name%>(x,y);
43
+ SET_DATA_STRIDE(p1,s1,dtype,x);
44
+ }
45
+ }
46
+ }
47
+ }
48
+
49
+ static VALUE
50
+ <%=c_func(1)%>(VALUE self, VALUE a1)
51
+ {
52
+ ndfunc_arg_in_t ain[2] = {{OVERWRITE,0},{<%=result_class%>,0}};
53
+ ndfunc_t ndf = { <%=c_iter%>, FULL_LOOP, 2, 0, ain, 0 };
54
+
55
+ na_ndloop(&ndf, 2, self, a1);
56
+ return a1;
57
+ }
@@ -0,0 +1,48 @@
1
+ <% (is_float ? ["_ignan","_prnan"] : [""]).each do |j| %>
2
+ static void
3
+ <%=c_iter%><%=j%>(na_loop_t *const lp)
4
+ {
5
+ size_t n;
6
+ char *ptr;
7
+ ssize_t step;
8
+
9
+ INIT_COUNTER(lp, n);
10
+ INIT_PTR(lp, 0, ptr, step);
11
+ SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%>", "<%=type_name%>");
12
+ <%=type_name%>_qsort<%=j%>(ptr, n, step);
13
+ }
14
+ <% end %>
15
+
16
+ /*
17
+ <%=name%> of self.
18
+ <% if is_float %>
19
+ @overload <%=name%>(axis:nil, nan:false)
20
+ @param [TrueClass] nan If true, propagete NaN. If false, ignore NaN.
21
+ <% else %>
22
+ @overload <%=name%>(axis:nil)
23
+ <% end %>
24
+ @param [Numeric,Array,Range] axis Affected dimensions.
25
+ @return [Cumo::<%=class_name%>] returns result of <%=name%>.
26
+ @example
27
+ Cumo::DFloat[3,4,1,2].sort => Cumo::DFloat[1,2,3,4]
28
+ */
29
+ static VALUE
30
+ <%=c_func(-1)%>(int argc, VALUE *argv, VALUE self)
31
+ {
32
+ VALUE reduce;
33
+ ndfunc_arg_in_t ain[2] = {{OVERWRITE,0},{sym_reduce,0}};
34
+ ndfunc_t ndf = {0, STRIDE_LOOP|NDF_FLAT_REDUCE, 2,0, ain,0};
35
+
36
+ if (!TEST_INPLACE(self)) {
37
+ self = na_copy(self);
38
+ }
39
+ <% if is_float %>
40
+ ndf.func = <%=c_iter%>_ignan;
41
+ reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, <%=c_iter%>_prnan);
42
+ <% else %>
43
+ ndf.func = <%=c_iter%>;
44
+ reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
45
+ <% end %>
46
+ na_ndloop(&ndf, 2, self, reduce);
47
+ return self;
48
+ }