cumo 0.6.0 → 0.7.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 (143) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +44 -2
  3. data/README.md +133 -0
  4. data/bench/cumo_sync_probe.rb +71 -8
  5. data/ext/cumo/cuda/cublas.c +0 -40
  6. data/ext/cumo/cuda/cudnn.c +48 -0
  7. data/ext/cumo/cuda/cudnn_impl.cpp +91 -62
  8. data/ext/cumo/cuda/runtime.c +3 -4
  9. data/ext/cumo/cumo.c +34 -0
  10. data/ext/cumo/extconf.rb +2 -0
  11. data/ext/cumo/include/cumo/cuda/cudnn.h +21 -2
  12. data/ext/cumo/include/cumo/cuda/cumo_thrust.hpp +1 -0
  13. data/ext/cumo/include/cumo/cuda/runtime.h +28 -0
  14. data/ext/cumo/include/cumo/intern.h +4 -1
  15. data/ext/cumo/include/cumo/narray.h +59 -3
  16. data/ext/cumo/include/cumo/template.h +35 -10
  17. data/ext/cumo/include/cumo/template_kernel.h +96 -0
  18. data/ext/cumo/include/cumo/types/bit.h +3 -0
  19. data/ext/cumo/include/cumo/types/bit_kernel.h +3 -0
  20. data/ext/cumo/include/cumo/types/complex_macro.h +2 -0
  21. data/ext/cumo/include/cumo/types/complex_macro_kernel.h +2 -0
  22. data/ext/cumo/include/cumo/types/float_macro.h +2 -0
  23. data/ext/cumo/include/cumo/types/float_macro_kernel.h +2 -0
  24. data/ext/cumo/include/cumo/types/half_def.h +129 -0
  25. data/ext/cumo/include/cumo/types/half_def_kernel.h +28 -0
  26. data/ext/cumo/include/cumo/types/half_macro.h +188 -0
  27. data/ext/cumo/include/cumo/types/half_macro_kernel.h +198 -0
  28. data/ext/cumo/include/cumo/types/hfloat.h +22 -0
  29. data/ext/cumo/include/cumo/types/hfloat_kernel.h +16 -0
  30. data/ext/cumo/include/cumo/types/real_accum.h +2 -0
  31. data/ext/cumo/include/cumo/types/real_accum_kernel.h +2 -0
  32. data/ext/cumo/include/cumo/types/robj_macro.h +3 -0
  33. data/ext/cumo/include/cumo/types/xint_macro.h +3 -0
  34. data/ext/cumo/include/cumo/types/xint_macro_kernel.h +2 -0
  35. data/ext/cumo/include/cumo.h +2 -2
  36. data/ext/cumo/narray/data.c +49 -174
  37. data/ext/cumo/narray/gen/def/bit.rb +2 -0
  38. data/ext/cumo/narray/gen/def/dcomplex.rb +2 -0
  39. data/ext/cumo/narray/gen/def/dfloat.rb +8 -0
  40. data/ext/cumo/narray/gen/def/hfloat.rb +47 -0
  41. data/ext/cumo/narray/gen/def/int16.rb +2 -0
  42. data/ext/cumo/narray/gen/def/int32.rb +2 -0
  43. data/ext/cumo/narray/gen/def/int64.rb +2 -0
  44. data/ext/cumo/narray/gen/def/int8.rb +2 -0
  45. data/ext/cumo/narray/gen/def/robject.rb +2 -0
  46. data/ext/cumo/narray/gen/def/scomplex.rb +2 -0
  47. data/ext/cumo/narray/gen/def/sfloat.rb +8 -0
  48. data/ext/cumo/narray/gen/def/uint16.rb +3 -1
  49. data/ext/cumo/narray/gen/def/uint32.rb +3 -1
  50. data/ext/cumo/narray/gen/def/uint64.rb +2 -0
  51. data/ext/cumo/narray/gen/def/uint8.rb +3 -1
  52. data/ext/cumo/narray/gen/erbpp2.rb +6 -0
  53. data/ext/cumo/narray/gen/spec.rb +1 -0
  54. data/ext/cumo/narray/gen/tmpl/accum.c +1 -1
  55. data/ext/cumo/narray/gen/tmpl/accum_arg.c +1 -1
  56. data/ext/cumo/narray/gen/tmpl/accum_arg_kernel.cu +5 -5
  57. data/ext/cumo/narray/gen/tmpl/accum_binary_kernel.cu +14 -1
  58. data/ext/cumo/narray/gen/tmpl/accum_index.c +1 -1
  59. data/ext/cumo/narray/gen/tmpl/accum_index_kernel.cu +5 -5
  60. data/ext/cumo/narray/gen/tmpl/alloc_func.c +4 -7
  61. data/ext/cumo/narray/gen/tmpl/allocate.c +1 -2
  62. data/ext/cumo/narray/gen/tmpl/aref_cpu.c +1 -1
  63. data/ext/cumo/narray/gen/tmpl/batch_norm.c +11 -23
  64. data/ext/cumo/narray/gen/tmpl/batch_norm_backward.c +12 -24
  65. data/ext/cumo/narray/gen/tmpl/binary_kernel.cu +69 -2
  66. data/ext/cumo/narray/gen/tmpl/clip.c +3 -3
  67. data/ext/cumo/narray/gen/tmpl/cond_unary.c +1 -1
  68. data/ext/cumo/narray/gen/tmpl/conv.c +11 -17
  69. data/ext/cumo/narray/gen/tmpl/conv_grad_w.c +11 -17
  70. data/ext/cumo/narray/gen/tmpl/conv_transpose.c +11 -17
  71. data/ext/cumo/narray/gen/tmpl/cum.c +24 -1
  72. data/ext/cumo/narray/gen/tmpl/cum_kernel.cu +29 -4
  73. data/ext/cumo/narray/gen/tmpl/each.c +2 -3
  74. data/ext/cumo/narray/gen/tmpl/each_with_index.c +5 -21
  75. data/ext/cumo/narray/gen/tmpl/extract_cpu.c +1 -1
  76. data/ext/cumo/narray/gen/tmpl/extract_data.c +1 -1
  77. data/ext/cumo/narray/gen/tmpl/fill.c +1 -1
  78. data/ext/cumo/narray/gen/tmpl/fixed_batch_norm.c +9 -21
  79. data/ext/cumo/narray/gen/tmpl/float_accum_kernel.cu +42 -37
  80. data/ext/cumo/narray/gen/tmpl/format.c +1 -1
  81. data/ext/cumo/narray/gen/tmpl/format_to_a.c +1 -1
  82. data/ext/cumo/narray/gen/tmpl/gemm.c +78 -27
  83. data/ext/cumo/narray/gen/tmpl/init_class.c +0 -7
  84. data/ext/cumo/narray/gen/tmpl/init_upcast.c +6 -0
  85. data/ext/cumo/narray/gen/tmpl/inspect.c +1 -1
  86. data/ext/cumo/narray/gen/tmpl/lib.c +11 -1
  87. data/ext/cumo/narray/gen/tmpl/map_with_index.c +7 -14
  88. data/ext/cumo/narray/gen/tmpl/median.c +9 -47
  89. data/ext/cumo/narray/gen/tmpl/minmax.c +1 -1
  90. data/ext/cumo/narray/gen/tmpl/poly.c +1 -1
  91. data/ext/cumo/narray/gen/tmpl/pooling_backward.c +2 -14
  92. data/ext/cumo/narray/gen/tmpl/pooling_forward.c +2 -14
  93. data/ext/cumo/narray/gen/tmpl/qsort.c +0 -1
  94. data/ext/cumo/narray/gen/tmpl/rand.c +20 -2
  95. data/ext/cumo/narray/gen/tmpl/rand_kernel.cu +13 -0
  96. data/ext/cumo/narray/gen/tmpl/rand_norm.c +4 -4
  97. data/ext/cumo/narray/gen/tmpl/rand_norm_kernel.cu +7 -5
  98. data/ext/cumo/narray/gen/tmpl/real_accum_kernel.cu +83 -97
  99. data/ext/cumo/narray/gen/tmpl/sort.c +1 -1
  100. data/ext/cumo/narray/gen/tmpl/sort_index.c +6 -3
  101. data/ext/cumo/narray/gen/tmpl/store_array.c +21 -22
  102. data/ext/cumo/narray/gen/tmpl/store_bit.c +1 -1
  103. data/ext/cumo/narray/gen/tmpl/store_from.c +1 -1
  104. data/ext/cumo/narray/gen/tmpl/store_from_kernel.cu +37 -2
  105. data/ext/cumo/narray/gen/tmpl/to_a.c +1 -1
  106. data/ext/cumo/narray/gen/tmpl/unary.c +20 -3
  107. data/ext/cumo/narray/gen/tmpl/unary2.c +1 -1
  108. data/ext/cumo/narray/gen/tmpl/unary_s.c +1 -1
  109. data/ext/cumo/narray/gen/tmpl_bit/allocate.c +2 -3
  110. data/ext/cumo/narray/gen/tmpl_bit/aref_cpu.c +1 -1
  111. data/ext/cumo/narray/gen/tmpl_bit/bit_count_cpu.c +1 -1
  112. data/ext/cumo/narray/gen/tmpl_bit/each.c +2 -2
  113. data/ext/cumo/narray/gen/tmpl_bit/each_with_index.c +5 -20
  114. data/ext/cumo/narray/gen/tmpl_bit/extract_cpu.c +1 -1
  115. data/ext/cumo/narray/gen/tmpl_bit/format.c +1 -1
  116. data/ext/cumo/narray/gen/tmpl_bit/format_to_a.c +1 -1
  117. data/ext/cumo/narray/gen/tmpl_bit/inspect.c +1 -1
  118. data/ext/cumo/narray/gen/tmpl_bit/mask.c +38 -17
  119. data/ext/cumo/narray/gen/tmpl_bit/mask_kernel.cu +4 -4
  120. data/ext/cumo/narray/gen/tmpl_bit/store_array.c +10 -11
  121. data/ext/cumo/narray/gen/tmpl_bit/store_from.c +1 -1
  122. data/ext/cumo/narray/gen/tmpl_bit/to_a.c +1 -1
  123. data/ext/cumo/narray/gen/tmpl_bit/where.c +66 -13
  124. data/ext/cumo/narray/gen/tmpl_bit/where2.c +57 -20
  125. data/ext/cumo/narray/gen/tmpl_bit/where_kernel.cu +6 -6
  126. data/ext/cumo/narray/index.c +63 -18
  127. data/ext/cumo/narray/index_kernel.cu +15 -0
  128. data/ext/cumo/narray/math.c +2 -0
  129. data/ext/cumo/narray/narray.c +289 -183
  130. data/ext/cumo/narray/ndloop.c +91 -26
  131. data/ext/cumo/narray/sort_kernel.cu +39 -18
  132. data/ext/cumo/narray/struct.c +14 -17
  133. data/lib/cumo/cuda/cudnn.rb +1 -1
  134. data/lib/cumo/narray/extra.rb +11 -2
  135. data/test/bit_test.rb +147 -0
  136. data/test/cudnn_test.rb +132 -46
  137. data/test/extra_test.rb +1 -1
  138. data/test/hfloat_test.rb +717 -0
  139. data/test/math_test.rb +4 -1
  140. data/test/narray_alt_coverage_test.rb +7 -0
  141. data/test/narray_test.rb +1018 -11
  142. data/test/test_helper.rb +73 -0
  143. metadata +11 -1
