cumo 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/3rd_party/LICENSE.txt +60 -0
- data/3rd_party/mkmf-cu/lib/mkmf-cu/cli.rb +13 -1
- data/LICENSE.txt +1 -62
- data/README.md +33 -29
- data/bench/cumo_bench.rb +47 -25
- data/bench/numo_bench.rb +27 -25
- data/docs/src-tree.md +16 -0
- data/ext/cumo/cuda/cublas.c +69 -219
- data/ext/cumo/cuda/memory_pool_impl.hpp +1 -0
- data/ext/cumo/cuda/runtime.c +2 -14
- data/ext/cumo/cumo.c +16 -16
- data/ext/cumo/include/cumo.h +2 -2
- data/ext/cumo/include/cumo/cuda/cublas.h +6 -129
- data/ext/cumo/include/cumo/cuda/runtime.h +16 -0
- data/ext/cumo/include/cumo/indexer.h +46 -63
- data/ext/cumo/include/cumo/intern.h +58 -112
- data/ext/cumo/include/cumo/narray.h +214 -185
- data/ext/cumo/include/cumo/narray_kernel.h +66 -37
- data/ext/cumo/include/cumo/ndloop.h +42 -42
- data/ext/cumo/include/cumo/reduce_kernel.h +55 -71
- data/ext/cumo/include/cumo/template.h +56 -51
- data/ext/cumo/include/cumo/template_kernel.h +31 -31
- data/ext/cumo/include/cumo/types/bit.h +3 -3
- data/ext/cumo/include/cumo/types/bit_kernel.h +2 -2
- data/ext/cumo/include/cumo/types/complex.h +126 -126
- data/ext/cumo/include/cumo/types/complex_kernel.h +126 -126
- data/ext/cumo/include/cumo/types/complex_macro.h +28 -28
- data/ext/cumo/include/cumo/types/complex_macro_kernel.h +20 -20
- data/ext/cumo/include/cumo/types/dcomplex.h +5 -5
- data/ext/cumo/include/cumo/types/dcomplex_kernel.h +1 -1
- data/ext/cumo/include/cumo/types/int_macro.h +1 -1
- data/ext/cumo/include/cumo/types/int_macro_kernel.h +1 -1
- data/ext/cumo/include/cumo/types/robj_macro.h +30 -30
- data/ext/cumo/include/cumo/types/scomplex.h +5 -5
- data/ext/cumo/include/cumo/types/scomplex_kernel.h +1 -1
- data/ext/cumo/narray/array.c +143 -143
- data/ext/cumo/narray/data.c +184 -184
- data/ext/cumo/narray/gen/cogen.rb +5 -2
- data/ext/cumo/narray/gen/cogen_kernel.rb +5 -2
- data/ext/cumo/narray/gen/def/dcomplex.rb +1 -1
- data/ext/cumo/narray/gen/def/scomplex.rb +1 -1
- data/ext/cumo/narray/gen/erbln.rb +132 -0
- data/ext/cumo/narray/gen/erbpp2.rb +18 -13
- data/ext/cumo/narray/gen/narray_def.rb +3 -3
- data/ext/cumo/narray/gen/spec.rb +2 -2
- data/ext/cumo/narray/gen/tmpl/accum.c +15 -15
- data/ext/cumo/narray/gen/tmpl/accum_binary.c +22 -22
- data/ext/cumo/narray/gen/tmpl/accum_binary_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/accum_index.c +30 -30
- data/ext/cumo/narray/gen/tmpl/accum_index_kernel.cu +2 -2
- data/ext/cumo/narray/gen/tmpl/accum_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/alloc_func.c +14 -14
- data/ext/cumo/narray/gen/tmpl/allocate.c +11 -11
- data/ext/cumo/narray/gen/tmpl/aref.c +2 -2
- data/ext/cumo/narray/gen/tmpl/aref_cpu.c +4 -4
- data/ext/cumo/narray/gen/tmpl/aset.c +2 -2
- data/ext/cumo/narray/gen/tmpl/binary.c +28 -28
- data/ext/cumo/narray/gen/tmpl/binary2.c +18 -18
- data/ext/cumo/narray/gen/tmpl/binary2_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/binary_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/binary_s.c +13 -13
- data/ext/cumo/narray/gen/tmpl/binary_s_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/bincount.c +23 -23
- data/ext/cumo/narray/gen/tmpl/cast.c +7 -7
- data/ext/cumo/narray/gen/tmpl/cast_array.c +3 -3
- data/ext/cumo/narray/gen/tmpl/clip.c +38 -38
- data/ext/cumo/narray/gen/tmpl/complex_accum_kernel.cu +2 -2
- data/ext/cumo/narray/gen/tmpl/cond_binary.c +19 -19
- data/ext/cumo/narray/gen/tmpl/cond_binary_kernel.cu +7 -7
- data/ext/cumo/narray/gen/tmpl/cond_unary.c +15 -15
- data/ext/cumo/narray/gen/tmpl/cum.c +15 -15
- data/ext/cumo/narray/gen/tmpl/each.c +9 -9
- data/ext/cumo/narray/gen/tmpl/each_with_index.c +9 -9
- data/ext/cumo/narray/gen/tmpl/ewcomp.c +15 -15
- data/ext/cumo/narray/gen/tmpl/ewcomp_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/extract_cpu.c +5 -5
- data/ext/cumo/narray/gen/tmpl/extract_data.c +12 -12
- data/ext/cumo/narray/gen/tmpl/eye.c +9 -9
- data/ext/cumo/narray/gen/tmpl/eye_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/fill.c +9 -9
- data/ext/cumo/narray/gen/tmpl/fill_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/float_accum_kernel.cu +1 -1
- data/ext/cumo/narray/gen/tmpl/format.c +11 -11
- data/ext/cumo/narray/gen/tmpl/format_to_a.c +8 -8
- data/ext/cumo/narray/gen/tmpl/frexp.c +13 -13
- data/ext/cumo/narray/gen/tmpl/gemm.c +252 -108
- data/ext/cumo/narray/gen/tmpl/inspect.c +1 -1
- data/ext/cumo/narray/gen/tmpl/lib.c +2 -2
- data/ext/cumo/narray/gen/tmpl/logseq.c +7 -7
- data/ext/cumo/narray/gen/tmpl/logseq_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/map_with_index.c +17 -17
- data/ext/cumo/narray/gen/tmpl/median.c +10 -10
- data/ext/cumo/narray/gen/tmpl/minmax.c +10 -10
- data/ext/cumo/narray/gen/tmpl/new_dim0.c +3 -3
- data/ext/cumo/narray/gen/tmpl/poly.c +6 -6
- data/ext/cumo/narray/gen/tmpl/pow.c +28 -28
- data/ext/cumo/narray/gen/tmpl/pow_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/rand.c +10 -10
- data/ext/cumo/narray/gen/tmpl/rand_norm.c +7 -7
- data/ext/cumo/narray/gen/tmpl/real_accum_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/seq.c +7 -7
- data/ext/cumo/narray/gen/tmpl/seq_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/set2.c +20 -20
- data/ext/cumo/narray/gen/tmpl/sort.c +11 -11
- data/ext/cumo/narray/gen/tmpl/sort_index.c +18 -18
- data/ext/cumo/narray/gen/tmpl/store.c +6 -6
- data/ext/cumo/narray/gen/tmpl/store_array.c +19 -19
- data/ext/cumo/narray/gen/tmpl/store_array_kernel.cu +12 -12
- data/ext/cumo/narray/gen/tmpl/store_bit.c +23 -23
- data/ext/cumo/narray/gen/tmpl/store_bit_kernel.cu +28 -28
- data/ext/cumo/narray/gen/tmpl/store_from.c +16 -16
- data/ext/cumo/narray/gen/tmpl/store_from_kernel.cu +12 -12
- data/ext/cumo/narray/gen/tmpl/to_a.c +10 -10
- data/ext/cumo/narray/gen/tmpl/unary.c +25 -25
- data/ext/cumo/narray/gen/tmpl/unary2.c +17 -17
- data/ext/cumo/narray/gen/tmpl/unary_kernel.cu +15 -15
- data/ext/cumo/narray/gen/tmpl/unary_ret2.c +13 -13
- data/ext/cumo/narray/gen/tmpl/unary_s.c +17 -17
- data/ext/cumo/narray/gen/tmpl/unary_s_kernel.cu +12 -12
- data/ext/cumo/narray/gen/tmpl_bit/allocate.c +9 -9
- data/ext/cumo/narray/gen/tmpl_bit/aref.c +2 -2
- data/ext/cumo/narray/gen/tmpl_bit/aref_cpu.c +5 -5
- data/ext/cumo/narray/gen/tmpl_bit/aset.c +2 -2
- data/ext/cumo/narray/gen/tmpl_bit/binary.c +29 -29
- data/ext/cumo/narray/gen/tmpl_bit/bit_count.c +14 -14
- data/ext/cumo/narray/gen/tmpl_bit/bit_count_cpu.c +21 -21
- data/ext/cumo/narray/gen/tmpl_bit/bit_count_kernel.cu +28 -28
- data/ext/cumo/narray/gen/tmpl_bit/bit_reduce.c +29 -29
- data/ext/cumo/narray/gen/tmpl_bit/each.c +10 -10
- data/ext/cumo/narray/gen/tmpl_bit/each_with_index.c +10 -10
- data/ext/cumo/narray/gen/tmpl_bit/extract.c +8 -8
- data/ext/cumo/narray/gen/tmpl_bit/extract_cpu.c +8 -8
- data/ext/cumo/narray/gen/tmpl_bit/fill.c +17 -17
- data/ext/cumo/narray/gen/tmpl_bit/format.c +14 -14
- data/ext/cumo/narray/gen/tmpl_bit/format_to_a.c +11 -11
- data/ext/cumo/narray/gen/tmpl_bit/inspect.c +3 -3
- data/ext/cumo/narray/gen/tmpl_bit/mask.c +33 -33
- data/ext/cumo/narray/gen/tmpl_bit/store_array.c +19 -19
- data/ext/cumo/narray/gen/tmpl_bit/store_bit.c +22 -22
- data/ext/cumo/narray/gen/tmpl_bit/store_from.c +18 -18
- data/ext/cumo/narray/gen/tmpl_bit/to_a.c +12 -12
- data/ext/cumo/narray/gen/tmpl_bit/unary.c +24 -24
- data/ext/cumo/narray/gen/tmpl_bit/where.c +16 -16
- data/ext/cumo/narray/gen/tmpl_bit/where2.c +20 -20
- data/ext/cumo/narray/index.c +213 -213
- data/ext/cumo/narray/math.c +27 -27
- data/ext/cumo/narray/narray.c +484 -484
- data/ext/cumo/narray/ndloop.c +259 -258
- data/ext/cumo/narray/rand.c +3 -3
- data/ext/cumo/narray/step.c +70 -70
- data/ext/cumo/narray/struct.c +139 -139
- metadata +6 -7
- data/ext/cumo/include/cumo/intern_fwd.h +0 -38
- data/lib/erbpp.rb +0 -294
- data/lib/erbpp/line_number.rb +0 -137
- data/lib/erbpp/narray_def.rb +0 -381
@@ -10,20 +10,20 @@
|
|
10
10
|
static VALUE
|
11
11
|
<%=c_func(0)%>(VALUE self)
|
12
12
|
{
|
13
|
-
|
13
|
+
CUMO_BIT_DIGIT *ptr, val;
|
14
14
|
size_t pos;
|
15
|
-
|
16
|
-
|
15
|
+
cumo_narray_t *na;
|
16
|
+
CumoGetNArray(self,na);
|
17
17
|
|
18
18
|
if (na->ndim==0) {
|
19
|
-
pos =
|
20
|
-
ptr = (
|
19
|
+
pos = cumo_na_get_offset(self);
|
20
|
+
ptr = (CUMO_BIT_DIGIT*)cumo_na_get_pointer_for_read(self);
|
21
21
|
|
22
|
-
|
22
|
+
CUMO_SHOW_SYNCHRONIZE_WARNING_ONCE("<%=name%>", "<%=type_name%>");
|
23
23
|
cumo_cuda_runtime_check_status(cudaDeviceSynchronize());
|
24
24
|
|
25
|
-
val = ((*((ptr)+(pos)/
|
26
|
-
|
25
|
+
val = ((*((ptr)+(pos)/CUMO_NB)) >> ((pos)%CUMO_NB)) & 1u;
|
26
|
+
cumo_na_release_lock(self);
|
27
27
|
return INT2FIX(val);
|
28
28
|
}
|
29
29
|
return self;
|
@@ -9,20 +9,20 @@
|
|
9
9
|
static VALUE
|
10
10
|
<%=c_func(0)%>(VALUE self)
|
11
11
|
{
|
12
|
-
|
12
|
+
CUMO_BIT_DIGIT *ptr, val;
|
13
13
|
size_t pos;
|
14
|
-
|
15
|
-
|
14
|
+
cumo_narray_t *na;
|
15
|
+
CumoGetNArray(self,na);
|
16
16
|
|
17
17
|
if (na->ndim==0) {
|
18
|
-
pos =
|
19
|
-
ptr = (
|
18
|
+
pos = cumo_na_get_offset(self);
|
19
|
+
ptr = (CUMO_BIT_DIGIT*)cumo_na_get_pointer_for_read(self);
|
20
20
|
|
21
|
-
|
21
|
+
CUMO_SHOW_SYNCHRONIZE_WARNING_ONCE("<%=name%>", "<%=type_name%>");
|
22
22
|
cumo_cuda_runtime_check_status(cudaDeviceSynchronize());
|
23
23
|
|
24
|
-
val = ((*((ptr)+(pos)/
|
25
|
-
|
24
|
+
val = ((*((ptr)+(pos)/CUMO_NB)) >> ((pos)%CUMO_NB)) & 1u;
|
25
|
+
cumo_na_release_lock(self);
|
26
26
|
return INT2FIX(val);
|
27
27
|
}
|
28
28
|
return self;
|
@@ -1,53 +1,53 @@
|
|
1
1
|
static void
|
2
|
-
<%=c_iter%>(
|
2
|
+
<%=c_iter%>(cumo_na_loop_t *const lp)
|
3
3
|
{
|
4
4
|
size_t n;
|
5
5
|
size_t p3;
|
6
6
|
ssize_t s3;
|
7
7
|
size_t *idx3;
|
8
8
|
int len;
|
9
|
-
|
10
|
-
|
9
|
+
CUMO_BIT_DIGIT *a3;
|
10
|
+
CUMO_BIT_DIGIT y;
|
11
11
|
VALUE x = lp->option;
|
12
12
|
|
13
13
|
// TODO(sonots): CUDA kernelize
|
14
|
-
|
14
|
+
CUMO_SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%>", "<%=type_name%>");
|
15
15
|
cumo_cuda_runtime_check_status(cudaDeviceSynchronize());
|
16
16
|
|
17
17
|
if (x==INT2FIX(0) || x==Qfalse) {
|
18
18
|
y = 0;
|
19
19
|
} else
|
20
20
|
if (x==INT2FIX(1) || x==Qtrue) {
|
21
|
-
y = ~(
|
21
|
+
y = ~(CUMO_BIT_DIGIT)0;
|
22
22
|
} else {
|
23
23
|
rb_raise(rb_eArgError, "invalid value for Bit");
|
24
24
|
}
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
CUMO_INIT_COUNTER(lp, n);
|
27
|
+
CUMO_INIT_PTR_BIT_IDX(lp, 0, a3, p3, s3, idx3);
|
28
28
|
if (idx3) {
|
29
29
|
y = y&1;
|
30
30
|
for (; n--;) {
|
31
|
-
|
31
|
+
CUMO_STORE_BIT(a3, p3+*idx3, y); idx3++;
|
32
32
|
}
|
33
33
|
} else if (s3!=1) {
|
34
34
|
y = y&1;
|
35
35
|
for (; n--;) {
|
36
|
-
|
36
|
+
CUMO_STORE_BIT(a3, p3, y); p3+=s3;
|
37
37
|
}
|
38
38
|
} else {
|
39
|
-
if (p3>0 || n<
|
40
|
-
len =
|
39
|
+
if (p3>0 || n<CUMO_NB) {
|
40
|
+
len = CUMO_NB - p3;
|
41
41
|
if ((int)n<len) len=n;
|
42
|
-
*a3 = (y & (
|
42
|
+
*a3 = (y & (CUMO_SLB(len)<<p3)) | (*a3 & ~(CUMO_SLB(len)<<p3));
|
43
43
|
a3++;
|
44
44
|
n -= len;
|
45
45
|
}
|
46
|
-
for (; n>=
|
46
|
+
for (; n>=CUMO_NB; n-=CUMO_NB) {
|
47
47
|
*(a3++) = y;
|
48
48
|
}
|
49
49
|
if (n>0) {
|
50
|
-
*a3 = (y &
|
50
|
+
*a3 = (y & CUMO_SLB(n)) | (*a3 & CUMO_BALL<<n);
|
51
51
|
}
|
52
52
|
}
|
53
53
|
}
|
@@ -61,9 +61,9 @@ static void
|
|
61
61
|
static VALUE
|
62
62
|
<%=c_func(1)%>(VALUE self, VALUE val)
|
63
63
|
{
|
64
|
-
|
65
|
-
|
64
|
+
cumo_ndfunc_arg_in_t ain[2] = {{CUMO_OVERWRITE,0},{cumo_sym_option}};
|
65
|
+
cumo_ndfunc_t ndf = {<%=c_iter%>, CUMO_FULL_LOOP, 2,0, ain,0};
|
66
66
|
|
67
|
-
|
67
|
+
cumo_na_ndloop(&ndf, 2, self, val);
|
68
68
|
return self;
|
69
69
|
}
|
@@ -11,10 +11,10 @@ format_<%=type_name%>(VALUE fmt, dtype x)
|
|
11
11
|
}
|
12
12
|
|
13
13
|
static void
|
14
|
-
<%=c_iter%>(
|
14
|
+
<%=c_iter%>(cumo_na_loop_t *const lp)
|
15
15
|
{
|
16
16
|
size_t i;
|
17
|
-
|
17
|
+
CUMO_BIT_DIGIT *a1, x=0;
|
18
18
|
size_t p1;
|
19
19
|
char *p2;
|
20
20
|
ssize_t s1, s2;
|
@@ -22,24 +22,24 @@ static void
|
|
22
22
|
VALUE y;
|
23
23
|
VALUE fmt = lp->option;
|
24
24
|
|
25
|
-
|
25
|
+
CUMO_SHOW_SYNCHRONIZE_WARNING_ONCE("<%=name%>", "<%=type_name%>");
|
26
26
|
cumo_cuda_runtime_check_status(cudaDeviceSynchronize());
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
CUMO_INIT_COUNTER(lp, i);
|
29
|
+
CUMO_INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
|
30
|
+
CUMO_INIT_PTR(lp, 1, p2, s2);
|
31
31
|
|
32
32
|
if (idx1) {
|
33
33
|
for (; i--;) {
|
34
|
-
|
34
|
+
CUMO_LOAD_BIT(a1, p1+*idx1, x); idx1++;
|
35
35
|
y = format_<%=type_name%>(fmt, x);
|
36
|
-
|
36
|
+
CUMO_SET_DATA_STRIDE(p2, s2, VALUE, y);
|
37
37
|
}
|
38
38
|
} else {
|
39
39
|
for (; i--;) {
|
40
|
-
|
40
|
+
CUMO_LOAD_BIT(a1, p1, x); p1+=s1;
|
41
41
|
y = format_<%=type_name%>(fmt, x);
|
42
|
-
|
42
|
+
CUMO_SET_DATA_STRIDE(p2, s2, VALUE, y);
|
43
43
|
}
|
44
44
|
}
|
45
45
|
}
|
@@ -55,10 +55,10 @@ static VALUE
|
|
55
55
|
{
|
56
56
|
VALUE fmt=Qnil;
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
cumo_ndfunc_arg_in_t ain[2] = {{Qnil,0},{cumo_sym_option}};
|
59
|
+
cumo_ndfunc_arg_out_t aout[1] = {{cumo_cRObject,0}};
|
60
|
+
cumo_ndfunc_t ndf = {<%=c_iter%>, CUMO_FULL_LOOP_NIP, 2,1, ain,aout};
|
61
61
|
|
62
62
|
rb_scan_args(argc, argv, "01", &fmt);
|
63
|
-
return
|
63
|
+
return cumo_na_ndloop(&ndf, 2, self, fmt);
|
64
64
|
}
|
@@ -1,8 +1,8 @@
|
|
1
1
|
static void
|
2
|
-
<%=c_iter%>(
|
2
|
+
<%=c_iter%>(cumo_na_loop_t *const lp)
|
3
3
|
{
|
4
4
|
size_t i;
|
5
|
-
|
5
|
+
CUMO_BIT_DIGIT *a1, x=0;
|
6
6
|
size_t p1;
|
7
7
|
ssize_t s1;
|
8
8
|
size_t *idx1;
|
@@ -10,19 +10,19 @@ static void
|
|
10
10
|
VALUE fmt = lp->option;
|
11
11
|
volatile VALUE a;
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
CUMO_INIT_COUNTER(lp, i);
|
14
|
+
CUMO_INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
|
15
15
|
a = rb_ary_new2(i);
|
16
16
|
rb_ary_push(lp->args[1].value, a);
|
17
17
|
if (idx1) {
|
18
18
|
for (; i--;) {
|
19
|
-
|
19
|
+
CUMO_LOAD_BIT(a1, p1+*idx1, x); idx1++;
|
20
20
|
y = format_bit(fmt, x);
|
21
21
|
rb_ary_push(a,y);
|
22
22
|
}
|
23
23
|
} else {
|
24
24
|
for (; i--;) {
|
25
|
-
|
25
|
+
CUMO_LOAD_BIT(a1, p1, x); p1+=s1;
|
26
26
|
y = format_bit(fmt, x);
|
27
27
|
rb_ary_push(a,y);
|
28
28
|
}
|
@@ -39,13 +39,13 @@ static VALUE
|
|
39
39
|
<%=c_func(-1)%>(int argc, VALUE *argv, VALUE self)
|
40
40
|
{
|
41
41
|
VALUE fmt=Qnil;
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
cumo_ndfunc_arg_in_t ain[3] = {{Qnil,0},{cumo_sym_loop_opt},{cumo_sym_option}};
|
43
|
+
cumo_ndfunc_arg_out_t aout[1] = {{rb_cArray,0}}; // dummy?
|
44
|
+
cumo_ndfunc_t ndf = {<%=c_iter%>, CUMO_FULL_LOOP_NIP, 3,1, ain,aout};
|
45
45
|
|
46
|
-
|
46
|
+
CUMO_SHOW_SYNCHRONIZE_WARNING_ONCE("<%=name%>", "<%=type_name%>");
|
47
47
|
cumo_cuda_runtime_check_status(cudaDeviceSynchronize());
|
48
48
|
|
49
49
|
rb_scan_args(argc, argv, "01", &fmt);
|
50
|
-
return
|
50
|
+
return cumo_na_ndloop_cast_narray_to_rarray(&ndf, self, fmt);
|
51
51
|
}
|
@@ -2,7 +2,7 @@ static VALUE
|
|
2
2
|
<%=c_iter%>(char *ptr, size_t pos, VALUE fmt)
|
3
3
|
{
|
4
4
|
dtype x;
|
5
|
-
|
5
|
+
CUMO_LOAD_BIT(ptr,pos,x);
|
6
6
|
return format_<%=type_name%>(fmt, x);
|
7
7
|
}
|
8
8
|
|
@@ -14,8 +14,8 @@ static VALUE
|
|
14
14
|
static VALUE
|
15
15
|
<%=c_func(0)%>(VALUE ary)
|
16
16
|
{
|
17
|
-
|
17
|
+
CUMO_SHOW_SYNCHRONIZE_WARNING_ONCE("<%=name%>", "<%=type_name%>");
|
18
18
|
cumo_cuda_runtime_check_status(cudaDeviceSynchronize());
|
19
19
|
|
20
|
-
return
|
20
|
+
return cumo_na_ndloop_inspect(ary, <%=c_iter%>, Qnil);
|
21
21
|
}
|
@@ -1,24 +1,24 @@
|
|
1
1
|
static void
|
2
|
-
<%=c_iter%>(
|
2
|
+
<%=c_iter%>(cumo_na_loop_t *const lp)
|
3
3
|
{
|
4
4
|
size_t i;
|
5
|
-
|
5
|
+
CUMO_BIT_DIGIT *a;
|
6
6
|
size_t p1, p2;
|
7
7
|
ssize_t s1, s2;
|
8
8
|
size_t *idx1, *idx2, *pidx;
|
9
|
-
|
9
|
+
CUMO_BIT_DIGIT x=0;
|
10
10
|
size_t count;
|
11
11
|
where_opt_t *g;
|
12
12
|
|
13
|
-
|
13
|
+
CUMO_SHOW_SYNCHRONIZE_WARNING_ONCE("<%=name%>", "<%=type_name%>");
|
14
14
|
cumo_cuda_runtime_check_status(cudaDeviceSynchronize());
|
15
15
|
|
16
16
|
g = (where_opt_t*)(lp->opt_ptr);
|
17
17
|
count = g->count;
|
18
18
|
pidx = (size_t*)(g->idx1);
|
19
|
-
|
20
|
-
|
21
|
-
//
|
19
|
+
CUMO_INIT_COUNTER(lp, i);
|
20
|
+
CUMO_INIT_PTR_BIT_IDX(lp, 0, a, p1, s1, idx1);
|
21
|
+
//CUMO_INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
22
22
|
p2 = lp->args[1].iter[0].pos;
|
23
23
|
s2 = lp->args[1].iter[0].step;
|
24
24
|
idx2 = lp->args[1].iter[0].idx;
|
@@ -26,7 +26,7 @@ static void
|
|
26
26
|
if (idx1) {
|
27
27
|
if (idx2) {
|
28
28
|
for (; i--;) {
|
29
|
-
|
29
|
+
CUMO_LOAD_BIT(a, p1+*idx1, x);
|
30
30
|
idx1++;
|
31
31
|
if (x) {
|
32
32
|
*(pidx++) = p2+*idx2;
|
@@ -36,7 +36,7 @@ static void
|
|
36
36
|
}
|
37
37
|
} else {
|
38
38
|
for (; i--;) {
|
39
|
-
|
39
|
+
CUMO_LOAD_BIT(a, p1+*idx1, x);
|
40
40
|
idx1++;
|
41
41
|
if (x) {
|
42
42
|
*(pidx++) = p2;
|
@@ -48,7 +48,7 @@ static void
|
|
48
48
|
} else {
|
49
49
|
if (idx2) {
|
50
50
|
for (; i--;) {
|
51
|
-
|
51
|
+
CUMO_LOAD_BIT(a, p1, x);
|
52
52
|
p1 += s1;
|
53
53
|
if (x) {
|
54
54
|
*(pidx++) = p2+*idx2;
|
@@ -58,7 +58,7 @@ static void
|
|
58
58
|
}
|
59
59
|
} else {
|
60
60
|
for (; i--;) {
|
61
|
-
|
61
|
+
CUMO_LOAD_BIT(a, p1, x);
|
62
62
|
p1 += s1;
|
63
63
|
if (x) {
|
64
64
|
*(pidx++) = p2;
|
@@ -88,48 +88,48 @@ static VALUE
|
|
88
88
|
<%=c_func(1)%>(VALUE mask, VALUE val)
|
89
89
|
{
|
90
90
|
volatile VALUE idx_1, view;
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
91
|
+
cumo_narray_data_t *nidx;
|
92
|
+
cumo_narray_view_t *nv;
|
93
|
+
cumo_narray_t *na;
|
94
|
+
cumo_narray_view_t *na1;
|
95
|
+
cumo_stridx_t stridx0;
|
96
96
|
size_t n_1;
|
97
97
|
where_opt_t g;
|
98
|
-
|
99
|
-
|
98
|
+
cumo_ndfunc_arg_in_t ain[2] = {{cT,0},{Qnil,0}};
|
99
|
+
cumo_ndfunc_t ndf = {<%=c_iter%>, CUMO_FULL_LOOP, 2, 0, ain, 0};
|
100
100
|
|
101
101
|
// TODO(sonots): bit_count_true synchronizes with CPU. Avoid.
|
102
102
|
n_1 = NUM2SIZET(<%=find_tmpl("count_true_cpu").c_func%>(0, NULL, mask));
|
103
|
-
idx_1 =
|
103
|
+
idx_1 = cumo_na_new(cIndex, 1, &n_1);
|
104
104
|
g.count = 0;
|
105
105
|
g.elmsz = SIZEOF_VOIDP;
|
106
|
-
g.idx1 =
|
106
|
+
g.idx1 = cumo_na_get_pointer_for_write(idx_1);
|
107
107
|
g.idx0 = NULL;
|
108
|
-
|
108
|
+
cumo_na_ndloop3(&ndf, &g, 2, mask, val);
|
109
109
|
|
110
|
-
view =
|
111
|
-
|
112
|
-
|
110
|
+
view = cumo_na_s_allocate_view(rb_obj_class(val));
|
111
|
+
CumoGetNArrayView(view, nv);
|
112
|
+
cumo_na_setup_shape((cumo_narray_t*)nv, 1, &n_1);
|
113
113
|
|
114
|
-
|
115
|
-
|
114
|
+
CumoGetNArrayData(idx_1,nidx);
|
115
|
+
CUMO_SDX_SET_INDEX(stridx0,(size_t*)nidx->ptr);
|
116
116
|
nidx->ptr = NULL;
|
117
117
|
|
118
|
-
nv->stridx = ALLOC_N(
|
118
|
+
nv->stridx = ALLOC_N(cumo_stridx_t,1);
|
119
119
|
nv->stridx[0] = stridx0;
|
120
120
|
nv->offset = 0;
|
121
121
|
|
122
|
-
|
123
|
-
switch(
|
124
|
-
case
|
122
|
+
CumoGetNArray(val, na);
|
123
|
+
switch(CUMO_NA_TYPE(na)) {
|
124
|
+
case CUMO_NARRAY_DATA_T:
|
125
125
|
nv->data = val;
|
126
126
|
break;
|
127
|
-
case
|
128
|
-
|
127
|
+
case CUMO_NARRAY_VIEW_T:
|
128
|
+
CumoGetNArrayView(val, na1);
|
129
129
|
nv->data = na1->data;
|
130
130
|
break;
|
131
131
|
default:
|
132
|
-
rb_raise(rb_eRuntimeError,"invalid
|
132
|
+
rb_raise(rb_eRuntimeError,"invalid CUMO_NA_TYPE: %d",CUMO_NA_TYPE(na));
|
133
133
|
}
|
134
134
|
|
135
135
|
return view;
|
@@ -1,24 +1,24 @@
|
|
1
1
|
static void
|
2
|
-
<%=c_iter%>(
|
2
|
+
<%=c_iter%>(cumo_na_loop_t *const lp)
|
3
3
|
{
|
4
4
|
size_t i, n;
|
5
5
|
size_t i1, n1;
|
6
6
|
VALUE v1, *ptr;
|
7
|
-
|
7
|
+
CUMO_BIT_DIGIT *a1;
|
8
8
|
size_t p1;
|
9
9
|
size_t s1, *idx1;
|
10
10
|
VALUE x;
|
11
11
|
double y;
|
12
|
-
|
12
|
+
CUMO_BIT_DIGIT z;
|
13
13
|
size_t len, c;
|
14
14
|
double beg, step;
|
15
15
|
|
16
16
|
// TODO(sonots): CUDA kernelize
|
17
|
-
|
17
|
+
CUMO_SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%>", "<%=type_name%>");
|
18
18
|
cumo_cuda_runtime_check_status(cudaDeviceSynchronize());
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
CUMO_INIT_COUNTER(lp, n);
|
21
|
+
CUMO_INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
|
22
22
|
v1 = lp->args[1].value;
|
23
23
|
i = 0;
|
24
24
|
|
@@ -52,34 +52,34 @@ static void
|
|
52
52
|
if (idx1) {
|
53
53
|
for (i=i1=0; i1<n1 && i<n; i++,i1++) {
|
54
54
|
x = ptr[i1];
|
55
|
-
if (rb_obj_is_kind_of(x, rb_cRange) || rb_obj_is_kind_of(x,
|
56
|
-
|
55
|
+
if (rb_obj_is_kind_of(x, rb_cRange) || rb_obj_is_kind_of(x, cumo_na_cStep)) {
|
56
|
+
cumo_na_step_sequence(x,&len,&beg,&step);
|
57
57
|
for (c=0; c<len && i<n; c++,i++) {
|
58
58
|
y = beg + step * c;
|
59
59
|
z = m_from_double(y);
|
60
|
-
|
60
|
+
CUMO_STORE_BIT(a1, p1+*idx1, z); idx1++;
|
61
61
|
}
|
62
62
|
}
|
63
63
|
if (TYPE(x) != T_ARRAY) {
|
64
64
|
if (x == Qnil) x = INT2FIX(0);
|
65
65
|
z = m_num_to_data(x);
|
66
|
-
|
66
|
+
CUMO_STORE_BIT(a1, p1+*idx1, z); idx1++;
|
67
67
|
}
|
68
68
|
}
|
69
69
|
} else {
|
70
70
|
for (i=i1=0; i1<n1 && i<n; i++,i1++) {
|
71
71
|
x = ptr[i1];
|
72
|
-
if (rb_obj_is_kind_of(x, rb_cRange) || rb_obj_is_kind_of(x,
|
73
|
-
|
72
|
+
if (rb_obj_is_kind_of(x, rb_cRange) || rb_obj_is_kind_of(x, cumo_na_cStep)) {
|
73
|
+
cumo_na_step_sequence(x,&len,&beg,&step);
|
74
74
|
for (c=0; c<len && i<n; c++,i++) {
|
75
75
|
y = beg + step * c;
|
76
76
|
z = m_from_double(y);
|
77
|
-
|
77
|
+
CUMO_STORE_BIT(a1, p1, z); p1+=s1;
|
78
78
|
}
|
79
79
|
}
|
80
80
|
if (TYPE(x) != T_ARRAY) {
|
81
81
|
z = m_num_to_data(x);
|
82
|
-
|
82
|
+
CUMO_STORE_BIT(a1, p1, z); p1+=s1;
|
83
83
|
}
|
84
84
|
}
|
85
85
|
}
|
@@ -88,11 +88,11 @@ static void
|
|
88
88
|
z = m_zero;
|
89
89
|
if (idx1) {
|
90
90
|
for (; i<n; i++) {
|
91
|
-
|
91
|
+
CUMO_STORE_BIT(a1, p1+*idx1, z); idx1++;
|
92
92
|
}
|
93
93
|
} else {
|
94
94
|
for (; i<n; i++) {
|
95
|
-
|
95
|
+
CUMO_STORE_BIT(a1, p1, z); p1+=s1;
|
96
96
|
}
|
97
97
|
}
|
98
98
|
}
|
@@ -100,9 +100,9 @@ static void
|
|
100
100
|
static VALUE
|
101
101
|
<%=c_func(:nodef)%>(VALUE self, VALUE rary)
|
102
102
|
{
|
103
|
-
|
104
|
-
|
103
|
+
cumo_ndfunc_arg_in_t ain[2] = {{CUMO_OVERWRITE,0}, {rb_cArray,0}};
|
104
|
+
cumo_ndfunc_t ndf = {<%=c_iter%>, CUMO_FULL_LOOP, 2, 0, ain, 0};
|
105
105
|
|
106
|
-
|
106
|
+
cumo_na_ndloop_store_rarray(&ndf, self, rary);
|
107
107
|
return self;
|
108
108
|
}
|