cumo 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6898598e4614bd912dfa4e83e31695d7fc5eb256
4
+ data.tar.gz: 752d37294a51016c0256bcdab6d324ebc975bdac
5
+ SHA512:
6
+ metadata.gz: 81279774f60ac5f38a23751f52a42ae01022d9a5c33cf24d905302def0bc75e20237ad76bb986f4bdd43a184eca14ff3d27da46095189c29217d8fd894dad9fc
7
+ data.tar.gz: 609ff0cbf6c3a28fc4fafde14f90adfc82ff7efcf268071a73605d61615feb21770e5bddfc8252a042657cbb2bc179f839030e4b85b1f4c11475ed9b27e92ef5
@@ -0,0 +1,27 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ test.rb
16
+ ext/cumo/narray/types/*.c
17
+ ext/cumo/narray/types/*.cu
18
+ ext/cumo/include/cumo/extconf.h
19
+ ext/cumo/Makefile
20
+ ext/cumo/depend
21
+ TAGS
22
+ t.rb
23
+ .ruby-version
24
+ .yardoc/
25
+ *.exe
26
+ .DS_Store
27
+ /vendor/
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.4
@@ -0,0 +1,36 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalization:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ Gemfile.lock
32
+ .ruby-version
33
+ .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 ruby-accel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,36 @@
1
+ # About mkmf-cu
2
+
3
+ mkmf-cu is a gem to build Ruby extensions written in C/C++ with NVIDIA CUDA.
4
+ It consists of a simple wrapper command for nvcc and a monkey patch for mkmf.
5
+
6
+ ## How to use it.
7
+
8
+ Instead of require "mkmf", just
9
+ ```ruby
10
+ require "mkmf-cu"
11
+ ```
12
+
13
+ ## How does it work?
14
+
15
+ By requiring "mkmf-cu", compiler commands defined in mkmf
16
+ will be replaced with mkmf-cu-nvcc, a command included in this gem.
17
+
18
+ When mkmf-cu-nvcc is called with arguments for gcc or clang,
19
+ it convert them to ones suitable for nvcc and execute nvcc with them.
20
+
21
+ For example,
22
+
23
+ mkmf-cu-nvcc -I. -fno-common -pipe -Os -O2 -Wall -o culib.o -c culib.cu
24
+
25
+ will execute
26
+
27
+ nvcc -I. -O2 -o culib.o -c culib.cu --compiler-options -fno-common --compiler-options -Wall
28
+
29
+ ## Example
30
+
31
+ * https://github.com/ruby-accel/ruby-cuda-example
32
+
33
+ ## Notice
34
+
35
+ When the suffix of the name of a file containing CUDA code is not .cu,
36
+ you must add the option "-x cu" to $CFLAGS or $CXXFLAGS in extconf.rb.
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ require 'rake/clean'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'test'
7
+ end
8
+ desc "Run tests"
9
+
10
+ task :default => [:test]
11
+
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative "../lib/mkmf-cu/cli"
3
+
4
+ MakeMakefileCuda::CLI.new(ARGV).run
@@ -0,0 +1,32 @@
1
+ require "mkmf"
2
+
3
+ module MakeMakefileCuda
4
+ BIN_PATH = File.join(File.dirname(__dir__), 'bin', 'mkmf-cu-nvcc')
5
+
6
+ class << self
7
+ # @params [cxx] Treat .cu files as C++ files
8
+ def install!(cxx: false)
9
+ MakeMakefile::CONFIG["CC"] = "#{BIN_PATH} --mkmf-cu-ext=c"
10
+ MakeMakefile::CONFIG["CXX"] = "#{BIN_PATH} --mkmf-cu-ext=cxx"
11
+ if cxx
12
+ MakeMakefile::CXX_EXT << "cu"
13
+ else
14
+ MakeMakefile::C_EXT << "cu"
15
+ end
16
+ MakeMakefile::SRC_EXT << "cu"
17
+ @installed = true
18
+ end
19
+
20
+ def installed?
21
+ !!@installed
22
+ end
23
+
24
+ def uninstall!
25
+ MakeMakefile::CONFIG["CC"] = RbConfig::CONFIG["CC"]
26
+ MakeMakefile::CONFIG["CXX"] = RbConfig::CONFIG["CXX"]
27
+ MakeMakefile::C_EXT.delete("cu")
28
+ MakeMakefile::CXX_EXT.delete("cu")
29
+ @installed = false
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,80 @@
1
+ require "open3"
2
+ require_relative "nvcc"
3
+
4
+ module MakeMakefileCuda
5
+ class CLI
6
+ attr_reader :argv
7
+
8
+ def initialize(argv)
9
+ @argv = argv.map{|e| e.dup }
10
+ end
11
+
12
+ def run
13
+ if cu_file?
14
+ puts "[given options]: #{argv.join(' ')}"
15
+ run_command!(*nvcc_command)
16
+ elsif c_file?
17
+ run_command!(*c_command)
18
+ elsif cxx_file?
19
+ run_command!(*cxx_command)
20
+ else
21
+ raise 'something wrong'
22
+ end
23
+ end
24
+
25
+ # private
26
+
27
+ def run_command!(*args)
28
+ puts colorize(:green, args.join(' '))
29
+ exit system(*args)
30
+ end
31
+
32
+ # TODO(sonots): Make it possible to configure "nvcc" and additional arguments
33
+ def nvcc_command
34
+ s = MakeMakefileCuda::Nvcc.generate(argv)
35
+ ["nvcc " << s << " -arch=sm_35"]
36
+ end
37
+
38
+ def c_command
39
+ [RbConfig::CONFIG["CC"], *argv[1..-1]]
40
+ end
41
+
42
+ def cxx_command
43
+ [RbConfig::CONFIG["CXX"], *argv[1..-1]]
44
+ end
45
+
46
+ def src_file
47
+ argv.last # *.{c,cc,cpp,cu}
48
+ end
49
+
50
+ def mkmf_cu_ext
51
+ argv.first # --mkmf-cu-ext={c|cxx}
52
+ end
53
+
54
+ def cu_file?
55
+ src_file.end_with?('.cu')
56
+ end
57
+
58
+ def c_file?
59
+ !cu_file? and mkmf_cu_ext.end_with?('=c')
60
+ end
61
+
62
+ def cxx_file?
63
+ !cu_file? and mkmf_cu_ext.end_with?('=cxx')
64
+ end
65
+
66
+ COLOR_CODES = {
67
+ red: 31,
68
+ green: 32,
69
+ yellow: 33,
70
+ blue: 34,
71
+ magenta: 35,
72
+ cyan: 36
73
+ }
74
+
75
+ def colorize(code, str)
76
+ raise "#{color_code} is not supported" unless COLOR_CODES[code]
77
+ "\e[#{COLOR_CODES[code]}m#{str}\e[0m"
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,157 @@
1
+ require "optparse"
2
+ require "rbconfig"
3
+
4
+ module MakeMakefileCuda
5
+ class Nvcc
6
+ # Generate (convert) NVCC arguments from GCC arguments
7
+ def self.generate(argv)
8
+ new.generate(argv)
9
+ end
10
+
11
+ # private
12
+
13
+ def generate(argv)
14
+ opt, opt_h = build_optparser()
15
+
16
+ parse_ill_short(argv, opt_h)
17
+ parse_ill_short_with_arg(argv, opt_h)
18
+
19
+ argv = opt.parse(argv)
20
+
21
+ if opt_h["-c"].size > 0
22
+ s = generate_compiling_command_line(opt_h)
23
+ elsif opt_h['-dynamic'].size > 0 or opt_h['-shared'].size > 0
24
+ s = generate_linking_command_line(argv, opt_h)
25
+ else
26
+ raise 'something wrong'
27
+ end
28
+ end
29
+
30
+ def build_optparser
31
+ opt = OptionParser.new
32
+ opt_h = Hash.new{|h, k| h[k] = [] }
33
+
34
+ opt.on("--arch arg") {|v| opt_h["-arch"] << v }
35
+ opt.on("--std arg") {|v| opt_h["-std"] << v }
36
+ opt.on("--stdlib arg") {|v| opt_h["-stdlib"] << v }
37
+
38
+ opt.on("--Wl arg") {|v| opt_h["-Wl"] << v }
39
+
40
+ opt.on('--profile') {|v| opt_h["-pg"] << "" }
41
+ opt.on('-g') {|v| opt_h["-g"] << "" }
42
+ opt.on('-G', "--device-debug") {|v| opt_h["-G"] << "" }
43
+
44
+ opt.on('-I path') {|v| opt_h["-I"] << v }
45
+ opt.on('-D flag') {|v| opt_h["-D"] << v }
46
+ opt.on('-W flag') {|v| opt_h["-W"] << v }
47
+ opt.on('-o output') {|v| opt_h["-o"] << v }
48
+ opt.on('-c file') {|v| opt_h["-c"] << v }
49
+ opt.on('-f flag') {|v| opt_h["-f"] << v }
50
+ opt.on('-l file') {|v| opt_h["-l"] << v }
51
+ opt.on('-L path') {|v| opt_h["-L"] << v }
52
+ opt.on('-x pat', "--x pat") {|v| opt_h["-x"] << v }
53
+ opt.on('-O num'){|v| opt_h["-O"] << v if /[0-9]/ =~ v }
54
+ opt.on('--mkmf-cu-ext ext'){|v| opt_h["--mkmf-cu-ext"] << v}
55
+
56
+ return [opt, opt_h]
57
+ end
58
+
59
+ def parse_ill_short(argv, opt_h)
60
+ ["-shared", "-rdynamic", "-dynamic", "-bundle", "-pipe", "-pg", "-ggdb3"].each{|opt|
61
+ if ind = argv.find_index(opt)
62
+ opt_h[opt] << ""
63
+ argv.delete_at(ind)
64
+ end
65
+ }
66
+ ["-arch", "-std", "-stdlib"].each{|opt|
67
+ if ind = argv.find_index(opt)
68
+ argv[ind] = "-" + opt
69
+ end
70
+ }
71
+ end
72
+
73
+ def parse_ill_short_with_arg(argv, opt_h)
74
+ [/\A(\-stdlib)=(.*)/, /\A(\-std)=(.*)/, /\A(\-Wl),(.*)/].each{|reg|
75
+ argv.each{|e|
76
+ if reg =~ e
77
+ e[0..-1] = "-" + $1 + '=' + $2
78
+ end
79
+ }
80
+ }
81
+ end
82
+
83
+ def compiler_option(opt_h)
84
+ ret = ""
85
+ ["-f", "-W", "-pipe"].each{|op|
86
+ opt_h[op].each{|e|
87
+ ret << " --compiler-options " + "#{op}#{e}"
88
+ }
89
+ }
90
+ ["-stdlib", "-std"].each{|op|
91
+ opt_h[op].each{|e|
92
+ ret << " --compiler-options " + "#{op}=#{e}"
93
+ }
94
+ }
95
+ return ret
96
+ end
97
+
98
+ def linker_option(opt_h)
99
+ ret = " -shared "
100
+ ["-dynamic", "-bundle"].each{|op|
101
+ opt_h[op].each{|e|
102
+ ret << " --linker-options " + op
103
+ }
104
+ }
105
+ opt_h["-Wl"].each{|e|
106
+ ret << " --linker-options " + e
107
+ }
108
+ return ret
109
+ end
110
+
111
+ def compiler_bin(opt_h)
112
+ if opt_h["--mkmf-cu-ext"][0] == "c"
113
+ " --compiler-bindir " + RbConfig::CONFIG["CC"]
114
+ elsif opt_h["--mkmf-cu-ext"][0] == "cxx"
115
+ " --compiler-bindir " + RbConfig::CONFIG["CXX"]
116
+ end
117
+ end
118
+
119
+ def generate_compiling_command_line(opt_h)
120
+ s = ""
121
+ # options nvcc can uderstatnd
122
+ ["-std", "-pg", "-g", "-G", "-x", "-I", "-D", "-o", "-c", "-O"].each{|op|
123
+ opt_h[op].each{|e|
124
+ case op
125
+ when "-o", "-c", "-x", "-std"
126
+ s << " #{op} #{e}"
127
+ else
128
+ s << " #{op}#{e}"
129
+ end
130
+ }
131
+ }
132
+ s << compiler_option(opt_h)
133
+ s << compiler_bin(opt_h)
134
+
135
+ return s
136
+ end
137
+
138
+ def generate_linking_command_line(argv, opt_h)
139
+ s = ""
140
+ ["-L", "-l", "-o", "-c", "-O"].each{|op|
141
+ opt_h[op].each{|e|
142
+ case op
143
+ when "-o", "-c"
144
+ s << " #{op} #{e}"
145
+ s << " " + argv.join(" ") + " " if op == "-o"
146
+ else
147
+ s << " #{op}#{e}"
148
+ end
149
+ }
150
+ }
151
+ s << compiler_option(opt_h)
152
+ s << linker_option(opt_h)
153
+ s << compiler_bin(opt_h)
154
+ return s
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'mkmf-cu'
3
+ s.version = '0.1.2'
4
+ s.date = '2016-03-26'
5
+ s.summary = "Write Ruby extension in C/C++ with NVIDIA CUDA."
6
+ s.description =
7
+ "Write Ruby extension in C/C++ with NVIDIA CUDA. A simple wrapper command for nvcc and a monkey patch for mkmf."
8
+ s.authors = ["Takashi Tamura"]
9
+ s.email = ''
10
+ s.files = ["lib/mkmf-cu.rb", "lib/mkmf-cu/opt.rb", "LICENSE", "README.md"]
11
+ s.homepage = 'https://github.com/ruby-accel/mkmf-cu'
12
+ s.license = 'MIT'
13
+ s.executables << "mkmf-cu-nvcc"
14
+
15
+ s.add_development_dependency "rake", "~> 10.0"
16
+ end