@@ -18,6 +18,7 @@ set is_object: false
18
18
  set is_real: false
19
19
  set is_comparable: false
20
20
  set is_double_precision: false
21
+ set is_half: false
21
22
  set need_align: false
22
23
 
23
24
  upcast_rb "Integer"
@@ -29,6 +30,7 @@ upcast "DComplex", "DComplex"
29
30
  upcast "SComplex", "SComplex"
30
31
  upcast "DFloat", "DFloat"
31
32
  upcast "SFloat", "SFloat"
33
+ upcast "HFloat", "HFloat"
32
34
  upcast "Int64", "Int64"
33
35
  upcast "Int32", "Int32"
34
36
  upcast "Int16", "Int16"
@@ -20,6 +20,7 @@ set is_complex: true
20
20
  set is_object: false
21
21
  set is_comparable: false
22
22
  set is_double_precision: true
23
+ set is_half: false
23
24
  set need_align: true
24
25
 
25
26
  upcast_rb "Integer"
@@ -31,6 +32,7 @@ upcast "DComplex", "DComplex"
31
32
  upcast "SComplex", "DComplex"
32
33
  upcast "DFloat", "DComplex"
33
34
  upcast "SFloat", "DComplex"
35
+ upcast "HFloat", "DComplex"
34
36
  upcast "Int64", "DComplex"
