cumo 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +27 -0
- data/.travis.yml +5 -0
- data/3rd_party/mkmf-cu/.gitignore +36 -0
- data/3rd_party/mkmf-cu/Gemfile +3 -0
- data/3rd_party/mkmf-cu/LICENSE +21 -0
- data/3rd_party/mkmf-cu/README.md +36 -0
- data/3rd_party/mkmf-cu/Rakefile +11 -0
- data/3rd_party/mkmf-cu/bin/mkmf-cu-nvcc +4 -0
- data/3rd_party/mkmf-cu/lib/mkmf-cu.rb +32 -0
- data/3rd_party/mkmf-cu/lib/mkmf-cu/cli.rb +80 -0
- data/3rd_party/mkmf-cu/lib/mkmf-cu/nvcc.rb +157 -0
- data/3rd_party/mkmf-cu/mkmf-cu.gemspec +16 -0
- data/3rd_party/mkmf-cu/test/test_mkmf-cu.rb +67 -0
- data/CODE_OF_CONDUCT.md +46 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +82 -0
- data/README.md +252 -0
- data/Rakefile +43 -0
- data/bench/broadcast_fp32.rb +138 -0
- data/bench/cumo_bench.rb +193 -0
- data/bench/numo_bench.rb +138 -0
- data/bench/reduction_fp32.rb +117 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/cumo.gemspec +32 -0
- data/ext/cumo/cuda/cublas.c +278 -0
- data/ext/cumo/cuda/driver.c +421 -0
- data/ext/cumo/cuda/memory_pool.cpp +185 -0
- data/ext/cumo/cuda/memory_pool_impl.cpp +308 -0
- data/ext/cumo/cuda/memory_pool_impl.hpp +370 -0
- data/ext/cumo/cuda/memory_pool_impl_test.cpp +554 -0
- data/ext/cumo/cuda/nvrtc.c +207 -0
- data/ext/cumo/cuda/runtime.c +167 -0
- data/ext/cumo/cumo.c +148 -0
- data/ext/cumo/depend.erb +58 -0
- data/ext/cumo/extconf.rb +179 -0
- data/ext/cumo/include/cumo.h +25 -0
- data/ext/cumo/include/cumo/compat.h +23 -0
- data/ext/cumo/include/cumo/cuda/cublas.h +153 -0
- data/ext/cumo/include/cumo/cuda/cumo_thrust.hpp +187 -0
- data/ext/cumo/include/cumo/cuda/cumo_thrust_complex.hpp +79 -0
- data/ext/cumo/include/cumo/cuda/driver.h +22 -0
- data/ext/cumo/include/cumo/cuda/memory_pool.h +28 -0
- data/ext/cumo/include/cumo/cuda/nvrtc.h +22 -0
- data/ext/cumo/include/cumo/cuda/runtime.h +40 -0
- data/ext/cumo/include/cumo/indexer.h +238 -0
- data/ext/cumo/include/cumo/intern.h +142 -0
- data/ext/cumo/include/cumo/intern_fwd.h +38 -0
- data/ext/cumo/include/cumo/intern_kernel.h +6 -0
- data/ext/cumo/include/cumo/narray.h +429 -0
- data/ext/cumo/include/cumo/narray_kernel.h +149 -0
- data/ext/cumo/include/cumo/ndloop.h +95 -0
- data/ext/cumo/include/cumo/reduce_kernel.h +126 -0
- data/ext/cumo/include/cumo/template.h +158 -0
- data/ext/cumo/include/cumo/template_kernel.h +77 -0
- data/ext/cumo/include/cumo/types/bit.h +40 -0
- data/ext/cumo/include/cumo/types/bit_kernel.h +34 -0
- data/ext/cumo/include/cumo/types/complex.h +402 -0
- data/ext/cumo/include/cumo/types/complex_kernel.h +414 -0
- data/ext/cumo/include/cumo/types/complex_macro.h +382 -0
- data/ext/cumo/include/cumo/types/complex_macro_kernel.h +186 -0
- data/ext/cumo/include/cumo/types/dcomplex.h +46 -0
- data/ext/cumo/include/cumo/types/dcomplex_kernel.h +13 -0
- data/ext/cumo/include/cumo/types/dfloat.h +47 -0
- data/ext/cumo/include/cumo/types/dfloat_kernel.h +14 -0
- data/ext/cumo/include/cumo/types/float_def.h +34 -0
- data/ext/cumo/include/cumo/types/float_def_kernel.h +39 -0
- data/ext/cumo/include/cumo/types/float_macro.h +191 -0
- data/ext/cumo/include/cumo/types/float_macro_kernel.h +158 -0
- data/ext/cumo/include/cumo/types/int16.h +24 -0
- data/ext/cumo/include/cumo/types/int16_kernel.h +23 -0
- data/ext/cumo/include/cumo/types/int32.h +24 -0
- data/ext/cumo/include/cumo/types/int32_kernel.h +19 -0
- data/ext/cumo/include/cumo/types/int64.h +24 -0
- data/ext/cumo/include/cumo/types/int64_kernel.h +19 -0
- data/ext/cumo/include/cumo/types/int8.h +24 -0
- data/ext/cumo/include/cumo/types/int8_kernel.h +19 -0
- data/ext/cumo/include/cumo/types/int_macro.h +67 -0
- data/ext/cumo/include/cumo/types/int_macro_kernel.h +48 -0
- data/ext/cumo/include/cumo/types/real_accum.h +486 -0
- data/ext/cumo/include/cumo/types/real_accum_kernel.h +101 -0
- data/ext/cumo/include/cumo/types/robj_macro.h +80 -0
- data/ext/cumo/include/cumo/types/robj_macro_kernel.h +0 -0
- data/ext/cumo/include/cumo/types/robject.h +27 -0
- data/ext/cumo/include/cumo/types/robject_kernel.h +7 -0
- data/ext/cumo/include/cumo/types/scomplex.h +46 -0
- data/ext/cumo/include/cumo/types/scomplex_kernel.h +13 -0
- data/ext/cumo/include/cumo/types/sfloat.h +48 -0
- data/ext/cumo/include/cumo/types/sfloat_kernel.h +14 -0
- data/ext/cumo/include/cumo/types/uint16.h +25 -0
- data/ext/cumo/include/cumo/types/uint16_kernel.h +20 -0
- data/ext/cumo/include/cumo/types/uint32.h +25 -0
- data/ext/cumo/include/cumo/types/uint32_kernel.h +20 -0
- data/ext/cumo/include/cumo/types/uint64.h +25 -0
- data/ext/cumo/include/cumo/types/uint64_kernel.h +20 -0
- data/ext/cumo/include/cumo/types/uint8.h +25 -0
- data/ext/cumo/include/cumo/types/uint8_kernel.h +20 -0
- data/ext/cumo/include/cumo/types/uint_macro.h +58 -0
- data/ext/cumo/include/cumo/types/uint_macro_kernel.h +38 -0
- data/ext/cumo/include/cumo/types/xint_macro.h +169 -0
- data/ext/cumo/include/cumo/types/xint_macro_kernel.h +88 -0
- data/ext/cumo/narray/SFMT-params.h +97 -0
- data/ext/cumo/narray/SFMT-params19937.h +46 -0
- data/ext/cumo/narray/SFMT.c +620 -0
- data/ext/cumo/narray/SFMT.h +167 -0
- data/ext/cumo/narray/array.c +638 -0
- data/ext/cumo/narray/data.c +961 -0
- data/ext/cumo/narray/gen/cogen.rb +56 -0
- data/ext/cumo/narray/gen/cogen_kernel.rb +58 -0
- data/ext/cumo/narray/gen/def/bit.rb +37 -0
- data/ext/cumo/narray/gen/def/dcomplex.rb +39 -0
- data/ext/cumo/narray/gen/def/dfloat.rb +37 -0
- data/ext/cumo/narray/gen/def/int16.rb +36 -0
- data/ext/cumo/narray/gen/def/int32.rb +36 -0
- data/ext/cumo/narray/gen/def/int64.rb +36 -0
- data/ext/cumo/narray/gen/def/int8.rb +36 -0
- data/ext/cumo/narray/gen/def/robject.rb +37 -0
- data/ext/cumo/narray/gen/def/scomplex.rb +39 -0
- data/ext/cumo/narray/gen/def/sfloat.rb +37 -0
- data/ext/cumo/narray/gen/def/uint16.rb +36 -0
- data/ext/cumo/narray/gen/def/uint32.rb +36 -0
- data/ext/cumo/narray/gen/def/uint64.rb +36 -0
- data/ext/cumo/narray/gen/def/uint8.rb +36 -0
- data/ext/cumo/narray/gen/erbpp2.rb +346 -0
- data/ext/cumo/narray/gen/narray_def.rb +268 -0
- data/ext/cumo/narray/gen/spec.rb +425 -0
- data/ext/cumo/narray/gen/tmpl/accum.c +86 -0
- data/ext/cumo/narray/gen/tmpl/accum_binary.c +121 -0
- data/ext/cumo/narray/gen/tmpl/accum_binary_kernel.cu +61 -0
- data/ext/cumo/narray/gen/tmpl/accum_index.c +119 -0
- data/ext/cumo/narray/gen/tmpl/accum_index_kernel.cu +66 -0
- data/ext/cumo/narray/gen/tmpl/accum_kernel.cu +12 -0
- data/ext/cumo/narray/gen/tmpl/alloc_func.c +107 -0
- data/ext/cumo/narray/gen/tmpl/allocate.c +37 -0
- data/ext/cumo/narray/gen/tmpl/aref.c +66 -0
- data/ext/cumo/narray/gen/tmpl/aref_cpu.c +50 -0
- data/ext/cumo/narray/gen/tmpl/aset.c +56 -0
- data/ext/cumo/narray/gen/tmpl/binary.c +162 -0
- data/ext/cumo/narray/gen/tmpl/binary2.c +70 -0
- data/ext/cumo/narray/gen/tmpl/binary2_kernel.cu +15 -0
- data/ext/cumo/narray/gen/tmpl/binary_kernel.cu +31 -0
- data/ext/cumo/narray/gen/tmpl/binary_s.c +45 -0
- data/ext/cumo/narray/gen/tmpl/binary_s_kernel.cu +15 -0
- data/ext/cumo/narray/gen/tmpl/bincount.c +181 -0
- data/ext/cumo/narray/gen/tmpl/cast.c +44 -0
- data/ext/cumo/narray/gen/tmpl/cast_array.c +13 -0
- data/ext/cumo/narray/gen/tmpl/class.c +9 -0
- data/ext/cumo/narray/gen/tmpl/class_kernel.cu +6 -0
- data/ext/cumo/narray/gen/tmpl/clip.c +121 -0
- data/ext/cumo/narray/gen/tmpl/coerce_cast.c +10 -0
- data/ext/cumo/narray/gen/tmpl/complex_accum_kernel.cu +129 -0
- data/ext/cumo/narray/gen/tmpl/cond_binary.c +68 -0
- data/ext/cumo/narray/gen/tmpl/cond_binary_kernel.cu +18 -0
- data/ext/cumo/narray/gen/tmpl/cond_unary.c +46 -0
- data/ext/cumo/narray/gen/tmpl/cum.c +50 -0
- data/ext/cumo/narray/gen/tmpl/each.c +47 -0
- data/ext/cumo/narray/gen/tmpl/each_with_index.c +70 -0
- data/ext/cumo/narray/gen/tmpl/ewcomp.c +79 -0
- data/ext/cumo/narray/gen/tmpl/ewcomp_kernel.cu +19 -0
- data/ext/cumo/narray/gen/tmpl/extract.c +22 -0
- data/ext/cumo/narray/gen/tmpl/extract_cpu.c +26 -0
- data/ext/cumo/narray/gen/tmpl/extract_data.c +53 -0
- data/ext/cumo/narray/gen/tmpl/eye.c +105 -0
- data/ext/cumo/narray/gen/tmpl/eye_kernel.cu +19 -0
- data/ext/cumo/narray/gen/tmpl/fill.c +52 -0
- data/ext/cumo/narray/gen/tmpl/fill_kernel.cu +29 -0
- data/ext/cumo/narray/gen/tmpl/float_accum_kernel.cu +106 -0
- data/ext/cumo/narray/gen/tmpl/format.c +62 -0
- data/ext/cumo/narray/gen/tmpl/format_to_a.c +49 -0
- data/ext/cumo/narray/gen/tmpl/frexp.c +38 -0
- data/ext/cumo/narray/gen/tmpl/gemm.c +203 -0
- data/ext/cumo/narray/gen/tmpl/init_class.c +20 -0
- data/ext/cumo/narray/gen/tmpl/init_module.c +12 -0
- data/ext/cumo/narray/gen/tmpl/inspect.c +21 -0
- data/ext/cumo/narray/gen/tmpl/lib.c +50 -0
- data/ext/cumo/narray/gen/tmpl/lib_kernel.cu +24 -0
- data/ext/cumo/narray/gen/tmpl/logseq.c +102 -0
- data/ext/cumo/narray/gen/tmpl/logseq_kernel.cu +31 -0
- data/ext/cumo/narray/gen/tmpl/map_with_index.c +98 -0
- data/ext/cumo/narray/gen/tmpl/median.c +66 -0
- data/ext/cumo/narray/gen/tmpl/minmax.c +47 -0
- data/ext/cumo/narray/gen/tmpl/module.c +9 -0
- data/ext/cumo/narray/gen/tmpl/module_kernel.cu +1 -0
- data/ext/cumo/narray/gen/tmpl/new_dim0.c +15 -0
- data/ext/cumo/narray/gen/tmpl/new_dim0_kernel.cu +8 -0
- data/ext/cumo/narray/gen/tmpl/poly.c +50 -0
- data/ext/cumo/narray/gen/tmpl/pow.c +97 -0
- data/ext/cumo/narray/gen/tmpl/pow_kernel.cu +29 -0
- data/ext/cumo/narray/gen/tmpl/powint.c +17 -0
- data/ext/cumo/narray/gen/tmpl/qsort.c +212 -0
- data/ext/cumo/narray/gen/tmpl/rand.c +168 -0
- data/ext/cumo/narray/gen/tmpl/rand_norm.c +121 -0
- data/ext/cumo/narray/gen/tmpl/real_accum_kernel.cu +75 -0
- data/ext/cumo/narray/gen/tmpl/seq.c +112 -0
- data/ext/cumo/narray/gen/tmpl/seq_kernel.cu +43 -0
- data/ext/cumo/narray/gen/tmpl/set2.c +57 -0
- data/ext/cumo/narray/gen/tmpl/sort.c +48 -0
- data/ext/cumo/narray/gen/tmpl/sort_index.c +111 -0
- data/ext/cumo/narray/gen/tmpl/store.c +41 -0
- data/ext/cumo/narray/gen/tmpl/store_array.c +187 -0
- data/ext/cumo/narray/gen/tmpl/store_array_kernel.cu +58 -0
- data/ext/cumo/narray/gen/tmpl/store_bit.c +86 -0
- data/ext/cumo/narray/gen/tmpl/store_bit_kernel.cu +66 -0
- data/ext/cumo/narray/gen/tmpl/store_from.c +81 -0
- data/ext/cumo/narray/gen/tmpl/store_from_kernel.cu +58 -0
- data/ext/cumo/narray/gen/tmpl/store_kernel.cu +3 -0
- data/ext/cumo/narray/gen/tmpl/store_numeric.c +9 -0
- data/ext/cumo/narray/gen/tmpl/to_a.c +43 -0
- data/ext/cumo/narray/gen/tmpl/unary.c +132 -0
- data/ext/cumo/narray/gen/tmpl/unary2.c +60 -0
- data/ext/cumo/narray/gen/tmpl/unary_kernel.cu +72 -0
- data/ext/cumo/narray/gen/tmpl/unary_ret2.c +34 -0
- data/ext/cumo/narray/gen/tmpl/unary_s.c +86 -0
- data/ext/cumo/narray/gen/tmpl/unary_s_kernel.cu +58 -0
- data/ext/cumo/narray/gen/tmpl_bit/allocate.c +24 -0
- data/ext/cumo/narray/gen/tmpl_bit/aref.c +54 -0
- data/ext/cumo/narray/gen/tmpl_bit/aref_cpu.c +57 -0
- data/ext/cumo/narray/gen/tmpl_bit/aset.c +56 -0
- data/ext/cumo/narray/gen/tmpl_bit/binary.c +98 -0
- data/ext/cumo/narray/gen/tmpl_bit/bit_count.c +64 -0
- data/ext/cumo/narray/gen/tmpl_bit/bit_count_cpu.c +88 -0
- data/ext/cumo/narray/gen/tmpl_bit/bit_count_kernel.cu +76 -0
- data/ext/cumo/narray/gen/tmpl_bit/bit_reduce.c +133 -0
- data/ext/cumo/narray/gen/tmpl_bit/each.c +48 -0
- data/ext/cumo/narray/gen/tmpl_bit/each_with_index.c +70 -0
- data/ext/cumo/narray/gen/tmpl_bit/extract.c +30 -0
- data/ext/cumo/narray/gen/tmpl_bit/extract_cpu.c +29 -0
- data/ext/cumo/narray/gen/tmpl_bit/fill.c +69 -0
- data/ext/cumo/narray/gen/tmpl_bit/format.c +64 -0
- data/ext/cumo/narray/gen/tmpl_bit/format_to_a.c +51 -0
- data/ext/cumo/narray/gen/tmpl_bit/inspect.c +21 -0
- data/ext/cumo/narray/gen/tmpl_bit/mask.c +136 -0
- data/ext/cumo/narray/gen/tmpl_bit/none_p.c +14 -0
- data/ext/cumo/narray/gen/tmpl_bit/store_array.c +108 -0
- data/ext/cumo/narray/gen/tmpl_bit/store_bit.c +70 -0
- data/ext/cumo/narray/gen/tmpl_bit/store_from.c +60 -0
- data/ext/cumo/narray/gen/tmpl_bit/to_a.c +47 -0
- data/ext/cumo/narray/gen/tmpl_bit/unary.c +81 -0
- data/ext/cumo/narray/gen/tmpl_bit/where.c +90 -0
- data/ext/cumo/narray/gen/tmpl_bit/where2.c +95 -0
- data/ext/cumo/narray/index.c +880 -0
- data/ext/cumo/narray/kwargs.c +153 -0
- data/ext/cumo/narray/math.c +142 -0
- data/ext/cumo/narray/narray.c +1948 -0
- data/ext/cumo/narray/ndloop.c +2105 -0
- data/ext/cumo/narray/rand.c +45 -0
- data/ext/cumo/narray/step.c +474 -0
- data/ext/cumo/narray/struct.c +886 -0
- data/lib/cumo.rb +3 -0
- data/lib/cumo/cuda.rb +11 -0
- data/lib/cumo/cuda/compile_error.rb +36 -0
- data/lib/cumo/cuda/compiler.rb +161 -0
- data/lib/cumo/cuda/device.rb +47 -0
- data/lib/cumo/cuda/link_state.rb +31 -0
- data/lib/cumo/cuda/module.rb +40 -0
- data/lib/cumo/cuda/nvrtc_program.rb +27 -0
- data/lib/cumo/linalg.rb +12 -0
- data/lib/cumo/narray.rb +2 -0
- data/lib/cumo/narray/extra.rb +1278 -0
- data/lib/erbpp.rb +294 -0
- data/lib/erbpp/line_number.rb +137 -0
- data/lib/erbpp/narray_def.rb +381 -0
- data/numo-narray-version +1 -0
- data/run.gdb +7 -0
- metadata +353 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
static VALUE
|
2
|
+
<%=c_func(-1)%>(int argc, VALUE *argv, VALUE self)
|
3
|
+
{
|
4
|
+
VALUE v;
|
5
|
+
|
6
|
+
v = <%=find_tmpl("any?").c_func%>(argc,argv,self);
|
7
|
+
|
8
|
+
if (v==Qtrue) {
|
9
|
+
return Qfalse;
|
10
|
+
} else if (v==Qfalse) {
|
11
|
+
return Qtrue;
|
12
|
+
}
|
13
|
+
return <%=find_tmpl("not").c_func%>(v);
|
14
|
+
}
|
@@ -0,0 +1,108 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t i, n;
|
5
|
+
size_t i1, n1;
|
6
|
+
VALUE v1, *ptr;
|
7
|
+
BIT_DIGIT *a1;
|
8
|
+
size_t p1;
|
9
|
+
size_t s1, *idx1;
|
10
|
+
VALUE x;
|
11
|
+
double y;
|
12
|
+
BIT_DIGIT z;
|
13
|
+
size_t len, c;
|
14
|
+
double beg, step;
|
15
|
+
|
16
|
+
// TODO(sonots): CUDA kernelize
|
17
|
+
SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%>", "<%=type_name%>");
|
18
|
+
cumo_cuda_runtime_check_status(cudaDeviceSynchronize());
|
19
|
+
|
20
|
+
INIT_COUNTER(lp, n);
|
21
|
+
INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
|
22
|
+
v1 = lp->args[1].value;
|
23
|
+
i = 0;
|
24
|
+
|
25
|
+
if (lp->args[1].ptr) {
|
26
|
+
if (v1 == Qtrue) {
|
27
|
+
iter_<%=type_name%>_store_<%=type_name%>(lp);
|
28
|
+
i = lp->args[1].shape[0];
|
29
|
+
if (idx1) {
|
30
|
+
idx1 += i;
|
31
|
+
} else {
|
32
|
+
p1 += s1 * i;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
goto loop_end;
|
36
|
+
}
|
37
|
+
|
38
|
+
ptr = &v1;
|
39
|
+
|
40
|
+
switch(TYPE(v1)) {
|
41
|
+
case T_ARRAY:
|
42
|
+
n1 = RARRAY_LEN(v1);
|
43
|
+
ptr = RARRAY_PTR(v1);
|
44
|
+
break;
|
45
|
+
case T_NIL:
|
46
|
+
n1 = 0;
|
47
|
+
break;
|
48
|
+
default:
|
49
|
+
n1 = 1;
|
50
|
+
}
|
51
|
+
|
52
|
+
if (idx1) {
|
53
|
+
for (i=i1=0; i1<n1 && i<n; i++,i1++) {
|
54
|
+
x = ptr[i1];
|
55
|
+
if (rb_obj_is_kind_of(x, rb_cRange) || rb_obj_is_kind_of(x, na_cStep)) {
|
56
|
+
nary_step_sequence(x,&len,&beg,&step);
|
57
|
+
for (c=0; c<len && i<n; c++,i++) {
|
58
|
+
y = beg + step * c;
|
59
|
+
z = m_from_double(y);
|
60
|
+
STORE_BIT(a1, p1+*idx1, z); idx1++;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
if (TYPE(x) != T_ARRAY) {
|
64
|
+
if (x == Qnil) x = INT2FIX(0);
|
65
|
+
z = m_num_to_data(x);
|
66
|
+
STORE_BIT(a1, p1+*idx1, z); idx1++;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
} else {
|
70
|
+
for (i=i1=0; i1<n1 && i<n; i++,i1++) {
|
71
|
+
x = ptr[i1];
|
72
|
+
if (rb_obj_is_kind_of(x, rb_cRange) || rb_obj_is_kind_of(x, na_cStep)) {
|
73
|
+
nary_step_sequence(x,&len,&beg,&step);
|
74
|
+
for (c=0; c<len && i<n; c++,i++) {
|
75
|
+
y = beg + step * c;
|
76
|
+
z = m_from_double(y);
|
77
|
+
STORE_BIT(a1, p1, z); p1+=s1;
|
78
|
+
}
|
79
|
+
}
|
80
|
+
if (TYPE(x) != T_ARRAY) {
|
81
|
+
z = m_num_to_data(x);
|
82
|
+
STORE_BIT(a1, p1, z); p1+=s1;
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
loop_end:
|
88
|
+
z = m_zero;
|
89
|
+
if (idx1) {
|
90
|
+
for (; i<n; i++) {
|
91
|
+
STORE_BIT(a1, p1+*idx1, z); idx1++;
|
92
|
+
}
|
93
|
+
} else {
|
94
|
+
for (; i<n; i++) {
|
95
|
+
STORE_BIT(a1, p1, z); p1+=s1;
|
96
|
+
}
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
static VALUE
|
101
|
+
<%=c_func(:nodef)%>(VALUE self, VALUE rary)
|
102
|
+
{
|
103
|
+
ndfunc_arg_in_t ain[2] = {{OVERWRITE,0}, {rb_cArray,0}};
|
104
|
+
ndfunc_t ndf = {<%=c_iter%>, FULL_LOOP, 2, 0, ain, 0};
|
105
|
+
|
106
|
+
na_ndloop_store_rarray(&ndf, self, rary);
|
107
|
+
return self;
|
108
|
+
}
|
@@ -0,0 +1,70 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t n;
|
5
|
+
size_t p1, p3;
|
6
|
+
ssize_t s1, s3;
|
7
|
+
size_t *idx1, *idx3;
|
8
|
+
int o1, l1, r1, len;
|
9
|
+
BIT_DIGIT *a1, *a3;
|
10
|
+
BIT_DIGIT x;
|
11
|
+
|
12
|
+
// TODO(sonots): CUDA kernelize
|
13
|
+
SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%>", "<%=type_name%>");
|
14
|
+
cumo_cuda_runtime_check_status(cudaDeviceSynchronize());
|
15
|
+
|
16
|
+
INIT_COUNTER(lp, n);
|
17
|
+
INIT_PTR_BIT_IDX(lp, 0, a3, p3, s3, idx3);
|
18
|
+
INIT_PTR_BIT_IDX(lp, 1, a1, p1, s1, idx1);
|
19
|
+
if (s1!=1 || s3!=1 || idx1 || idx3) {
|
20
|
+
for (; n--;) {
|
21
|
+
LOAD_BIT_STEP(a1, p1, s1, idx1, x);
|
22
|
+
STORE_BIT_STEP(a3, p3, s3, idx3, x);
|
23
|
+
}
|
24
|
+
} else {
|
25
|
+
o1 = p1 % NB;
|
26
|
+
o1 -= p3;
|
27
|
+
l1 = NB+o1;
|
28
|
+
r1 = NB-o1;
|
29
|
+
if (p3>0 || n<NB) {
|
30
|
+
len = NB - p3;
|
31
|
+
if ((int)n<len) len=n;
|
32
|
+
if (o1>=0) x = *a1>>o1;
|
33
|
+
else x = *a1<<-o1;
|
34
|
+
if (p1+len>NB) x |= *(a1+1)<<r1;
|
35
|
+
a1++;
|
36
|
+
*a3 = (x & (SLB(len)<<p3)) | (*a3 & ~(SLB(len)<<p3));
|
37
|
+
a3++;
|
38
|
+
n -= len;
|
39
|
+
}
|
40
|
+
if (o1==0) {
|
41
|
+
for (; n>=NB; n-=NB) {
|
42
|
+
x = *(a1++);
|
43
|
+
*(a3++) = x;
|
44
|
+
}
|
45
|
+
} else {
|
46
|
+
for (; n>=NB; n-=NB) {
|
47
|
+
x = *a1>>o1;
|
48
|
+
if (o1<0) x |= *(a1-1)>>l1;
|
49
|
+
if (o1>0) x |= *(a1+1)<<r1;
|
50
|
+
a1++;
|
51
|
+
*(a3++) = x;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
if (n>0) {
|
55
|
+
x = *a1>>o1;
|
56
|
+
if (o1<0) x |= *(a1-1)>>l1;
|
57
|
+
*a3 = (x & SLB(n)) | (*a3 & BALL<<n);
|
58
|
+
}
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
static VALUE
|
63
|
+
<%=c_func(:nodef)%>(VALUE self, VALUE obj)
|
64
|
+
{
|
65
|
+
ndfunc_arg_in_t ain[2] = {{OVERWRITE,0},{Qnil,0}};
|
66
|
+
ndfunc_t ndf = {<%=c_iter%>, FULL_LOOP, 2,0, ain,0};
|
67
|
+
|
68
|
+
na_ndloop(&ndf, 2, self, obj);
|
69
|
+
return self;
|
70
|
+
}
|
@@ -0,0 +1,60 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
ssize_t i, s1, s2;
|
5
|
+
size_t p1;
|
6
|
+
char *p2;
|
7
|
+
size_t *idx1, *idx2;
|
8
|
+
<%=dtype%> x;
|
9
|
+
BIT_DIGIT *a1;
|
10
|
+
BIT_DIGIT y;
|
11
|
+
|
12
|
+
// TODO(sonots): CUDA kernelize
|
13
|
+
SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%>", "<%=type_name%>");
|
14
|
+
cumo_cuda_runtime_check_status(cudaDeviceSynchronize());
|
15
|
+
|
16
|
+
INIT_COUNTER(lp, i);
|
17
|
+
INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
|
18
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
19
|
+
|
20
|
+
if (idx2) {
|
21
|
+
if (idx1) {
|
22
|
+
for (; i--;) {
|
23
|
+
GET_DATA_INDEX(p2,idx2,<%=dtype%>,x);
|
24
|
+
y = <%=macro%>(x);
|
25
|
+
STORE_BIT(a1, p1+*idx1, y); idx1++;
|
26
|
+
}
|
27
|
+
} else {
|
28
|
+
for (; i--;) {
|
29
|
+
GET_DATA_INDEX(p2,idx2,<%=dtype%>,x);
|
30
|
+
y = <%=macro%>(x);
|
31
|
+
STORE_BIT(a1, p1, y); p1+=s1;
|
32
|
+
}
|
33
|
+
}
|
34
|
+
} else {
|
35
|
+
if (idx1) {
|
36
|
+
for (; i--;) {
|
37
|
+
GET_DATA_STRIDE(p2,s2,<%=dtype%>,x);
|
38
|
+
y = <%=macro%>(x);
|
39
|
+
STORE_BIT(a1, p1+*idx1, y); idx1++;
|
40
|
+
}
|
41
|
+
} else {
|
42
|
+
for (; i--;) {
|
43
|
+
GET_DATA_STRIDE(p2,s2,<%=dtype%>,x);
|
44
|
+
y = <%=macro%>(x);
|
45
|
+
STORE_BIT(a1, p1, y); p1+=s1;
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
|
52
|
+
static VALUE
|
53
|
+
<%=c_func(:nodef)%>(VALUE self, VALUE obj)
|
54
|
+
{
|
55
|
+
ndfunc_arg_in_t ain[2] = {{OVERWRITE,0},{Qnil,0}};
|
56
|
+
ndfunc_t ndf = {<%=c_iter%>, FULL_LOOP, 2,0, ain,0};
|
57
|
+
|
58
|
+
na_ndloop(&ndf, 2, self, obj);
|
59
|
+
return self;
|
60
|
+
}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t i;
|
5
|
+
BIT_DIGIT *a1;
|
6
|
+
size_t p1;
|
7
|
+
ssize_t s1;
|
8
|
+
size_t *idx1;
|
9
|
+
BIT_DIGIT x=0;
|
10
|
+
VALUE a, y;
|
11
|
+
|
12
|
+
SHOW_SYNCHRONIZE_WARNING_ONCE("<%=name%>", "<%=type_name%>");
|
13
|
+
cumo_cuda_runtime_check_status(cudaDeviceSynchronize());
|
14
|
+
|
15
|
+
INIT_COUNTER(lp, i);
|
16
|
+
INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
|
17
|
+
a = rb_ary_new2(i);
|
18
|
+
rb_ary_push(lp->args[1].value, a);
|
19
|
+
if (idx1) {
|
20
|
+
for (; i--;) {
|
21
|
+
LOAD_BIT(a1,p1+*idx1,x); idx1++;
|
22
|
+
y = m_data_to_num(x);
|
23
|
+
rb_ary_push(a,y);
|
24
|
+
}
|
25
|
+
} else {
|
26
|
+
for (; i--;) {
|
27
|
+
LOAD_BIT(a1,p1,x); p1+=s1;
|
28
|
+
y = m_data_to_num(x);
|
29
|
+
rb_ary_push(a,y);
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
/*
|
35
|
+
Convert self to Array.
|
36
|
+
@overload <%=name%>
|
37
|
+
@return [Array]
|
38
|
+
*/
|
39
|
+
static VALUE
|
40
|
+
<%=c_func(0)%>(VALUE self)
|
41
|
+
{
|
42
|
+
ndfunc_arg_in_t ain[3] = {{Qnil,0},{sym_loop_opt},{sym_option}};
|
43
|
+
ndfunc_arg_out_t aout[1] = {{rb_cArray,0}}; // dummy?
|
44
|
+
ndfunc_t ndf = {<%=c_iter%>, FULL_LOOP_NIP, 3,1, ain,aout};
|
45
|
+
|
46
|
+
return na_ndloop_cast_narray_to_rarray(&ndf, self, Qnil);
|
47
|
+
}
|
@@ -0,0 +1,81 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t n;
|
5
|
+
size_t p1, p3;
|
6
|
+
ssize_t s1, s3;
|
7
|
+
size_t *idx1, *idx3;
|
8
|
+
int o1, l1, r1, len;
|
9
|
+
BIT_DIGIT *a1, *a3;
|
10
|
+
BIT_DIGIT x;
|
11
|
+
BIT_DIGIT y;
|
12
|
+
|
13
|
+
// TODO(sonots): CUDA kernelize
|
14
|
+
SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%>", "<%=type_name%>");
|
15
|
+
cumo_cuda_runtime_check_status(cudaDeviceSynchronize());
|
16
|
+
|
17
|
+
INIT_COUNTER(lp, n);
|
18
|
+
INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
|
19
|
+
INIT_PTR_BIT_IDX(lp, 1, a3, p3, s3, idx3);
|
20
|
+
if (s1!=1 || s3!=1 || idx1 || idx3) {
|
21
|
+
for (; n--;) {
|
22
|
+
LOAD_BIT_STEP(a1, p1, s1, idx1, x);
|
23
|
+
y = m_<%=name%>(x);
|
24
|
+
STORE_BIT_STEP(a3, p3, s3, idx3, y);
|
25
|
+
}
|
26
|
+
} else {
|
27
|
+
o1 = p1 % NB;
|
28
|
+
o1 -= p3;
|
29
|
+
l1 = NB+o1;
|
30
|
+
r1 = NB-o1;
|
31
|
+
if (p3>0 || n<NB) {
|
32
|
+
len = NB - p3;
|
33
|
+
if ((int)n<len) len=n;
|
34
|
+
if (o1>=0) x = *a1>>o1;
|
35
|
+
else x = *a1<<-o1;
|
36
|
+
if (p1+len>NB) x |= *(a1+1)<<r1;
|
37
|
+
a1++;
|
38
|
+
y = m_<%=name%>(x);
|
39
|
+
*a3 = (y & (SLB(len)<<p3)) | (*a3 & ~(SLB(len)<<p3));
|
40
|
+
a3++;
|
41
|
+
n -= len;
|
42
|
+
}
|
43
|
+
if (o1==0) {
|
44
|
+
for (; n>=NB; n-=NB) {
|
45
|
+
x = *(a1++);
|
46
|
+
y = m_<%=name%>(x);
|
47
|
+
*(a3++) = y;
|
48
|
+
}
|
49
|
+
} else {
|
50
|
+
for (; n>=NB; n-=NB) {
|
51
|
+
x = *a1>>o1;
|
52
|
+
if (o1<0) x |= *(a1-1)>>l1;
|
53
|
+
if (o1>0) x |= *(a1+1)<<r1;
|
54
|
+
a1++;
|
55
|
+
y = m_<%=name%>(x);
|
56
|
+
*(a3++) = y;
|
57
|
+
}
|
58
|
+
}
|
59
|
+
if (n>0) {
|
60
|
+
x = *a1>>o1;
|
61
|
+
if (o1<0) x |= *(a1-1)>>l1;
|
62
|
+
y = m_<%=name%>(x);
|
63
|
+
*a3 = (y & SLB(n)) | (*a3 & BALL<<n);
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
/*
|
69
|
+
Unary <%=name%>.
|
70
|
+
@overload <%=name%>
|
71
|
+
@return [Cumo::<%=class_name%>] <%=name%> of self.
|
72
|
+
*/
|
73
|
+
static VALUE
|
74
|
+
<%=c_func(0)%>(VALUE self)
|
75
|
+
{
|
76
|
+
ndfunc_arg_in_t ain[1] = {{cT,0}};
|
77
|
+
ndfunc_arg_out_t aout[1] = {{cT,0}};
|
78
|
+
ndfunc_t ndf = {<%=c_iter%>, FULL_LOOP, 1,1, ain,aout};
|
79
|
+
|
80
|
+
return na_ndloop(&ndf, 1, self);
|
81
|
+
}
|
@@ -0,0 +1,90 @@
|
|
1
|
+
typedef struct {
|
2
|
+
size_t count;
|
3
|
+
char *idx0;
|
4
|
+
char *idx1;
|
5
|
+
size_t elmsz;
|
6
|
+
} where_opt_t;
|
7
|
+
|
8
|
+
#define STORE_INT(ptr, esz, x) memcpy(ptr,&(x),esz)
|
9
|
+
|
10
|
+
static void
|
11
|
+
<%=c_iter%>(na_loop_t *const lp)
|
12
|
+
{
|
13
|
+
size_t i;
|
14
|
+
BIT_DIGIT *a;
|
15
|
+
size_t p;
|
16
|
+
ssize_t s;
|
17
|
+
size_t *idx;
|
18
|
+
BIT_DIGIT x=0;
|
19
|
+
char *idx1;
|
20
|
+
size_t count;
|
21
|
+
size_t e;
|
22
|
+
where_opt_t *g;
|
23
|
+
|
24
|
+
// TODO(sonots): CUDA kernelize
|
25
|
+
SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%>", "<%=type_name%>");
|
26
|
+
cumo_cuda_runtime_check_status(cudaDeviceSynchronize());
|
27
|
+
|
28
|
+
g = (where_opt_t*)(lp->opt_ptr);
|
29
|
+
count = g->count;
|
30
|
+
idx1 = g->idx1;
|
31
|
+
e = g->elmsz;
|
32
|
+
INIT_COUNTER(lp, i);
|
33
|
+
INIT_PTR_BIT_IDX(lp, 0, a, p, s, idx);
|
34
|
+
if (idx) {
|
35
|
+
for (; i--;) {
|
36
|
+
LOAD_BIT(a, p+*idx, x);
|
37
|
+
idx++;
|
38
|
+
if (x!=0) {
|
39
|
+
STORE_INT(idx1,e,count);
|
40
|
+
idx1 += e;
|
41
|
+
}
|
42
|
+
count++;
|
43
|
+
}
|
44
|
+
} else {
|
45
|
+
for (; i--;) {
|
46
|
+
LOAD_BIT(a, p, x);
|
47
|
+
p+=s;
|
48
|
+
if (x!=0) {
|
49
|
+
STORE_INT(idx1,e,count);
|
50
|
+
idx1 += e;
|
51
|
+
}
|
52
|
+
count++;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
g->count = count;
|
56
|
+
g->idx1 = idx1;
|
57
|
+
}
|
58
|
+
|
59
|
+
/*
|
60
|
+
Returns the array of index where the bit is one (true).
|
61
|
+
@overload <%=op_map%>
|
62
|
+
@return [Cumo::Int32,Cumo::Int64]
|
63
|
+
*/
|
64
|
+
static VALUE
|
65
|
+
<%=c_func(0)%>(VALUE self)
|
66
|
+
{
|
67
|
+
volatile VALUE idx_1;
|
68
|
+
size_t size, n_1;
|
69
|
+
where_opt_t *g;
|
70
|
+
|
71
|
+
ndfunc_arg_in_t ain[1] = {{cT,0}};
|
72
|
+
ndfunc_t ndf = { <%=c_iter%>, FULL_LOOP, 1, 0, ain, 0 };
|
73
|
+
|
74
|
+
size = RNARRAY_SIZE(self);
|
75
|
+
n_1 = NUM2SIZET(<%=find_tmpl("count_true_cpu").c_func%>(0, NULL, self));
|
76
|
+
g = ALLOCA_N(where_opt_t,1);
|
77
|
+
g->count = 0;
|
78
|
+
if (size>4294967295ul) {
|
79
|
+
idx_1 = nary_new(cumo_cInt64, 1, &n_1);
|
80
|
+
g->elmsz = 8;
|
81
|
+
} else {
|
82
|
+
idx_1 = nary_new(cumo_cInt32, 1, &n_1);
|
83
|
+
g->elmsz = 4;
|
84
|
+
}
|
85
|
+
g->idx1 = na_get_pointer_for_write(idx_1);
|
86
|
+
g->idx0 = NULL;
|
87
|
+
na_ndloop3(&ndf, g, 1, self);
|
88
|
+
na_release_lock(idx_1);
|
89
|
+
return idx_1;
|
90
|
+
}
|