cumo 0.5.11 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +76 -1
- data/README.md +133 -0
- data/bench/cumo_shape_probe.rb +264 -0
- data/bench/cumo_sync_probe.rb +71 -8
- data/ext/cumo/cuda/cublas.c +0 -40
- data/ext/cumo/cuda/cudnn.c +48 -0
- data/ext/cumo/cuda/cudnn_impl.cpp +100 -63
- data/ext/cumo/cuda/memory_pool_impl_test.cpp +4 -1
- data/ext/cumo/cuda/nvrtc.c +1 -1
- data/ext/cumo/cuda/runtime.c +3 -4
- data/ext/cumo/cumo.c +34 -0
- data/ext/cumo/depend.erb +7 -0
- data/ext/cumo/extconf.rb +2 -0
- data/ext/cumo/include/cumo/bit_reduce_kernel.h +119 -13
- data/ext/cumo/include/cumo/check.h +51 -0
- data/ext/cumo/include/cumo/cuda/cudnn.h +47 -43
- data/ext/cumo/include/cumo/cuda/cumo_thrust.hpp +1 -0
- data/ext/cumo/include/cumo/cuda/runtime.h +28 -0
- data/ext/cumo/include/cumo/indexer.h +29 -8
- data/ext/cumo/include/cumo/intern.h +4 -1
- data/ext/cumo/include/cumo/narray.h +69 -3
- data/ext/cumo/include/cumo/ndloop.h +1 -0
- data/ext/cumo/include/cumo/reduce_kernel.h +133 -50
- data/ext/cumo/include/cumo/template.h +35 -10
- data/ext/cumo/include/cumo/template_kernel.h +96 -0
- data/ext/cumo/include/cumo/types/bit.h +3 -0
- data/ext/cumo/include/cumo/types/bit_kernel.h +3 -0
- data/ext/cumo/include/cumo/types/complex_macro.h +2 -0
- data/ext/cumo/include/cumo/types/complex_macro_kernel.h +2 -0
- data/ext/cumo/include/cumo/types/float_macro.h +17 -2
- data/ext/cumo/include/cumo/types/float_macro_kernel.h +17 -2
- data/ext/cumo/include/cumo/types/half_def.h +129 -0
- data/ext/cumo/include/cumo/types/half_def_kernel.h +28 -0
- data/ext/cumo/include/cumo/types/half_macro.h +188 -0
- data/ext/cumo/include/cumo/types/half_macro_kernel.h +198 -0
- data/ext/cumo/include/cumo/types/hfloat.h +22 -0
- data/ext/cumo/include/cumo/types/hfloat_kernel.h +16 -0
- data/ext/cumo/include/cumo/types/int_macro.h +20 -0
- data/ext/cumo/include/cumo/types/int_macro_kernel.h +20 -0
- data/ext/cumo/include/cumo/types/real_accum.h +2 -0
- data/ext/cumo/include/cumo/types/real_accum_kernel.h +2 -0
- data/ext/cumo/include/cumo/types/robj_macro.h +11 -3
- data/ext/cumo/include/cumo/types/xint_macro.h +3 -0
- data/ext/cumo/include/cumo/types/xint_macro_kernel.h +2 -0
- data/ext/cumo/include/cumo.h +2 -2
- data/ext/cumo/narray/data.c +70 -199
- data/ext/cumo/narray/data_kernel.cu +113 -0
- data/ext/cumo/narray/gen/def/bit.rb +2 -0
- data/ext/cumo/narray/gen/def/dcomplex.rb +2 -0
- data/ext/cumo/narray/gen/def/dfloat.rb +8 -0
- data/ext/cumo/narray/gen/def/hfloat.rb +47 -0
- data/ext/cumo/narray/gen/def/int16.rb +2 -0
- data/ext/cumo/narray/gen/def/int32.rb +2 -0
- data/ext/cumo/narray/gen/def/int64.rb +2 -0
- data/ext/cumo/narray/gen/def/int8.rb +2 -0
- data/ext/cumo/narray/gen/def/robject.rb +2 -0
- data/ext/cumo/narray/gen/def/scomplex.rb +2 -0
- data/ext/cumo/narray/gen/def/sfloat.rb +8 -0
- data/ext/cumo/narray/gen/def/uint16.rb +3 -1
- data/ext/cumo/narray/gen/def/uint32.rb +3 -1
- data/ext/cumo/narray/gen/def/uint64.rb +2 -0
- data/ext/cumo/narray/gen/def/uint8.rb +3 -1
- data/ext/cumo/narray/gen/erbpp2.rb +6 -0
- data/ext/cumo/narray/gen/narray_def.rb +5 -0
- data/ext/cumo/narray/gen/spec.rb +11 -0
- data/ext/cumo/narray/gen/tmpl/accum.c +1 -1
- data/ext/cumo/narray/gen/tmpl/accum_arg.c +1 -1
- data/ext/cumo/narray/gen/tmpl/accum_arg_kernel.cu +5 -5
- data/ext/cumo/narray/gen/tmpl/accum_binary_kernel.cu +14 -1
- data/ext/cumo/narray/gen/tmpl/accum_index.c +1 -1
- data/ext/cumo/narray/gen/tmpl/accum_index_kernel.cu +5 -5
- data/ext/cumo/narray/gen/tmpl/alloc_func.c +4 -7
- data/ext/cumo/narray/gen/tmpl/allocate.c +1 -2
- data/ext/cumo/narray/gen/tmpl/aref_cpu.c +1 -1
- data/ext/cumo/narray/gen/tmpl/batch_norm.c +27 -36
- data/ext/cumo/narray/gen/tmpl/batch_norm_backward.c +26 -35
- data/ext/cumo/narray/gen/tmpl/binary.c +3 -3
- data/ext/cumo/narray/gen/tmpl/binary2.c +1 -1
- data/ext/cumo/narray/gen/tmpl/binary_kernel.cu +69 -2
- data/ext/cumo/narray/gen/tmpl/binary_s.c +3 -3
- data/ext/cumo/narray/gen/tmpl/clip.c +9 -9
- data/ext/cumo/narray/gen/tmpl/cond_binary.c +3 -3
- data/ext/cumo/narray/gen/tmpl/cond_unary.c +2 -2
- data/ext/cumo/narray/gen/tmpl/conv.c +19 -25
- data/ext/cumo/narray/gen/tmpl/conv_grad_w.c +21 -27
- data/ext/cumo/narray/gen/tmpl/conv_transpose.c +21 -27
- data/ext/cumo/narray/gen/tmpl/cum.c +24 -1
- data/ext/cumo/narray/gen/tmpl/cum_kernel.cu +29 -4
- data/ext/cumo/narray/gen/tmpl/each.c +2 -3
- data/ext/cumo/narray/gen/tmpl/each_with_index.c +5 -21
- data/ext/cumo/narray/gen/tmpl/ewcomp.c +1 -1
- data/ext/cumo/narray/gen/tmpl/extract_cpu.c +1 -1
- data/ext/cumo/narray/gen/tmpl/extract_data.c +1 -1
- data/ext/cumo/narray/gen/tmpl/fill.c +2 -2
- data/ext/cumo/narray/gen/tmpl/fixed_batch_norm.c +18 -27
- data/ext/cumo/narray/gen/tmpl/float_accum_kernel.cu +42 -37
- data/ext/cumo/narray/gen/tmpl/format.c +1 -1
- data/ext/cumo/narray/gen/tmpl/format_to_a.c +1 -1
- data/ext/cumo/narray/gen/tmpl/frexp.c +1 -1
- data/ext/cumo/narray/gen/tmpl/gemm.c +78 -27
- data/ext/cumo/narray/gen/tmpl/init_class.c +0 -7
- data/ext/cumo/narray/gen/tmpl/init_upcast.c +6 -0
- data/ext/cumo/narray/gen/tmpl/inspect.c +1 -1
- data/ext/cumo/narray/gen/tmpl/lib.c +11 -1
- data/ext/cumo/narray/gen/tmpl/map_with_index.c +7 -14
- data/ext/cumo/narray/gen/tmpl/median.c +9 -47
- data/ext/cumo/narray/gen/tmpl/minmax.c +1 -1
- data/ext/cumo/narray/gen/tmpl/poly.c +2 -2
- data/ext/cumo/narray/gen/tmpl/pooling_backward.c +6 -18
- data/ext/cumo/narray/gen/tmpl/pooling_forward.c +6 -18
- data/ext/cumo/narray/gen/tmpl/pow.c +6 -6
- data/ext/cumo/narray/gen/tmpl/qsort.c +0 -1
- data/ext/cumo/narray/gen/tmpl/rand.c +20 -2
- data/ext/cumo/narray/gen/tmpl/rand_kernel.cu +13 -0
- data/ext/cumo/narray/gen/tmpl/rand_norm.c +4 -4
- data/ext/cumo/narray/gen/tmpl/rand_norm_kernel.cu +7 -5
- data/ext/cumo/narray/gen/tmpl/real_accum_kernel.cu +155 -96
- data/ext/cumo/narray/gen/tmpl/set2.c +1 -1
- data/ext/cumo/narray/gen/tmpl/sort.c +1 -1
- data/ext/cumo/narray/gen/tmpl/sort_index.c +6 -3
- data/ext/cumo/narray/gen/tmpl/store_array.c +21 -22
- data/ext/cumo/narray/gen/tmpl/store_bit.c +2 -2
- data/ext/cumo/narray/gen/tmpl/store_from.c +2 -2
- data/ext/cumo/narray/gen/tmpl/store_from_kernel.cu +37 -2
- data/ext/cumo/narray/gen/tmpl/to_a.c +1 -1
- data/ext/cumo/narray/gen/tmpl/unary.c +21 -4
- data/ext/cumo/narray/gen/tmpl/unary2.c +2 -2
- data/ext/cumo/narray/gen/tmpl/unary_ret2.c +1 -1
- data/ext/cumo/narray/gen/tmpl/unary_s.c +2 -2
- data/ext/cumo/narray/gen/tmpl_bit/allocate.c +2 -3
- data/ext/cumo/narray/gen/tmpl_bit/aref_cpu.c +1 -1
- data/ext/cumo/narray/gen/tmpl_bit/binary.c +1 -1
- data/ext/cumo/narray/gen/tmpl_bit/bit_count_cpu.c +1 -1
- data/ext/cumo/narray/gen/tmpl_bit/bit_reduce.c +4 -1
- data/ext/cumo/narray/gen/tmpl_bit/bit_stat.c +36 -0
- data/ext/cumo/narray/gen/tmpl_bit/bit_stat_kernel.cu +4 -0
- data/ext/cumo/narray/gen/tmpl_bit/each.c +2 -2
- data/ext/cumo/narray/gen/tmpl_bit/each_with_index.c +5 -20
- data/ext/cumo/narray/gen/tmpl_bit/extract.c +13 -27
- data/ext/cumo/narray/gen/tmpl_bit/extract_cpu.c +1 -1
- data/ext/cumo/narray/gen/tmpl_bit/fill.c +1 -1
- data/ext/cumo/narray/gen/tmpl_bit/format.c +1 -1
- data/ext/cumo/narray/gen/tmpl_bit/format_to_a.c +1 -1
- data/ext/cumo/narray/gen/tmpl_bit/inspect.c +1 -1
- data/ext/cumo/narray/gen/tmpl_bit/mask.c +38 -17
- data/ext/cumo/narray/gen/tmpl_bit/mask_kernel.cu +4 -4
- data/ext/cumo/narray/gen/tmpl_bit/store_array.c +10 -11
- data/ext/cumo/narray/gen/tmpl_bit/store_bit.c +1 -1
- data/ext/cumo/narray/gen/tmpl_bit/store_from.c +2 -2
- data/ext/cumo/narray/gen/tmpl_bit/to_a.c +1 -1
- data/ext/cumo/narray/gen/tmpl_bit/unary.c +1 -1
- data/ext/cumo/narray/gen/tmpl_bit/where.c +66 -13
- data/ext/cumo/narray/gen/tmpl_bit/where2.c +57 -20
- data/ext/cumo/narray/gen/tmpl_bit/where_kernel.cu +6 -6
- data/ext/cumo/narray/index.c +83 -26
- data/ext/cumo/narray/index_kernel.cu +15 -0
- data/ext/cumo/narray/math.c +2 -0
- data/ext/cumo/narray/narray.c +421 -178
- data/ext/cumo/narray/ndloop.c +158 -26
- data/ext/cumo/narray/sort_kernel.cu +39 -18
- data/ext/cumo/narray/struct.c +14 -17
- data/lib/cumo/cuda/cudnn.rb +1 -1
- data/lib/cumo/narray/extra.rb +130 -26
- data/test/bit_test.rb +290 -0
- data/test/cudnn_test.rb +208 -34
- data/test/cumo_test.rb +1 -0
- data/test/extra_test.rb +75 -7
- data/test/hfloat_test.rb +717 -0
- data/test/math_test.rb +4 -1
- data/test/narray_alt_coverage_test.rb +7 -0
- data/test/narray_test.rb +1865 -10
- data/test/test_helper.rb +73 -0
- metadata +15 -1
|
@@ -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
|
-
|
|
24
|
-
|
|
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;
|
|
@@ -60,14 +48,14 @@ static VALUE
|
|
|
60
48
|
|
|
61
49
|
rb_scan_args(argc, argv, "2:", &gamma, &beta, &kw_hash);
|
|
62
50
|
rb_get_kwargs(kw_hash, kw_table, 0, 8, opts);
|
|
63
|
-
running_mean =
|
|
64
|
-
running_var =
|
|
65
|
-
mean =
|
|
66
|
-
inv_std =
|
|
67
|
-
eps =
|
|
68
|
-
decay =
|
|
69
|
-
axis =
|
|
70
|
-
y =
|
|
51
|
+
running_mean = cumo_option_value(opts[0], Qnil);
|
|
52
|
+
running_var = cumo_option_value(opts[1], Qnil);
|
|
53
|
+
mean = cumo_option_value(opts[2], Qnil);
|
|
54
|
+
inv_std = cumo_option_value(opts[3], Qnil);
|
|
55
|
+
eps = cumo_option_value(opts[4], Qnil);
|
|
56
|
+
decay = cumo_option_value(opts[5], Qnil);
|
|
57
|
+
axis = cumo_option_value(opts[6], Qnil);
|
|
58
|
+
y = cumo_option_value(opts[7], Qnil);
|
|
71
59
|
|
|
72
60
|
if (running_mean != Qnil) {
|
|
73
61
|
running_mean_ptr = cumo_na_get_offset_pointer_for_write(running_mean);
|
|
@@ -93,6 +81,7 @@ static VALUE
|
|
|
93
81
|
|
|
94
82
|
CumoGetNArray(x, nx);
|
|
95
83
|
x_ndim = nx->ndim;
|
|
84
|
+
cumo_cuda_cudnn_check_axis(axis_ndim, int_axis, x_ndim);
|
|
96
85
|
x_shape = nx->shape;
|
|
97
86
|
|
|
98
87
|
{
|
|
@@ -103,34 +92,34 @@ static VALUE
|
|
|
103
92
|
cumo_cuda_cudnn_check_reduced_size(reduced_total_size, x_ndim, x_shape);
|
|
104
93
|
|
|
105
94
|
CumoGetNArray(gamma, ngamma);
|
|
106
|
-
|
|
95
|
+
CUMO_CHECK_SIZE_EQ(ngamma->size, reduced_total_size);
|
|
107
96
|
CumoGetNArray(beta, nbeta);
|
|
108
|
-
|
|
97
|
+
CUMO_CHECK_SIZE_EQ(nbeta->size, reduced_total_size);
|
|
109
98
|
if (running_mean != Qnil) {
|
|
110
99
|
CumoGetNArray(running_mean, nrunning_mean);
|
|
111
|
-
|
|
100
|
+
CUMO_CHECK_SIZE_EQ(nrunning_mean->size, reduced_total_size);
|
|
112
101
|
}
|
|
113
102
|
if (running_var != Qnil) {
|
|
114
103
|
CumoGetNArray(running_var, nrunning_var);
|
|
115
|
-
|
|
104
|
+
CUMO_CHECK_SIZE_EQ(nrunning_var->size, reduced_total_size);
|
|
116
105
|
}
|
|
117
106
|
if (mean != Qnil) {
|
|
118
107
|
CumoGetNArray(mean, nmean);
|
|
119
|
-
|
|
108
|
+
CUMO_CHECK_SIZE_EQ(nmean->size, reduced_total_size);
|
|
120
109
|
}
|
|
121
110
|
if (inv_std != Qnil) {
|
|
122
111
|
CumoGetNArray(inv_std, ninv_std);
|
|
123
|
-
|
|
112
|
+
CUMO_CHECK_SIZE_EQ(ninv_std->size, reduced_total_size);
|
|
124
113
|
}
|
|
125
114
|
}
|
|
126
115
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (running_mean != Qnil)
|
|
131
|
-
if (running_var != Qnil)
|
|
132
|
-
if (mean != Qnil)
|
|
133
|
-
if (inv_std != Qnil)
|
|
116
|
+
CUMO_CHECK_NARRAY_TYPE(x, 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");
|
|
134
123
|
|
|
135
124
|
x_cont = cumo_na_as_contiguous_array(x);
|
|
136
125
|
gamma_cont = cumo_na_as_contiguous_array(gamma);
|
|
@@ -165,7 +154,9 @@ static VALUE
|
|
|
165
154
|
mode = cumo_cuda_cudnn_GetBatchNormMode(axis_ndim, int_axis);
|
|
166
155
|
status = cumo_cuda_cudnn_CreateBNTensorDescriptor(&bn_desc, x_desc, mode);
|
|
167
156
|
if (status != CUDNN_STATUS_SUCCESS) goto BATCH_NORM_ERROR;
|
|
168
|
-
//
|
|
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.
|
|
169
160
|
|
|
170
161
|
handle = cumo_cuda_cudnn_handle();
|
|
171
162
|
|
|
@@ -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
|
// gx, ggamma, gbeta = x.batch_norm_backward(gamma, gy, mean:, inv_std:, eps:, axis:)
|
|
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
|
-
|
|
24
|
-
|
|
11
|
+
<%=cudnn_scalar_t%> coef_one = 1;
|
|
12
|
+
<%=cudnn_scalar_t%> coef_zero = 0;
|
|
25
13
|
|
|
26
14
|
VALUE x=self, gamma, gy, mean, inv_std, eps, axis, gx, ggamma, gbeta;
|
|
27
15
|
VALUE kw_hash = Qnil;
|
|
@@ -56,13 +44,13 @@ static VALUE
|
|
|
56
44
|
|
|
57
45
|
rb_scan_args(argc, argv, "2:", &gamma, &gy, &kw_hash);
|
|
58
46
|
rb_get_kwargs(kw_hash, kw_table, 0, 7, opts);
|
|
59
|
-
mean =
|
|
60
|
-
inv_std =
|
|
61
|
-
eps =
|
|
62
|
-
axis =
|
|
63
|
-
gx =
|
|
64
|
-
ggamma =
|
|
65
|
-
gbeta =
|
|
47
|
+
mean = cumo_option_value(opts[0], Qnil);
|
|
48
|
+
inv_std = cumo_option_value(opts[1], Qnil);
|
|
49
|
+
eps = cumo_option_value(opts[2], Qnil);
|
|
50
|
+
axis = cumo_option_value(opts[3], Qnil);
|
|
51
|
+
gx = cumo_option_value(opts[4], Qnil);
|
|
52
|
+
ggamma = cumo_option_value(opts[5], Qnil);
|
|
53
|
+
gbeta = cumo_option_value(opts[6], Qnil);
|
|
66
54
|
|
|
67
55
|
if (mean != Qnil) {
|
|
68
56
|
mean_ptr = cumo_na_get_offset_pointer_for_read(mean);
|
|
@@ -80,6 +68,7 @@ static VALUE
|
|
|
80
68
|
CumoGetNArray(x, nx);
|
|
81
69
|
CumoGetNArray(gamma, ngamma);
|
|
82
70
|
x_ndim = nx->ndim;
|
|
71
|
+
cumo_cuda_cudnn_check_axis(axis_ndim, int_axis, x_ndim);
|
|
83
72
|
x_shape = nx->shape;
|
|
84
73
|
gamma_ndim = ngamma->ndim;
|
|
85
74
|
gamma_shape = ngamma->shape;
|
|
@@ -92,24 +81,24 @@ static VALUE
|
|
|
92
81
|
cumo_cuda_cudnn_check_reduced_size(reduced_total_size, x_ndim, x_shape);
|
|
93
82
|
|
|
94
83
|
CumoGetNArray(gy, ngy);
|
|
95
|
-
|
|
84
|
+
CUMO_CHECK_SIZE_EQ(nx->size, ngy->size);
|
|
96
85
|
|
|
97
|
-
|
|
86
|
+
CUMO_CHECK_SIZE_EQ(ngamma->size, reduced_total_size);
|
|
98
87
|
if (mean != Qnil) {
|
|
99
88
|
CumoGetNArray(mean, nmean);
|
|
100
|
-
|
|
89
|
+
CUMO_CHECK_SIZE_EQ(nmean->size, reduced_total_size);
|
|
101
90
|
}
|
|
102
91
|
if (inv_std != Qnil) {
|
|
103
92
|
CumoGetNArray(inv_std, ninv_std);
|
|
104
|
-
|
|
93
|
+
CUMO_CHECK_SIZE_EQ(ninv_std->size, reduced_total_size);
|
|
105
94
|
}
|
|
106
95
|
}
|
|
107
96
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (mean != Qnil)
|
|
112
|
-
if (inv_std != Qnil)
|
|
97
|
+
CUMO_CHECK_NARRAY_TYPE(x, cT);
|
|
98
|
+
cumo_cuda_cudnn_check_param_type(gamma, <%=cudnn_param_class%>, "gamma");
|
|
99
|
+
CUMO_CHECK_NARRAY_TYPE(gy, cT);
|
|
100
|
+
if (mean != Qnil) cumo_cuda_cudnn_check_param_type(mean, <%=cudnn_param_class%>, "mean");
|
|
101
|
+
if (inv_std != Qnil) cumo_cuda_cudnn_check_param_type(inv_std, <%=cudnn_param_class%>, "inv_std");
|
|
113
102
|
|
|
114
103
|
x_cont = cumo_na_as_contiguous_array(x);
|
|
115
104
|
gamma_cont = cumo_na_as_contiguous_array(gamma);
|
|
@@ -132,15 +121,15 @@ static VALUE
|
|
|
132
121
|
}
|
|
133
122
|
gx_ptr = cumo_na_get_offset_pointer_for_write(gx);
|
|
134
123
|
if (ggamma == Qnil) {
|
|
135
|
-
ggamma = cumo_na_new(
|
|
124
|
+
ggamma = cumo_na_new(<%=cudnn_param_class%>, gamma_ndim, gamma_shape);
|
|
136
125
|
} else {
|
|
137
|
-
cumo_cuda_cudnn_check_output(ggamma,
|
|
126
|
+
cumo_cuda_cudnn_check_output(ggamma, <%=cudnn_param_class%>, gamma_ndim, gamma_shape);
|
|
138
127
|
}
|
|
139
128
|
ggamma_ptr = cumo_na_get_offset_pointer_for_write(ggamma);
|
|
140
129
|
if (gbeta == Qnil) {
|
|
141
|
-
gbeta = cumo_na_new(
|
|
130
|
+
gbeta = cumo_na_new(<%=cudnn_param_class%>, gamma_ndim, gamma_shape);
|
|
142
131
|
} else {
|
|
143
|
-
cumo_cuda_cudnn_check_output(gbeta,
|
|
132
|
+
cumo_cuda_cudnn_check_output(gbeta, <%=cudnn_param_class%>, gamma_ndim, gamma_shape);
|
|
144
133
|
}
|
|
145
134
|
gbeta_ptr = cumo_na_get_offset_pointer_for_write(gbeta);
|
|
146
135
|
|
|
@@ -150,7 +139,9 @@ static VALUE
|
|
|
150
139
|
mode = cumo_cuda_cudnn_GetBatchNormMode(axis_ndim, int_axis);
|
|
151
140
|
status = cumo_cuda_cudnn_CreateBNTensorDescriptor(&bn_desc, x_desc, mode);
|
|
152
141
|
if (status != CUDNN_STATUS_SUCCESS) goto BATCH_NORM_BACKWARD_ERROR;
|
|
153
|
-
//
|
|
142
|
+
// cuDNN derives the parameter descriptor as float for a half x and as x's
|
|
143
|
+
// own type otherwise, and the checks above hold every parameter to exactly
|
|
144
|
+
// that class, so none of them needs a cast.
|
|
154
145
|
|
|
155
146
|
handle = cumo_cuda_cudnn_handle();
|
|
156
147
|
|
|
@@ -196,7 +196,7 @@ static VALUE
|
|
|
196
196
|
dtype x = m_num_to_data(num);
|
|
197
197
|
cumo_ndfunc_arg_in_t ain_s[1] = {{cT,0}};
|
|
198
198
|
cumo_ndfunc_arg_out_t aout_s[1] = {{cT,0}};
|
|
199
|
-
cumo_ndfunc_t ndf_s = { <%=c_iter%>_s_left, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP, 1, 1, ain_s, aout_s };
|
|
199
|
+
cumo_ndfunc_t ndf_s = { <%=c_iter%>_s_left, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP|CUMO_NDF_ANY_ORDER, 1, 1, ain_s, aout_s };
|
|
200
200
|
return cumo_na_ndloop3(&ndf_s, &x, 1, other);
|
|
201
201
|
}
|
|
202
202
|
}
|
|
@@ -204,7 +204,7 @@ static VALUE
|
|
|
204
204
|
dtype y = m_num_to_data(other);
|
|
205
205
|
cumo_ndfunc_arg_in_t ain_s[1] = {{cT,0}};
|
|
206
206
|
cumo_ndfunc_arg_out_t aout_s[1] = {{cT,0}};
|
|
207
|
-
cumo_ndfunc_t ndf_s = { <%=c_iter%>_s, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP, 1, 1, ain_s, aout_s };
|
|
207
|
+
cumo_ndfunc_t ndf_s = { <%=c_iter%>_s, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP|CUMO_NDF_ANY_ORDER, 1, 1, ain_s, aout_s };
|
|
208
208
|
return cumo_na_ndloop3(&ndf_s, &y, 1, self);
|
|
209
209
|
}
|
|
210
210
|
//<% end %>
|
|
@@ -213,7 +213,7 @@ static VALUE
|
|
|
213
213
|
<% if type_name == 'robject' %>
|
|
214
214
|
cumo_ndfunc_t ndf = { <%=c_iter%>, CUMO_STRIDE_LOOP, 2, 1, ain, aout };
|
|
215
215
|
<% else %>
|
|
216
|
-
cumo_ndfunc_t ndf = { <%=c_iter%>, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP, 2, 1, ain, aout };
|
|
216
|
+
cumo_ndfunc_t ndf = { <%=c_iter%>, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP|CUMO_NDF_ANY_ORDER, 2, 1, ain, aout };
|
|
217
217
|
<% end %>
|
|
218
218
|
|
|
219
219
|
return cumo_na_ndloop(&ndf, 2, self, other);
|
|
@@ -62,7 +62,7 @@ static VALUE
|
|
|
62
62
|
<% if type_name == 'robject' %>
|
|
63
63
|
cumo_ndfunc_t ndf = { <%=c_iter%>, CUMO_STRIDE_LOOP, 2, 2, ain, aout };
|
|
64
64
|
<% else %>
|
|
65
|
-
cumo_ndfunc_t ndf = { <%=c_iter%>, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP, 2, 2, ain, aout };
|
|
65
|
+
cumo_ndfunc_t ndf = { <%=c_iter%>, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP|CUMO_NDF_ANY_ORDER, 2, 2, ain, aout };
|
|
66
66
|
<% end %>
|
|
67
67
|
|
|
68
68
|
return cumo_na_ndloop(&ndf, 2, self, other);
|
|
@@ -48,6 +48,64 @@ __global__ void <%="cumo_#{c_iter}_kernel_dim#{idim}"%>(cumo_na_iarray_t a1, cum
|
|
|
48
48
|
//<% end %>
|
|
49
49
|
<% end %>
|
|
50
50
|
|
|
51
|
+
// One operand of a 2-d elementwise op can be a transposed view, which leaves
|
|
52
|
+
// either its read or the write strided whichever way the loop walks. Stage that
|
|
53
|
+
// operand through a shared memory tile so all three arrays are touched in rows.
|
|
54
|
+
// t_side says which operand is the transposed one.
|
|
55
|
+
__global__ void <%="cumo_#{c_iter}_transpose_kernel"%>(char *p1, char *p2, char *p3, int* divzero, int t_side, uint64_t rows, uint64_t cols)
|
|
56
|
+
{
|
|
57
|
+
CUMO_TRANSPOSE_TILE_DECL(dtype, tile);
|
|
58
|
+
char *tp = (t_side == 1) ? p1 : p2;
|
|
59
|
+
char *sp = (t_side == 1) ? p2 : p1;
|
|
60
|
+
|
|
61
|
+
CUMO_TRANSPOSE_TILE_LOOP(tile, rows, cols,
|
|
62
|
+
*(dtype*)(tp + cumo_tile_src * sizeof(dtype)),
|
|
63
|
+
dtype o = *(dtype*)(sp + cumo_tile_dst * sizeof(dtype));
|
|
64
|
+
dtype lhs = (t_side == 1) ? cumo_tile_val : o;
|
|
65
|
+
dtype rhs = (t_side == 1) ? o : cumo_tile_val;
|
|
66
|
+
cumo_check_intdivzero(rhs);
|
|
67
|
+
*(dtype*)(p3 + cumo_tile_dst * sizeof(dtype)) = m_<%=name%>(lhs, rhs);
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Launches the tiled kernel and answers 1 when it did. It takes over when one
|
|
72
|
+
// operand is a transposed plain array and the other two are row-major ones, and
|
|
73
|
+
// only once both sides reach a tile: a shorter one leaves most of each warp idle
|
|
74
|
+
// while the plain loop already reads or writes it in one go.
|
|
75
|
+
static int
|
|
76
|
+
<%="cumo_#{c_iter}_launch_transpose"%>(cumo_na_iarray_t* a1, cumo_na_iarray_t* a2, cumo_na_iarray_t* a3, cumo_na_indexer_t* indexer, int* divzero)
|
|
77
|
+
{
|
|
78
|
+
ssize_t esz = (ssize_t)sizeof(dtype);
|
|
79
|
+
uint64_t rows, cols;
|
|
80
|
+
ssize_t row, col;
|
|
81
|
+
int rows_a1, rows_a2, t_side;
|
|
82
|
+
|
|
83
|
+
if (!CUMO_TRANSPOSE_TILE_FITS(indexer)) {
|
|
84
|
+
return 0;
|
|
85
|
+
}
|
|
86
|
+
rows = indexer->shape[0];
|
|
87
|
+
cols = indexer->shape[1];
|
|
88
|
+
row = esz * (ssize_t)cols;
|
|
89
|
+
col = esz * (ssize_t)rows;
|
|
90
|
+
if (a3->step[0] != row || a3->step[1] != esz) {
|
|
91
|
+
return 0;
|
|
92
|
+
}
|
|
93
|
+
rows_a1 = (a1->step[0] == row && a1->step[1] == esz);
|
|
94
|
+
rows_a2 = (a2->step[0] == row && a2->step[1] == esz);
|
|
95
|
+
if (!rows_a2 && rows_a1 && a2->step[0] == esz && a2->step[1] == col) {
|
|
96
|
+
t_side = 2;
|
|
97
|
+
} else if (!rows_a1 && rows_a2 && a1->step[0] == esz && a1->step[1] == col) {
|
|
98
|
+
t_side = 1;
|
|
99
|
+
} else {
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
CUMO_TRANSPOSE_LAUNCH(<%="cumo_#{c_iter}_transpose_kernel"%>, rows, cols,
|
|
104
|
+
a1->ptr, a2->ptr, a3->ptr, divzero, t_side);
|
|
105
|
+
cumo_cuda_runtime_check_kernel_launch();
|
|
106
|
+
return 1;
|
|
107
|
+
}
|
|
108
|
+
|
|
51
109
|
//<% if has_scalar %>
|
|
52
110
|
static void <%="cumo_#{c_iter}_kernel_dispatch"%>(cumo_na_iarray_t* a1, cumo_na_iarray_t* a2, cumo_na_iarray_t* a3, cumo_na_indexer_t* indexer, int* divzero, dtype sv, int use_scalar)
|
|
53
111
|
{
|
|
@@ -69,6 +127,10 @@ static void <%="cumo_#{c_iter}_kernel_dispatch"%>(cumo_na_iarray_t* a1, cumo_na_
|
|
|
69
127
|
void <%="cumo_#{c_iter}_kernel_launch"%>(cumo_na_iarray_t* a1, cumo_na_iarray_t* a2, cumo_na_iarray_t* a3, cumo_na_indexer_t* indexer, int* divzero)
|
|
70
128
|
{
|
|
71
129
|
dtype sv;
|
|
130
|
+
|
|
131
|
+
if (<%="cumo_#{c_iter}_launch_transpose"%>(a1,a2,a3,indexer,divzero)) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
72
134
|
memset(&sv, 0, sizeof(dtype));
|
|
73
135
|
<%="cumo_#{c_iter}_kernel_dispatch"%>(a1,a2,a3,indexer,divzero,sv,0);
|
|
74
136
|
}
|
|
@@ -82,8 +144,13 @@ void <%="cumo_#{c_iter}_s_kernel_launch"%>(cumo_na_iarray_t* a1, dtype sv, cumo_
|
|
|
82
144
|
//<% else %>
|
|
83
145
|
void <%="cumo_#{c_iter}_kernel_launch"%>(cumo_na_iarray_t* a1, cumo_na_iarray_t* a2, cumo_na_iarray_t* a3, cumo_na_indexer_t* indexer, int* divzero)
|
|
84
146
|
{
|
|
85
|
-
size_t grid_dim
|
|
86
|
-
|
|
147
|
+
size_t grid_dim, block_dim;
|
|
148
|
+
|
|
149
|
+
if (<%="cumo_#{c_iter}_launch_transpose"%>(a1,a2,a3,indexer,divzero)) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
grid_dim = cumo_get_grid_dim(indexer->total_size);
|
|
153
|
+
block_dim = cumo_get_block_dim(indexer->total_size);
|
|
87
154
|
switch (indexer->ndim) {
|
|
88
155
|
<% (0..opt_indexer_ndim).each do |idim| %>
|
|
89
156
|
case <%=idim%>:
|
|
@@ -79,7 +79,7 @@ static VALUE
|
|
|
79
79
|
<% if type_name == 'robject' %>
|
|
80
80
|
cumo_ndfunc_t ndf = { <%=c_iter%>, CUMO_STRIDE_LOOP, 2, 1, ain, aout };
|
|
81
81
|
<% else %>
|
|
82
|
-
cumo_ndfunc_t ndf = { <%=c_iter%>, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP, 2, 1, ain, aout };
|
|
82
|
+
cumo_ndfunc_t ndf = { <%=c_iter%>, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP|CUMO_NDF_ANY_ORDER, 2, 1, ain, aout };
|
|
83
83
|
|
|
84
84
|
{
|
|
85
85
|
cumo_ndfunc_arg_in_t ain_s[1] = {{cT,0}};
|
|
@@ -88,12 +88,12 @@ static VALUE
|
|
|
88
88
|
|
|
89
89
|
if (!n1 && n2) {
|
|
90
90
|
dtype sv = m_num_to_data(a2);
|
|
91
|
-
cumo_ndfunc_t ndf_s = { <%=c_iter%>_s, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP, 1, 1, ain_s, aout };
|
|
91
|
+
cumo_ndfunc_t ndf_s = { <%=c_iter%>_s, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP|CUMO_NDF_ANY_ORDER, 1, 1, ain_s, aout };
|
|
92
92
|
return cumo_na_ndloop3(&ndf_s, &sv, 1, a1);
|
|
93
93
|
}
|
|
94
94
|
if (n1 && !n2) {
|
|
95
95
|
dtype sv = m_num_to_data(a1);
|
|
96
|
-
cumo_ndfunc_t ndf_s = { <%=c_iter%>_s_left, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP, 1, 1, ain_s, aout };
|
|
96
|
+
cumo_ndfunc_t ndf_s = { <%=c_iter%>_s_left, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP|CUMO_NDF_ANY_ORDER, 1, 1, ain_s, aout };
|
|
97
97
|
return cumo_na_ndloop3(&ndf_s, &sv, 1, a2);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
@@ -24,7 +24,7 @@ static void
|
|
|
24
24
|
CUMO_INIT_PTR(lp, 3, p4, s4);
|
|
25
25
|
|
|
26
26
|
CUMO_SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%>", "<%=type_name%>");
|
|
27
|
-
|
|
27
|
+
cumo_cuda_runtime_device_synchronize();
|
|
28
28
|
for (i=n; i--;) {
|
|
29
29
|
CUMO_GET_DATA_STRIDE(p1,s1,dtype,x);
|
|
30
30
|
CUMO_GET_DATA_STRIDE(p2,s2,dtype,min);
|
|
@@ -69,7 +69,7 @@ static void
|
|
|
69
69
|
CUMO_INIT_PTR(lp, 2, p3, s3);
|
|
70
70
|
|
|
71
71
|
CUMO_SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%>_min", "<%=type_name%>");
|
|
72
|
-
|
|
72
|
+
cumo_cuda_runtime_device_synchronize();
|
|
73
73
|
for (i=n; i--;) {
|
|
74
74
|
CUMO_GET_DATA_STRIDE(p1,s1,dtype,x);
|
|
75
75
|
CUMO_GET_DATA_STRIDE(p2,s2,dtype,min);
|
|
@@ -105,7 +105,7 @@ static void
|
|
|
105
105
|
CUMO_INIT_PTR(lp, 2, p3, s3);
|
|
106
106
|
|
|
107
107
|
CUMO_SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%>_max", "<%=type_name%>");
|
|
108
|
-
|
|
108
|
+
cumo_cuda_runtime_device_synchronize();
|
|
109
109
|
for (i=n; i--;) {
|
|
110
110
|
CUMO_GET_DATA_STRIDE(p1,s1,dtype,x);
|
|
111
111
|
CUMO_GET_DATA_STRIDE(p2,s2,dtype,max);
|
|
@@ -204,9 +204,9 @@ static VALUE
|
|
|
204
204
|
cumo_ndfunc_t ndf_max = { <%=c_iter%>_max, CUMO_STRIDE_LOOP, 2, 1, ain, aout };
|
|
205
205
|
cumo_ndfunc_t ndf_both = { <%=c_iter%>, CUMO_STRIDE_LOOP, 3, 1, ain, aout };
|
|
206
206
|
<% else %>
|
|
207
|
-
cumo_ndfunc_t ndf_min = { <%=c_iter%>_min, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP, 2, 1, ain, aout };
|
|
208
|
-
cumo_ndfunc_t ndf_max = { <%=c_iter%>_max, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP, 2, 1, ain, aout };
|
|
209
|
-
cumo_ndfunc_t ndf_both = { <%=c_iter%>, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP, 3, 1, ain, aout };
|
|
207
|
+
cumo_ndfunc_t ndf_min = { <%=c_iter%>_min, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP|CUMO_NDF_ANY_ORDER, 2, 1, ain, aout };
|
|
208
|
+
cumo_ndfunc_t ndf_max = { <%=c_iter%>_max, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP|CUMO_NDF_ANY_ORDER, 2, 1, ain, aout };
|
|
209
|
+
cumo_ndfunc_t ndf_both = { <%=c_iter%>, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP|CUMO_NDF_ANY_ORDER, 3, 1, ain, aout };
|
|
210
210
|
|
|
211
211
|
{
|
|
212
212
|
cumo_ndfunc_arg_in_t ain_s[1] = {{Qnil,0}};
|
|
@@ -215,7 +215,7 @@ static VALUE
|
|
|
215
215
|
|
|
216
216
|
if (min_s && max_s) {
|
|
217
217
|
dtype sv[2];
|
|
218
|
-
cumo_ndfunc_t ndf_s = { <%=c_iter%>_s, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP, 1, 1, ain_s, aout };
|
|
218
|
+
cumo_ndfunc_t ndf_s = { <%=c_iter%>_s, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP|CUMO_NDF_ANY_ORDER, 1, 1, ain_s, aout };
|
|
219
219
|
sv[0] = m_num_to_data(min);
|
|
220
220
|
sv[1] = m_num_to_data(max);
|
|
221
221
|
if (m_gt(sv[0],sv[1])) {rb_raise(cumo_na_eOperationError,"min is greater than max");}
|
|
@@ -223,12 +223,12 @@ static VALUE
|
|
|
223
223
|
}
|
|
224
224
|
if (min_s && !RTEST(max)) {
|
|
225
225
|
dtype sv = m_num_to_data(min);
|
|
226
|
-
cumo_ndfunc_t ndf_min_s = { <%=c_iter%>_min_s, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP, 1, 1, ain_s, aout };
|
|
226
|
+
cumo_ndfunc_t ndf_min_s = { <%=c_iter%>_min_s, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP|CUMO_NDF_ANY_ORDER, 1, 1, ain_s, aout };
|
|
227
227
|
return cumo_na_ndloop3(&ndf_min_s, &sv, 1, self);
|
|
228
228
|
}
|
|
229
229
|
if (max_s && !RTEST(min)) {
|
|
230
230
|
dtype sv = m_num_to_data(max);
|
|
231
|
-
cumo_ndfunc_t ndf_max_s = { <%=c_iter%>_max_s, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP, 1, 1, ain_s, aout };
|
|
231
|
+
cumo_ndfunc_t ndf_max_s = { <%=c_iter%>_max_s, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP|CUMO_NDF_ANY_ORDER, 1, 1, ain_s, aout };
|
|
232
232
|
return cumo_na_ndloop3(&ndf_max_s, &sv, 1, self);
|
|
233
233
|
}
|
|
234
234
|
}
|
|
@@ -76,7 +76,7 @@ static VALUE
|
|
|
76
76
|
<% if type_name == 'robject' %>
|
|
77
77
|
cumo_ndfunc_t ndf = { <%=c_iter%>, CUMO_STRIDE_LOOP, 2, 1, ain, aout };
|
|
78
78
|
<% else %>
|
|
79
|
-
cumo_ndfunc_t ndf = { <%=c_iter%>, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP, 2, 1, ain, aout };
|
|
79
|
+
cumo_ndfunc_t ndf = { <%=c_iter%>, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP|CUMO_NDF_ANY_ORDER, 2, 1, ain, aout };
|
|
80
80
|
|
|
81
81
|
{
|
|
82
82
|
// coerce hands a numeric on the left over as a 0-dimensional array that
|
|
@@ -92,14 +92,14 @@ static VALUE
|
|
|
92
92
|
if (!NIL_P(num) && CumoIsNArray(other)) {
|
|
93
93
|
dtype sv = m_num_to_data(num);
|
|
94
94
|
cumo_ndfunc_arg_in_t ain_s[1] = {{cT,0}};
|
|
95
|
-
cumo_ndfunc_t ndf_s = { <%=c_iter%>_s_left, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP, 1, 1, ain_s, aout };
|
|
95
|
+
cumo_ndfunc_t ndf_s = { <%=c_iter%>_s_left, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP|CUMO_NDF_ANY_ORDER, 1, 1, ain_s, aout };
|
|
96
96
|
return cumo_na_ndloop3(&ndf_s, &sv, 1, other);
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
|
100
100
|
dtype sv = m_num_to_data(other);
|
|
101
101
|
cumo_ndfunc_arg_in_t ain_s[1] = {{cT,0}};
|
|
102
|
-
cumo_ndfunc_t ndf_s = { <%=c_iter%>_s, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP, 1, 1, ain_s, aout };
|
|
102
|
+
cumo_ndfunc_t ndf_s = { <%=c_iter%>_s, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP|CUMO_NDF_ANY_ORDER, 1, 1, ain_s, aout };
|
|
103
103
|
return cumo_na_ndloop3(&ndf_s, &sv, 1, self);
|
|
104
104
|
}
|
|
105
105
|
<% end %>
|
|
@@ -20,7 +20,7 @@ static void
|
|
|
20
20
|
CUMO_INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
21
21
|
CUMO_INIT_PTR_BIT(lp, 1, a2, p2, s2);
|
|
22
22
|
CUMO_SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%>", "<%=type_name%>");
|
|
23
|
-
|
|
23
|
+
cumo_cuda_runtime_device_synchronize();
|
|
24
24
|
if (idx1) {
|
|
25
25
|
for (i=0; i<n; i++) {
|
|
26
26
|
CUMO_GET_DATA_INDEX(p1,idx1,dtype,x);
|
|
@@ -61,7 +61,7 @@ static VALUE
|
|
|
61
61
|
<% if type_name == 'robject' %>
|
|
62
62
|
cumo_ndfunc_t ndf = { <%=c_iter%>, CUMO_FULL_LOOP, 1, 1, ain, aout };
|
|
63
63
|
<% else %>
|
|
64
|
-
cumo_ndfunc_t ndf = { <%=c_iter%>, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP, 1, 1, ain, aout };
|
|
64
|
+
cumo_ndfunc_t ndf = { <%=c_iter%>, CUMO_STRIDE_LOOP|CUMO_NDF_INDEXER_LOOP|CUMO_NDF_ANY_ORDER, 1, 1, ain, aout };
|
|
65
65
|
<% end %>
|
|
66
66
|
|
|
67
67
|
return cumo_na_ndloop(&ndf, 1, self);
|
|
@@ -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
|
// cover_all=true is not supported with CUDNN
|
|
17
5
|
// dilation > 1 is not supported yet
|
|
@@ -22,8 +10,8 @@ static VALUE
|
|
|
22
10
|
cudnnDataType_t cudnn_dtype = <%= cudnn_dtype %>;
|
|
23
11
|
cudnnStatus_t status = 0;
|
|
24
12
|
cudnnHandle_t handle = 0;
|
|
25
|
-
|
|
26
|
-
|
|
13
|
+
<%=cudnn_scalar_t%> alpha = 1;
|
|
14
|
+
<%=cudnn_scalar_t%> beta = 0;
|
|
27
15
|
|
|
28
16
|
VALUE x=self, w, b, stride, pad, y;
|
|
29
17
|
VALUE kw_hash = Qnil;
|
|
@@ -45,7 +33,7 @@ static VALUE
|
|
|
45
33
|
|
|
46
34
|
cudnnConvolutionFwdAlgoPerf_t perf_result;
|
|
47
35
|
cudnnConvolutionFwdAlgo_t algo;
|
|
48
|
-
size_t max_workspace_size =
|
|
36
|
+
size_t max_workspace_size = cumo_cuda_cudnn_max_workspace_size();
|
|
49
37
|
size_t workspace_size;
|
|
50
38
|
char* workspace = 0;
|
|
51
39
|
|
|
@@ -54,17 +42,17 @@ static VALUE
|
|
|
54
42
|
|
|
55
43
|
rb_scan_args(argc, argv, "1:", &w, &kw_hash);
|
|
56
44
|
rb_get_kwargs(kw_hash, kw_table, 0, 4, opts);
|
|
57
|
-
stride =
|
|
58
|
-
pad =
|
|
59
|
-
b =
|
|
60
|
-
y =
|
|
45
|
+
stride = cumo_option_value(opts[0], Qnil);
|
|
46
|
+
pad = cumo_option_value(opts[1], Qnil);
|
|
47
|
+
b = cumo_option_value(opts[2], Qnil);
|
|
48
|
+
y = cumo_option_value(opts[3], Qnil);
|
|
61
49
|
|
|
62
50
|
CumoGetNArray(x, nx);
|
|
63
51
|
CumoGetNArray(w, nw);
|
|
64
52
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
53
|
+
CUMO_CHECK_DIM_EQ(nx->ndim, nw->ndim);
|
|
54
|
+
CUMO_CHECK_NARRAY_TYPE(x, cT);
|
|
55
|
+
CUMO_CHECK_NARRAY_TYPE(w, cT);
|
|
68
56
|
if (nx->ndim - 2 < 2) {
|
|
69
57
|
rb_raise(cumo_na_eShapeError, "CUDNN convolution requires number of spatial "
|
|
70
58
|
"dimensions to be greater than or equal to 2, but %d", nx->ndim - 2);
|
|
@@ -113,7 +101,7 @@ static VALUE
|
|
|
113
101
|
if (status != CUDNN_STATUS_SUCCESS) goto CONV_ERROR;
|
|
114
102
|
status = cumo_cuda_cudnn_CreateFilterDescriptor(&w_desc, w_cont, cudnn_dtype);
|
|
115
103
|
if (status != CUDNN_STATUS_SUCCESS) goto CONV_ERROR;
|
|
116
|
-
status = cumo_cuda_cudnn_CreateConvolutionDescriptor(&conv_desc, ndim, int_stride, int_pad,
|
|
104
|
+
status = cumo_cuda_cudnn_CreateConvolutionDescriptor(&conv_desc, ndim, int_stride, int_pad, <%=cudnn_compute_dtype%>, <%=cudnn_math_type%>);
|
|
117
105
|
if (status != CUDNN_STATUS_SUCCESS) goto CONV_ERROR;
|
|
118
106
|
|
|
119
107
|
handle = cumo_cuda_cudnn_handle();
|
|
@@ -135,10 +123,16 @@ static VALUE
|
|
|
135
123
|
ndim,
|
|
136
124
|
cudnn_dtype);
|
|
137
125
|
if (status != CUDNN_STATUS_SUCCESS) goto CONV_ERROR;
|
|
126
|
+
// The descriptor asked for a math type; use the one the search settled on.
|
|
127
|
+
status = cudnnSetConvolutionMathType(conv_desc, perf_result.mathType);
|
|
128
|
+
if (status != CUDNN_STATUS_SUCCESS) goto CONV_ERROR;
|
|
129
|
+
|
|
138
130
|
algo = perf_result.algo;
|
|
139
131
|
workspace_size = perf_result.memory;
|
|
140
132
|
|
|
141
|
-
|
|
133
|
+
// The search may look at algorithms needing up to max_workspace_size,
|
|
134
|
+
// but only the one it picked has to be paid for.
|
|
135
|
+
if (workspace_size > 0) workspace = cumo_cuda_runtime_malloc(workspace_size);
|
|
142
136
|
status = cudnnConvolutionForward(
|
|
143
137
|
handle,
|
|
144
138
|
(void*)&alpha,
|
|
@@ -163,7 +157,7 @@ static VALUE
|
|
|
163
157
|
size_t *b_shape;
|
|
164
158
|
int b_ndim;
|
|
165
159
|
|
|
166
|
-
|
|
160
|
+
CUMO_CHECK_NARRAY_TYPE(b, cT);
|
|
167
161
|
CumoGetNArray(b, nb);
|
|
168
162
|
new_shape[0] = 1;
|
|
169
163
|
new_shape[1] = nb->size;
|