35
37
  upcast "Int32", "DComplex"
36
38
  upcast "Int16", "DComplex"
@@ -18,8 +18,15 @@ set is_object: false
18
18
  set is_real: true
19
19
  set is_comparable: true
20
20
  set is_double_precision: true
21
+ set is_half: false
21
22
  set need_align: true
22
23
 
24
+ set cudnn_dtype: "CUDNN_DATA_DOUBLE"
25
+ set cudnn_compute_dtype: "CUDNN_DATA_DOUBLE"
26
+ set cudnn_scalar_t: "dtype"
27
+ set cudnn_param_class: "cT"
28
+ set cudnn_math_type: "CUDNN_DEFAULT_MATH"
29
+
23
30
  upcast_rb "Integer"
24
31
  upcast_rb "Float"
25
32
  upcast_rb "Complex", "DComplex"
@@ -29,6 +36,7 @@ upcast "DComplex", "DComplex"
29
36
  upcast "SComplex", "DComplex"
30
37
  upcast "DFloat", "DFloat"
31
38
  upcast "SFloat", "DFloat"
39
+ upcast "HFloat", "DFloat"
32
40
  upcast "Int64", "DFloat"
33
41
  upcast "Int32", "DFloat"
34
42
  upcast "Int16", "DFloat"
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ set name: "hfloat"
4
+ set type_name: "hfloat"
5
+ set full_class_name: "Cumo::HFloat"
6
+ set class_name: "HFloat"
7
+ set class_alias: "Float16"
8
+ set class_var: "cT"
9
+ set ctype: "cumo_half"
10
+
11
+ set has_math: true
12
+ set is_bit: false
13
+ set is_int: false
14
+ set is_unsigned: false
15
+ set is_float: true
16
+ set is_complex: false
17
+ set is_object: false
18
+ set is_real: true
19
+ set is_comparable: true
20
+ set is_double_precision: false
21
+ set is_half: true
22
+ set need_align: true
23
+
24
+ set cudnn_dtype: "CUDNN_DATA_HALF"
25
+ set cudnn_compute_dtype: "CUDNN_DATA_FLOAT"
26
+ set cudnn_scalar_t: "float"
27
+ set cudnn_param_class: "cumo_cSFloat"
28
+ set cudnn_math_type: "CUDNN_TENSOR_OP_MATH"
29
+
30
+ upcast_rb "Integer"
31
+ upcast_rb "Float"
32
+ upcast_rb "Complex", "SComplex"
33
+
34
+ upcast "RObject", "RObject"
35
+ upcast "DComplex", "DComplex"
36
+ upcast "SComplex", "SComplex"
37
+ upcast "DFloat", "DFloat"
38
+ upcast "SFloat", "SFloat"
39
+ upcast "HFloat", "HFloat"
40
+ upcast "Int64", "HFloat"
41
+ upcast "Int32", "HFloat"
42
+ upcast "Int16", "HFloat"
43
+ upcast "Int8", "HFloat"
44
+ upcast "UInt64", "HFloat"
45
+ upcast "UInt32", "HFloat"
46
+ upcast "UInt16", "HFloat"
47
+ upcast "UInt8", "HFloat"
@@ -17,6 +17,7 @@ set is_object: false
17
17
  set is_real: true
18
18
  set is_comparable: true
19
19
  set is_double_precision: false
20
+ set is_half: false
20
21
  set need_align: true
21
22
 
22
23
  upcast_rb "Integer"
@@ -28,6 +29,7 @@ upcast "DComplex", "DComplex"
28
29
  upcast "SComplex", "SComplex"
29
30
  upcast "DFloat", "DFloat"
30
31
  upcast "SFloat", "SFloat"
32
+ upcast "HFloat", "HFloat"
31
33
  upcast "Int64", "Int64"
32
34
  upcast "Int32", "Int32"
33
35
  upcast "Int16"
@@ -17,6 +17,7 @@ set is_object: false
17
17
  set is_real: true
18
18
  set is_comparable: true
19
19
  set is_double_precision: false
20
+ set is_half: false
20
21
  set need_align: true
21
22
 
22
23
  upcast_rb "Integer"
@@ -28,6 +29,7 @@ upcast "DComplex", "DComplex"
28
29
  upcast "SComplex", "SComplex"
29
30
  upcast "DFloat", "DFloat"
30
31
  upcast "SFloat", "SFloat"
32
+ upcast "HFloat", "HFloat"
31
33
  upcast "Int64", "Int64"
32
34
  upcast "Int32"
33
35
  upcast "Int16"
@@ -17,6 +17,7 @@ set is_object: false
17
17
  set is_real: true
18
18
  set is_comparable: true
19
19
  set is_double_precision: false
20
+ set is_half: false
20
21
  set need_align: true
21
22
 
22
23
  upcast_rb "Integer"
@@ -28,6 +29,7 @@ upcast "DComplex", "DComplex"
28
29
  upcast "SComplex", "SComplex"
29
30
  upcast "DFloat", "DFloat"
30
31
  upcast "SFloat", "SFloat"
32
+ upcast "HFloat", "HFloat"
31
33
  upcast "Int64"
32
34
  upcast "Int32"
33
35
  upcast "Int16"
@@ -17,6 +17,7 @@ set is_object: false
17
17
  set is_real: true
18
18
  set is_comparable: true
19
19
  set is_double_precision: false
20
+ set is_half: false
20
21
  set need_align: false
21
22
 
22
23
  upcast_rb "Integer"
@@ -28,6 +29,7 @@ upcast "DComplex", "DComplex"
28
29
  upcast "SComplex", "SComplex"
29
30
  upcast "DFloat", "DFloat"
30
31
  upcast "SFloat", "SFloat"
32
+ upcast "HFloat", "HFloat"
31
33
  upcast "Int64", "Int64"
32
34
  upcast "Int32", "Int32"
33
35
  upcast "Int16", "Int16"
@@ -19,6 +19,7 @@ set is_complex: false
19
19
  set is_object: true
20
20
  set is_comparable: true
21
21
  set is_double_precision: false
22
+ set is_half: false
22
23
  set need_align: false
23
24
 
24
25
  upcast_rb "Integer"
@@ -29,6 +30,7 @@ upcast "DComplex", "RObject"
29
30
  upcast "SComplex", "RObject"
30
31
  upcast "DFloat", "RObject"
31
32
  upcast "SFloat", "RObject"
33
+ upcast "HFloat", "RObject"
32
34
  upcast "Int64", "RObject"
33
35
  upcast "Int32", "RObject"
34
36
  upcast "Int16", "RObject"
@@ -20,6 +20,7 @@ set is_complex: true
20
20
  set is_object: false
21
21
  set is_comparable: false
22
22
  set is_double_precision: false
23
+ set is_half: false
23
24
  set need_align: true
24
25
 
25
26
  upcast_rb "Integer"
@@ -31,6 +32,7 @@ upcast "DComplex", "DComplex"
31
32
  upcast "SComplex", "SComplex"
32
33
  upcast "DFloat", "DComplex"
33
34
  upcast "SFloat", "SComplex"
35
+ upcast "HFloat", "SComplex"
34
36
  upcast "Int64", "SComplex"
35
37
  upcast "Int32", "SComplex"
36
38
  upcast "Int16", "SComplex"
@@ -18,8 +18,15 @@ set is_object: false
18
18
  set is_real: true
19
19
  set is_comparable: true
20
20
  set is_double_precision: false
21
+ set is_half: false
21
22
  set need_align: true
22
23
 
24
+ set cudnn_dtype: "CUDNN_DATA_FLOAT"
25
+ set cudnn_compute_dtype: "CUDNN_DATA_FLOAT"
26
+ set cudnn_scalar_t: "dtype"
27
+ set cudnn_param_class: "cT"
28
+ set cudnn_math_type: "CUDNN_DEFAULT_MATH"
29
+
23
30
  upcast_rb "Integer"
24
31
  upcast_rb "Float"
25
32
  upcast_rb "Complex", "SComplex"
@@ -29,6 +36,7 @@ upcast "DComplex", "DComplex"
29
36
  upcast "SComplex", "SComplex"
30
37
  upcast "DFloat", "DFloat"
31
38
  upcast "SFloat", "SFloat"
39
+ upcast "HFloat", "SFloat"
32
40
  upcast "Int64", "SFloat"
33
41
  upcast "Int32", "SFloat"
34
42
  upcast "Int16", "SFloat"
@@ -17,6 +17,7 @@ set is_object: false
17
17
  set is_real: true
18
18
  set is_comparable: true
19
19
  set is_double_precision: false
20
+ set is_half: false
20
21
  set need_align: true
21
22
 
22
23
  upcast_rb "Integer"
@@ -28,10 +29,11 @@ upcast "DComplex", "DComplex"
28
29
  upcast "SComplex", "SComplex"
29
30
  upcast "DFloat", "DFloat"
30
31
  upcast "SFloat", "SFloat"
32
+ upcast "HFloat", "HFloat"
31
33
  upcast "Int64", "Int64"
32
34
  upcast "Int32", "Int32"
33
35
  upcast "Int16", "Int16"
34
- upcast "Int8", "Int16"
36
+ upcast "Int8", "Int32"
35
37
  upcast "UInt64", "UInt64"
36
38
  upcast "UInt32", "UInt32"
37
39
  upcast "UInt16"
@@ -17,6 +17,7 @@ set is_object: false
17
17
  set is_real: true
18
18
  set is_comparable: true
19
19
  set is_double_precision: false
20
+ set is_half: false
20
21
  set need_align: true
21
22
 
22
23
  upcast_rb "Integer"
@@ -28,10 +29,11 @@ upcast "DComplex", "DComplex"
28
29
  upcast "SComplex", "SComplex"
29
30
  upcast "DFloat", "DFloat"
30
31
  upcast "SFloat", "SFloat"
32
+ upcast "HFloat", "HFloat"
31
33
  upcast "Int64", "Int64"
32
34
  upcast "Int32", "Int32"
33
35
  upcast "Int16", "Int32"
34
- upcast "Int8", "Int32"
36
+ upcast "Int8", "Int64"
35
37
  upcast "UInt64", "UInt64"
36
38
  upcast "UInt32"
37
39
  upcast "UInt16"
@@ -17,6 +17,7 @@ set is_object: false
17
17
  set is_real: true
18
18
  set is_comparable: true
19
19
  set is_double_precision: false
20
+ set is_half: false
20
21
  set need_align: true
21
22
 
22
23
  upcast_rb "Integer"
@@ -28,6 +29,7 @@ upcast "DComplex", "DComplex"
28
29
  upcast "SComplex", "SComplex"
29
30
  upcast "DFloat", "DFloat"
30
31
  upcast "SFloat", "SFloat"
32
+ upcast "HFloat", "HFloat"
31
33
  upcast "Int64", "Int64"
32
34
  upcast "Int32", "Int64"
33
35
  upcast "Int16", "Int64"
@@ -17,6 +17,7 @@ set is_object: false
17
17
  set is_real: true
18
18
  set is_comparable: true
19
19
  set is_double_precision: false
20
+ set is_half: false
20
21
  set need_align: false
21
22
 
22
23
  upcast_rb "Integer"
@@ -28,10 +29,11 @@ upcast "DComplex", "DComplex"
28
29
  upcast "SComplex", "SComplex"
29
30
  upcast "DFloat", "DFloat"
30
31
  upcast "SFloat", "SFloat"
32
+ upcast "HFloat", "HFloat"
31
33
  upcast "Int64", "Int64"
32
34
  upcast "Int32", "Int32"
33
35
  upcast "Int16", "Int16"
34
- upcast "Int8", "Int8"
36
+ upcast "Int8", "Int16"
35
37
  upcast "UInt64", "UInt64"
36
38
  upcast "UInt32", "UInt32"
37
39
  upcast "UInt16", "UInt16"
@@ -110,6 +110,9 @@ class ErbPP
110
110
  def init_def
111
111
  end
112
112
 
113
+ def upcast_def
114
+ end
115
+
113
116
  def find_tmpl(name)
114
117
  @parent.children.find { |x| x.name == name }
115
118
  end
@@ -212,6 +215,9 @@ class DefClass < DefModule
212
215
  def init_erb
213
216
  @opts[:init_erb] || "init_class"
214
217
  end
218
+ def upcast_def
219
+ load_erb("init_upcast").result(binding)
220
+ end
215
221
  def super_class
216
222
  @opts[:super_class] || "rb_cObject"
217
223
  end
@@ -127,6 +127,7 @@ def_method "store" do
127
127
  store_from "DComplex", "cumo_dcomplex", "m_from_dcomplex"
128
128
  store_from "SComplex", "cumo_scomplex", "m_from_scomplex"
129
129
  end
130
+ store_from "HFloat", "cumo_half", "m_from_half"
130
131
  store_from "DFloat", "double", "m_from_real"
131
132
  store_from "SFloat", "float", "m_from_real"
132
133
  store_from "Int64", "int64_t", "m_from_int64"
@@ -23,7 +23,7 @@ static void
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
- cumo_cuda_runtime_check_status(cudaDeviceSynchronize());
26
+ cumo_cuda_runtime_device_synchronize();
27
27
  *(<%=dtype%>*)p2 = f_<%=name%><%=nan%>(n,p1,s1);
28
28
  }
29
29
  //<% elsif !indexer_ops.include?(name) %>
@@ -20,7 +20,7 @@ static void
20
20
  o_ptr = CUMO_NDL_PTR(lp,1);
21
21
 
22
22
  CUMO_SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%><%=nan%>", "<%=type_name%>");
23
- cumo_cuda_runtime_check_status(cudaDeviceSynchronize());
23
+ cumo_cuda_runtime_device_synchronize();
24
24
  idx = f_<%=name[3..5]%>_index<%=nan%>(n,d_ptr,d_step);
25
25
  *(idx_t*)o_ptr = (idx_t)idx;
26
26
  }
@@ -33,7 +33,7 @@ struct cumo_<%=type_name%>_argmin_int<%=i%>_impl {
33
33
  return;
34
34
  }
35
35
  <% end %>
36
- if (accum.value > next.value || (accum.value == next.value && next.index < accum.index)) { accum = next; }
36
+ if (m_gt(accum.value, next.value) || (m_eq(accum.value, next.value) && next.index < accum.index)) { accum = next; }
37
37
  }
38
38
  __device__ idx_t MapOut(ValueAndIndex accum) { return accum.index; }
39
39
  };
@@ -56,7 +56,7 @@ struct cumo_<%=type_name%>_argmin_nan_int<%=i%>_impl {
56
56
  if (next_nan && (!accum_nan || next.index < accum.index)) { accum = next; }
57
57
  return;
58
58
  }
59
- if (accum.value > next.value || (accum.value == next.value && next.index < accum.index)) { accum = next; }
59
+ if (m_gt(accum.value, next.value) || (m_eq(accum.value, next.value) && next.index < accum.index)) { accum = next; }
60
60
  }
61
61
  __device__ idx_t MapOut(ValueAndIndex accum) { return accum.index; }
62
62
  };
@@ -83,7 +83,7 @@ struct cumo_<%=type_name%>_argmax_int<%=i%>_impl {
83
83
  return;
84
84
  }
85
85
  <% end %>
86
- if (accum.value < next.value || (accum.value == next.value && next.index < accum.index)) { accum = next; }
86
+ if (m_lt(accum.value, next.value) || (m_eq(accum.value, next.value) && next.index < accum.index)) { accum = next; }
87
87
  }
88
88
  __device__ idx_t MapOut(ValueAndIndex accum) { return accum.index; }
89
89
  };
@@ -97,7 +97,7 @@ struct cumo_<%=type_name%>_argmax_nan_int<%=i%>_impl {
97
97
  dtype value;
98
98
  idx_t index;
99
99
  };
100
- __device__ ValueAndIndex Identity(idx_t /*index*/) { return {-(dtype)INFINITY, INT<%=i%>_MAX}; }
100
+ __device__ ValueAndIndex Identity(idx_t /*index*/) { return {(dtype)(-INFINITY), INT<%=i%>_MAX}; }
101
101
  __device__ ValueAndIndex MapIn(dtype in, idx_t index) { return {in, index}; }
102
102
  __device__ void Reduce(ValueAndIndex next, ValueAndIndex& accum) {
103
103
  bool accum_nan = !not_nan(accum.value);
@@ -106,7 +106,7 @@ struct cumo_<%=type_name%>_argmax_nan_int<%=i%>_impl {
106
106
  if (next_nan && (!accum_nan || next.index < accum.index)) { accum = next; }
107
107
  return;
108
108
  }
109
- if (accum.value < next.value || (accum.value == next.value && next.index < accum.index)) { accum = next; }
109
+ if (m_lt(accum.value, next.value) || (m_eq(accum.value, next.value) && next.index < accum.index)) { accum = next; }
110
110
  }
111
111
  __device__ idx_t MapOut(ValueAndIndex accum) { return accum.index; }
112
112
  };
@@ -14,8 +14,20 @@
14
14
 
15
15
  // The product is never an array of its own: MapIn takes one element of each
16
16
  // operand, which is what a zip reduction hands it. The accumulator stays dtype
17
- // rather than widening, as the host loop it replaces did.
17
+ // rather than widening, as the host loop it replaces did, except for half,
18
+ // which cannot carry a sum of more than a couple of thousand terms.
18
19
  struct <%="cumo_#{type_name}_#{name}#{nan}_impl"%> {
20
+ <% if is_half %>
21
+ __device__ float Identity(int64_t /*index*/) { return 0.0f; }
22
+ __device__ float MapIn(dtype x, dtype y, int64_t /*index*/) {
23
+ <% if nan == '_nan' %>
24
+ if (!not_nan(x) || !not_nan(y)) { return 0.0f; }
25
+ <% end %>
26
+ return cumo_half2float(x) * cumo_half2float(y);
27
+ }
28
+ __device__ void Reduce(float next, float& accum) { accum = next + accum; }
29
+ __device__ dtype MapOut(float accum) { return cumo_float2half(accum); }
30
+ <% else %>
19
31
  __device__ dtype Identity(int64_t /*index*/) { return m_zero; }
20
32
  __device__ dtype MapIn(dtype x, dtype y, int64_t /*index*/) {
21
33
  dtype z = m_zero;
@@ -24,6 +36,7 @@ struct <%="cumo_#{type_name}_#{name}#{nan}_impl"%> {
24
36
  }
25
37
  __device__ void Reduce(dtype next, dtype& accum) { accum = m_add(next, accum); }
26
38
  __device__ dtype MapOut(dtype accum) { return accum; }
39
+ <% end %>
27
40
  };
28
41
  //<% end %>
29
42
 
@@ -21,7 +21,7 @@ static void
21
21
  o_ptr = CUMO_NDL_PTR(lp,2);
22
22
 
23
23
  CUMO_SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%><%=nan%>", "<%=type_name%>");
24
- cumo_cuda_runtime_check_status(cudaDeviceSynchronize());
24
+ cumo_cuda_runtime_device_synchronize();
25
25
  idx = f_<%=name%><%=nan%>(n,d_ptr,d_step);
26
26
  *(idx_t*)o_ptr = *(idx_t*)(i_ptr + i_step * idx);
27
27
  }
@@ -33,7 +33,7 @@ struct cumo_<%=type_name%>_min_index_int<%=i%>_impl {
33
33
  return;
34
34
  }
35
35
  <% end %>
36
- if (accum.value > next.value || (accum.value == next.value && next.index < accum.index)) { accum = next; }
36
+ if (m_gt(accum.value, next.value) || (m_eq(accum.value, next.value) && next.index < accum.index)) { accum = next; }
37
37
  }
38
38
  __device__ idx_t MapOut(ValueAndIndex accum) { return accum.index; }
39
39
  };
@@ -56,7 +56,7 @@ struct cumo_<%=type_name%>_min_index_nan_int<%=i%>_impl {
56
56
  if (next_nan && (!accum_nan || next.index < accum.index)) { accum = next; }
57
57
  return;
58
58
  }
59
- if (accum.value > next.value || (accum.value == next.value && next.index < accum.index)) { accum = next; }
59
+ if (m_gt(accum.value, next.value) || (m_eq(accum.value, next.value) && next.index < accum.index)) { accum = next; }
60
60
  }
61
61
  __device__ idx_t MapOut(ValueAndIndex accum) { return accum.index; }
62
62
  };
@@ -83,7 +83,7 @@ struct cumo_<%=type_name%>_max_index_int<%=i%>_impl {
83
83
  return;
84
84
  }
85
85
  <% end %>
86
- if (accum.value < next.value || (accum.value == next.value && next.index < accum.index)) { accum = next; }
86
+ if (m_lt(accum.value, next.value) || (m_eq(accum.value, next.value) && next.index < accum.index)) { accum = next; }
87
87
  }
88
88
  __device__ idx_t MapOut(ValueAndIndex accum) { return accum.index; }
89
89
  };
@@ -97,7 +97,7 @@ struct cumo_<%=type_name%>_max_index_nan_int<%=i%>_impl {
97
97
  dtype value;
98
98
  idx_t index;
99
99
  };
100
- __device__ ValueAndIndex Identity(idx_t /*index*/) { return {-(dtype)INFINITY, INT<%=i%>_MAX}; }
100
+ __device__ ValueAndIndex Identity(idx_t /*index*/) { return {(dtype)(-INFINITY), INT<%=i%>_MAX}; }
101
101
  __device__ ValueAndIndex MapIn(dtype in, idx_t index) { return {in, index}; }
102
102
  __device__ void Reduce(ValueAndIndex next, ValueAndIndex& accum) {
103
103
  bool accum_nan = !not_nan(accum.value);
@@ -106,7 +106,7 @@ struct cumo_<%=type_name%>_max_index_nan_int<%=i%>_impl {
106
106
  if (next_nan && (!accum_nan || next.index < accum.index)) { accum = next; }
107
107
  return;
108
108
  }
109
- if (accum.value < next.value || (accum.value == next.value && next.index < accum.index)) { accum = next; }
109
+ if (m_lt(accum.value, next.value) || (m_eq(accum.value, next.value) && next.index < accum.index)) { accum = next; }
110
110
  }
111
111
  __device__ idx_t MapOut(ValueAndIndex accum) { return accum.index; }
112
112
  };
@@ -5,7 +5,7 @@ static size_t
5
5
  return 0;
6
6
  }
7
7
  <% if is_bit %>
8
- return ((na->base.size-1)/8/sizeof(CUMO_BIT_DIGIT)+1)*sizeof(CUMO_BIT_DIGIT);
8
+ return CUMO_BIT_BYTES(na->base.size);
9
9
  <% else %>
10
10
  return na->base.size * sizeof(dtype);
11
11
  <% end %>
@@ -38,14 +38,12 @@ static void
38
38
  assert(na->base.type == CUMO_NARRAY_DATA_T);
39
39
 
40
40
  if (na->ptr != NULL) {
41
- if (na->owned) {
42
41
  <% if is_object %>
43
- xfree(na->ptr);
42
+ xfree(na->ptr);
44
43
  <% else %>
45
- cumo_cuda_runtime_free_no_raise(na->ptr);
46
- rb_gc_adjust_memory_usage(-(ssize_t)<%=type_name%>_data_bytes(na));
44
+ cumo_cuda_runtime_free_no_raise(na->ptr);
45
+ rb_gc_adjust_memory_usage(-(ssize_t)<%=type_name%>_data_bytes(na));
47
46
  <% end %>
48
- }
49
47
  na->ptr = NULL;
50
48
  }
51
49
  if (na->base.shape != NULL && na->base.shape != &(na->base.size)) {
@@ -117,6 +115,5 @@ static VALUE
117
115
  na->base.shape = NULL;
118
116
  na->base.reduce = INT2FIX(0);
119
117
  na->ptr = NULL;
120
- na->owned = FALSE;
121
118
  return TypedData_Wrap_Struct(klass, &<%=type_name%>_data_type, (void*)na);
122
119
  }
@@ -29,7 +29,6 @@ static VALUE
29
29
  ptr = cumo_cuda_runtime_malloc(sizeof(dtype) * na->size);
30
30
  <% end %>
31
31
  CUMO_NA_DATA_PTR(na) = ptr;
32
- CUMO_NA_DATA_OWNED(na) = TRUE;
33
32
  <% unless is_object %>
34
33
  // Device memory never passes through ruby_xmalloc, so the GC sees a
35
34
  // few-byte object holding an arbitrarily large buffer and does not
@@ -48,7 +47,7 @@ static VALUE
48
47
  // Callers that read on the host synchronize before they ask for
49
48
  // the pointer, which is before this fill was even launched.
50
49
  CUMO_SHOW_SYNCHRONIZE_WARNING_ONCE("allocate", "<%=type_name%>");
51
- cumo_cuda_runtime_check_status(cudaDeviceSynchronize());
50
+ cumo_cuda_runtime_device_synchronize();
52
51
  }
53
52
  }
54
53
  <% end %>
@@ -44,7 +44,7 @@ static VALUE
44
44
  } else {
45
45
  ptr = cumo_na_get_pointer_for_read(self) + pos;
46
46
  CUMO_SHOW_SYNCHRONIZE_WARNING_ONCE("<%=name%>", "<%=type_name%>");
47
- cumo_cuda_runtime_check_status(cudaDeviceSynchronize());
47
+ cumo_cuda_runtime_device_synchronize();
48
48
  return m_extract(ptr);
49
49
  }
50
50
  }
@@ -1,17 +1,5 @@
1
1
  #ifdef CUDNN_FOUND
2
2
 
3
- <%
4
- cudnn_dtype =
5
- case type_name
6
- when 'sfloat'
7
- 'CUDNN_DATA_FLOAT'
8
- when 'dfloat'
9
- 'CUDNN_DATA_DOUBLE'
10
- else
11
- # CUDNN_DATA_HALF
12
- raise 'not supported'
13
- end
14
- %>
15
3
 
16
4
  // y = x.batch_norm(gamma, beta, running_mean:, running_var:, eps:, decay:, axis:, mean:, inv_std:)
17
5
  static VALUE
@@ -20,8 +8,8 @@ static VALUE
20
8
  cudnnDataType_t cudnn_dtype = <%= cudnn_dtype %>;
21
9
  cudnnStatus_t status = 0;
22
10
  cudnnHandle_t handle = 0;
23
- dtype coef_one = 1;
24
- dtype coef_zero = 0;
11
+ <%=cudnn_scalar_t%> coef_one = 1;
12
+ <%=cudnn_scalar_t%> coef_zero = 0;
25
13
 
26
14
  VALUE x=self, gamma, beta, running_mean, running_var, eps, decay, axis, mean, inv_std, y;
27
15
  VALUE kw_hash = Qnil;
@@ -126,12 +114,12 @@ static VALUE
126
114
  }
127
115
 
128
116
  CUMO_CHECK_NARRAY_TYPE(x, cT);
129
- CUMO_CHECK_NARRAY_TYPE(gamma, cT);
130
- CUMO_CHECK_NARRAY_TYPE(beta, cT);
131
- if (running_mean != Qnil) CUMO_CHECK_NARRAY_TYPE(running_mean, cT);
132
- if (running_var != Qnil) CUMO_CHECK_NARRAY_TYPE(running_var, cT);
133
- if (mean != Qnil) CUMO_CHECK_NARRAY_TYPE(mean, cT);
134
- if (inv_std != Qnil) CUMO_CHECK_NARRAY_TYPE(inv_std, cT);
117
+ cumo_cuda_cudnn_check_param_type(gamma, <%=cudnn_param_class%>, "gamma");
118
+ cumo_cuda_cudnn_check_param_type(beta, <%=cudnn_param_class%>, "beta");
119
+ if (running_mean != Qnil) cumo_cuda_cudnn_check_param_type(running_mean, <%=cudnn_param_class%>, "running_mean");
120
+ if (running_var != Qnil) cumo_cuda_cudnn_check_param_type(running_var, <%=cudnn_param_class%>, "running_var");
121
+ if (mean != Qnil) cumo_cuda_cudnn_check_param_type(mean, <%=cudnn_param_class%>, "mean");
122
+ if (inv_std != Qnil) cumo_cuda_cudnn_check_param_type(inv_std, <%=cudnn_param_class%>, "inv_std");
135
123
 
136
124
  x_cont = cumo_na_as_contiguous_array(x);
137
125
  gamma_cont = cumo_na_as_contiguous_array(gamma);
@@ -166,9 +154,9 @@ static VALUE
166
154
  mode = cumo_cuda_cudnn_GetBatchNormMode(axis_ndim, int_axis);
167
155
  status = cumo_cuda_cudnn_CreateBNTensorDescriptor(&bn_desc, x_desc, mode);
168
156
  if (status != CUDNN_STATUS_SUCCESS) goto BATCH_NORM_ERROR;
169
- // The derived descriptor carries x's own type -- cuDNN widens only for
170
- // half, which these templates are never generated for -- and the checks
171
- // above hold every parameter to x's class, so none of them needs a cast.
157
+ // cuDNN derives the parameter descriptor as float for a half x and as x's
158
+ // own type otherwise, and the checks above hold every parameter to exactly
159
+ // that class, so none of them needs a cast.
172
160
 
173
161
  handle = cumo_cuda_cudnn_handle();
174
162