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,66 @@
|
|
1
|
+
<% unless c_iter.include? 'robject' %>
|
2
|
+
__global__ void <%="cumo_#{c_iter}_index_index_kernel"%>(char *p1, size_t p2, BIT_DIGIT *a2, size_t *idx1, size_t *idx2, uint64_t n)
|
3
|
+
{
|
4
|
+
for (uint64_t i = blockIdx.x * blockDim.x + threadIdx.x; i < n; i += blockDim.x * gridDim.x) {
|
5
|
+
BIT_DIGIT x;
|
6
|
+
LOAD_BIT(a2, p2 + idx2[i], x);
|
7
|
+
*(dtype*)(p1 + idx1[i]) = m_from_real(x);
|
8
|
+
}
|
9
|
+
}
|
10
|
+
|
11
|
+
__global__ void <%="cumo_#{c_iter}_stride_index_kernel"%>(char *p1, size_t p2, BIT_DIGIT *a2, ssize_t s1, size_t *idx2, uint64_t n)
|
12
|
+
{
|
13
|
+
for (uint64_t i = blockIdx.x * blockDim.x + threadIdx.x; i < n; i += blockDim.x * gridDim.x) {
|
14
|
+
BIT_DIGIT x;
|
15
|
+
LOAD_BIT(a2, p2 + idx2[i], x);
|
16
|
+
*(dtype*)(p1 + (i * s1)) = m_from_real(x);
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
__global__ void <%="cumo_#{c_iter}_index_stride_kernel"%>(char *p1, size_t p2, BIT_DIGIT *a2, size_t *idx1, ssize_t s2, uint64_t n)
|
21
|
+
{
|
22
|
+
for (uint64_t i = blockIdx.x * blockDim.x + threadIdx.x; i < n; i += blockDim.x * gridDim.x) {
|
23
|
+
BIT_DIGIT x;
|
24
|
+
LOAD_BIT(a2, p2 + (i * s2), x);
|
25
|
+
*(dtype*)(p1 + idx1[i]) = m_from_real(x);
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
__global__ void <%="cumo_#{c_iter}_stride_stride_kernel"%>(char *p1, size_t p2, BIT_DIGIT *a2, ssize_t s1, ssize_t s2, uint64_t n)
|
30
|
+
{
|
31
|
+
for (uint64_t i = blockIdx.x * blockDim.x + threadIdx.x; i < n; i += blockDim.x * gridDim.x) {
|
32
|
+
BIT_DIGIT x;
|
33
|
+
LOAD_BIT(a2, p2 + (i * s2), x);
|
34
|
+
*(dtype*)(p1 + (i * s1)) = m_from_real(x);
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
void <%="cumo_#{c_iter}_index_index_kernel_launch"%>(char *p1, size_t p2, BIT_DIGIT *a2, size_t *idx1, size_t *idx2, uint64_t n)
|
39
|
+
{
|
40
|
+
size_t gridDim = get_gridDim(n);
|
41
|
+
size_t blockDim = get_blockDim(n);
|
42
|
+
<%="cumo_#{c_iter}_index_index_kernel"%><<<gridDim, blockDim>>>(p1,p2,a2,idx1,idx2,n);
|
43
|
+
}
|
44
|
+
|
45
|
+
void <%="cumo_#{c_iter}_stride_index_kernel_launch"%>(char *p1, size_t p2, BIT_DIGIT *a2, ssize_t s1, size_t *idx2, uint64_t n)
|
46
|
+
{
|
47
|
+
size_t gridDim = get_gridDim(n);
|
48
|
+
size_t blockDim = get_blockDim(n);
|
49
|
+
<%="cumo_#{c_iter}_stride_index_kernel"%><<<gridDim, blockDim>>>(p1,p2,a2,s1,idx2,n);
|
50
|
+
}
|
51
|
+
|
52
|
+
void <%="cumo_#{c_iter}_index_stride_kernel_launch"%>(char *p1, size_t p2, BIT_DIGIT *a2, size_t *idx1, ssize_t s2, uint64_t n)
|
53
|
+
{
|
54
|
+
size_t gridDim = get_gridDim(n);
|
55
|
+
size_t blockDim = get_blockDim(n);
|
56
|
+
<%="cumo_#{c_iter}_index_stride_kernel"%><<<gridDim, blockDim>>>(p1,p2,a2,idx1,s2,n);
|
57
|
+
}
|
58
|
+
|
59
|
+
void <%="cumo_#{c_iter}_stride_stride_kernel_launch"%>(char *p1, size_t p2, BIT_DIGIT *a2, ssize_t s1, ssize_t s2, uint64_t n)
|
60
|
+
{
|
61
|
+
size_t gridDim = get_gridDim(n);
|
62
|
+
size_t blockDim = get_blockDim(n);
|
63
|
+
<%="cumo_#{c_iter}_stride_stride_kernel"%><<<gridDim, blockDim>>>(p1,p2,a2,s1,s2,n);
|
64
|
+
}
|
65
|
+
|
66
|
+
<% end %>
|
@@ -0,0 +1,81 @@
|
|
1
|
+
//<% unless c_iter.include? 'robject' %>
|
2
|
+
void <%="cumo_#{c_iter}_index_index_kernel_launch"%>(char *p1, char *p2, size_t *idx1, size_t *idx2, uint64_t n);
|
3
|
+
void <%="cumo_#{c_iter}_stride_index_kernel_launch"%>(char *p1, char *p2, ssize_t s1, size_t *idx2, uint64_t n);
|
4
|
+
void <%="cumo_#{c_iter}_index_stride_kernel_launch"%>(char *p1, char *p2, size_t *idx1, ssize_t s2, uint64_t n);
|
5
|
+
void <%="cumo_#{c_iter}_stride_stride_kernel_launch"%>(char *p1, char *p2, ssize_t s1, ssize_t s2, uint64_t n);
|
6
|
+
//<% end %>
|
7
|
+
|
8
|
+
static void
|
9
|
+
<%=c_iter%>(na_loop_t *const lp)
|
10
|
+
{
|
11
|
+
size_t i, s1, s2;
|
12
|
+
char *p1, *p2;
|
13
|
+
size_t *idx1, *idx2;
|
14
|
+
|
15
|
+
INIT_COUNTER(lp, i);
|
16
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
17
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
18
|
+
//<% if c_iter.include? 'robject' %>
|
19
|
+
SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%>", "<%=type_name%>");
|
20
|
+
{
|
21
|
+
<%=dtype%> x;
|
22
|
+
dtype y;
|
23
|
+
if (idx2) {
|
24
|
+
if (idx1) {
|
25
|
+
for (; i--;) {
|
26
|
+
GET_DATA_INDEX(p2,idx2,<%=dtype%>,x);
|
27
|
+
y = <%=macro%>(x);
|
28
|
+
SET_DATA_INDEX(p1,idx1,dtype,y);
|
29
|
+
}
|
30
|
+
} else {
|
31
|
+
for (; i--;) {
|
32
|
+
GET_DATA_INDEX(p2,idx2,<%=dtype%>,x);
|
33
|
+
y = <%=macro%>(x);
|
34
|
+
SET_DATA_STRIDE(p1,s1,dtype,y);
|
35
|
+
}
|
36
|
+
}
|
37
|
+
} else {
|
38
|
+
if (idx1) {
|
39
|
+
for (; i--;) {
|
40
|
+
GET_DATA_STRIDE(p2,s2,<%=dtype%>,x);
|
41
|
+
y = <%=macro%>(x);
|
42
|
+
SET_DATA_INDEX(p1,idx1,dtype,y);
|
43
|
+
}
|
44
|
+
} else {
|
45
|
+
for (; i--;) {
|
46
|
+
GET_DATA_STRIDE(p2,s2,<%=dtype%>,x);
|
47
|
+
y = <%=macro%>(x);
|
48
|
+
SET_DATA_STRIDE(p1,s1,dtype,y);
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
//<% else %>
|
54
|
+
{
|
55
|
+
if (idx2) {
|
56
|
+
if (idx1) {
|
57
|
+
<%="cumo_#{c_iter}_index_index_kernel_launch"%>(p1,p2,idx1,idx2,i);
|
58
|
+
} else {
|
59
|
+
<%="cumo_#{c_iter}_stride_index_kernel_launch"%>(p1,p2,s1,idx2,i);
|
60
|
+
}
|
61
|
+
} else {
|
62
|
+
if (idx1) {
|
63
|
+
<%="cumo_#{c_iter}_index_stride_kernel_launch"%>(p1,p2,idx1,s2,i);
|
64
|
+
} else {
|
65
|
+
<%="cumo_#{c_iter}_stride_stride_kernel_launch"%>(p1,p2,s1,s2,i);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
//<% end %>
|
70
|
+
}
|
71
|
+
|
72
|
+
|
73
|
+
static VALUE
|
74
|
+
<%=c_func(:nodef)%>(VALUE self, VALUE obj)
|
75
|
+
{
|
76
|
+
ndfunc_arg_in_t ain[2] = {{OVERWRITE,0},{Qnil,0}};
|
77
|
+
ndfunc_t ndf = { <%=c_iter%>, FULL_LOOP, 2, 0, ain, 0 };
|
78
|
+
|
79
|
+
na_ndloop(&ndf, 2, self, obj);
|
80
|
+
return self;
|
81
|
+
}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
<% unless c_iter.include? 'robject' %>
|
2
|
+
__global__ void <%="cumo_#{c_iter}_index_index_kernel"%>(char *p1, char *p2, size_t *idx1, size_t *idx2, uint64_t n)
|
3
|
+
{
|
4
|
+
for (uint64_t i = blockIdx.x * blockDim.x + threadIdx.x; i < n; i += blockDim.x * gridDim.x) {
|
5
|
+
*(dtype*)(p1 + idx1[i]) = <%=macro%>(*(<%=dtype%>*)(p2 + idx2[i]));
|
6
|
+
}
|
7
|
+
}
|
8
|
+
|
9
|
+
__global__ void <%="cumo_#{c_iter}_stride_index_kernel"%>(char *p1, char *p2, ssize_t s1, size_t *idx2, uint64_t n)
|
10
|
+
{
|
11
|
+
for (uint64_t i = blockIdx.x * blockDim.x + threadIdx.x; i < n; i += blockDim.x * gridDim.x) {
|
12
|
+
*(dtype*)(p1 + (i * s1)) = <%=macro%>(*(<%=dtype%>*)(p2 + idx2[i]));
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
__global__ void <%="cumo_#{c_iter}_index_stride_kernel"%>(char *p1, char *p2, size_t *idx1, ssize_t s2, uint64_t n)
|
17
|
+
{
|
18
|
+
for (uint64_t i = blockIdx.x * blockDim.x + threadIdx.x; i < n; i += blockDim.x * gridDim.x) {
|
19
|
+
*(dtype*)(p1 + idx1[i]) = <%=macro%>(*(<%=dtype%>*)(p2 + (i * s2)));
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
__global__ void <%="cumo_#{c_iter}_stride_stride_kernel"%>(char *p1, char *p2, ssize_t s1, ssize_t s2, uint64_t n)
|
24
|
+
{
|
25
|
+
for (uint64_t i = blockIdx.x * blockDim.x + threadIdx.x; i < n; i += blockDim.x * gridDim.x) {
|
26
|
+
*(dtype*)(p1 + (i * s1)) = <%=macro%>(*(<%=dtype%>*)(p2 + (i * s2)));
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
void <%="cumo_#{c_iter}_index_index_kernel_launch"%>(char *p1, char *p2, size_t *idx1, size_t *idx2, uint64_t n)
|
31
|
+
{
|
32
|
+
size_t gridDim = get_gridDim(n);
|
33
|
+
size_t blockDim = get_blockDim(n);
|
34
|
+
<%="cumo_#{c_iter}_index_index_kernel"%><<<gridDim, blockDim>>>(p1,p2,idx1,idx2,n);
|
35
|
+
}
|
36
|
+
|
37
|
+
void <%="cumo_#{c_iter}_stride_index_kernel_launch"%>(char *p1, char *p2, ssize_t s1, size_t *idx2, uint64_t n)
|
38
|
+
{
|
39
|
+
size_t gridDim = get_gridDim(n);
|
40
|
+
size_t blockDim = get_blockDim(n);
|
41
|
+
<%="cumo_#{c_iter}_stride_index_kernel"%><<<gridDim, blockDim>>>(p1,p2,s1,idx2,n);
|
42
|
+
}
|
43
|
+
|
44
|
+
void <%="cumo_#{c_iter}_index_stride_kernel_launch"%>(char *p1, char *p2, size_t *idx1, ssize_t s2, uint64_t n)
|
45
|
+
{
|
46
|
+
size_t gridDim = get_gridDim(n);
|
47
|
+
size_t blockDim = get_blockDim(n);
|
48
|
+
<%="cumo_#{c_iter}_index_stride_kernel"%><<<gridDim, blockDim>>>(p1,p2,idx1,s2,n);
|
49
|
+
}
|
50
|
+
|
51
|
+
void <%="cumo_#{c_iter}_stride_stride_kernel_launch"%>(char *p1, char *p2, ssize_t s1, ssize_t s2, uint64_t n)
|
52
|
+
{
|
53
|
+
size_t gridDim = get_gridDim(n);
|
54
|
+
size_t blockDim = get_blockDim(n);
|
55
|
+
<%="cumo_#{c_iter}_stride_stride_kernel"%><<<gridDim, blockDim>>>(p1,p2,s1,s2,n);
|
56
|
+
}
|
57
|
+
|
58
|
+
<% end %>
|
@@ -0,0 +1,43 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t i, s1;
|
5
|
+
char *p1;
|
6
|
+
size_t *idx1;
|
7
|
+
dtype x;
|
8
|
+
volatile VALUE a, y;
|
9
|
+
|
10
|
+
INIT_COUNTER(lp, i);
|
11
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
12
|
+
a = rb_ary_new2(i);
|
13
|
+
rb_ary_push(lp->args[1].value, a);
|
14
|
+
//SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%>", "<%=type_name%>");
|
15
|
+
if (idx1) {
|
16
|
+
for (; i--;) {
|
17
|
+
GET_DATA_INDEX(p1,idx1,dtype,x);
|
18
|
+
y = m_data_to_num(x);
|
19
|
+
rb_ary_push(a,y);
|
20
|
+
}
|
21
|
+
} else {
|
22
|
+
for (; i--;) {
|
23
|
+
GET_DATA_STRIDE(p1,s1,dtype,x);
|
24
|
+
y = m_data_to_num(x);
|
25
|
+
rb_ary_push(a,y);
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
/*
|
31
|
+
Convert self to Array.
|
32
|
+
@overload <%=name%>
|
33
|
+
@return [Array]
|
34
|
+
*/
|
35
|
+
static VALUE
|
36
|
+
<%=c_func(0)%>(VALUE self)
|
37
|
+
{
|
38
|
+
ndfunc_arg_in_t ain[3] = {{Qnil,0},{sym_loop_opt},{sym_option}};
|
39
|
+
ndfunc_arg_out_t aout[1] = {{rb_cArray,0}}; // dummy?
|
40
|
+
ndfunc_t ndf = { <%=c_iter%>, FULL_LOOP_NIP, 3, 1, ain, aout };
|
41
|
+
cumo_cuda_runtime_check_status(cudaDeviceSynchronize());
|
42
|
+
return na_ndloop_cast_narray_to_rarray(&ndf, self, Qnil);
|
43
|
+
}
|
@@ -0,0 +1,132 @@
|
|
1
|
+
<% if type_name == 'robject' || name == 'map' %>
|
2
|
+
<% else %>
|
3
|
+
void <%="cumo_#{c_iter}_index_index_kernel_launch"%>(char *p1, char *p2, size_t *idx1, size_t *idx2, uint64_t n);
|
4
|
+
void <%="cumo_#{c_iter}_index_stride_kernel_launch"%>(char *p1, char *p2, size_t *idx1, ssize_t s2, uint64_t n);
|
5
|
+
void <%="cumo_#{c_iter}_stride_index_kernel_launch"%>(char *p1, char *p2, ssize_t s1, size_t *idx2, uint64_t n);
|
6
|
+
void <%="cumo_#{c_iter}_stride_stride_kernel_launch"%>(char *p1, char *p2, ssize_t s1, ssize_t s2, uint64_t n);
|
7
|
+
void <%="cumo_#{c_iter}_contiguous_kernel_launch"%>(char *p1, char *p2, uint64_t n);
|
8
|
+
<% end %>
|
9
|
+
|
10
|
+
static void
|
11
|
+
<%=c_iter%>(na_loop_t *const lp)
|
12
|
+
{
|
13
|
+
size_t n;
|
14
|
+
char *p1, *p2;
|
15
|
+
ssize_t s1, s2;
|
16
|
+
size_t *idx1, *idx2;
|
17
|
+
|
18
|
+
INIT_COUNTER(lp, n);
|
19
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
20
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
21
|
+
|
22
|
+
<% if type_name == 'robject' || name == 'map' %>
|
23
|
+
{
|
24
|
+
size_t i;
|
25
|
+
dtype x;
|
26
|
+
SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%>", "<%=type_name%>");
|
27
|
+
if (idx1) {
|
28
|
+
if (idx2) {
|
29
|
+
for (i=0; i<n; i++) {
|
30
|
+
GET_DATA_INDEX(p1,idx1,dtype,x);
|
31
|
+
x = m_<%=name%>(x);
|
32
|
+
SET_DATA_INDEX(p2,idx2,dtype,x);
|
33
|
+
}
|
34
|
+
} else {
|
35
|
+
for (i=0; i<n; i++) {
|
36
|
+
GET_DATA_INDEX(p1,idx1,dtype,x);
|
37
|
+
x = m_<%=name%>(x);
|
38
|
+
SET_DATA_STRIDE(p2,s2,dtype,x);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
} else {
|
42
|
+
if (idx2) {
|
43
|
+
for (i=0; i<n; i++) {
|
44
|
+
GET_DATA_STRIDE(p1,s1,dtype,x);
|
45
|
+
x = m_<%=name%>(x);
|
46
|
+
SET_DATA_INDEX(p2,idx2,dtype,x);
|
47
|
+
}
|
48
|
+
} else {
|
49
|
+
//<% if need_align %>
|
50
|
+
if (is_aligned(p1,sizeof(dtype)) &&
|
51
|
+
is_aligned(p2,sizeof(dtype)) ) {
|
52
|
+
if (s1 == sizeof(dtype) &&
|
53
|
+
s2 == sizeof(dtype) ) {
|
54
|
+
for (i=0; i<n; i++) {
|
55
|
+
((dtype*)p2)[i] = m_<%=name%>(((dtype*)p1)[i]);
|
56
|
+
}
|
57
|
+
return;
|
58
|
+
}
|
59
|
+
if (is_aligned_step(s1,sizeof(dtype)) &&
|
60
|
+
is_aligned_step(s2,sizeof(dtype)) ) {
|
61
|
+
//<% end %>
|
62
|
+
for (i=0; i<n; i++) {
|
63
|
+
*(dtype*)p2 = m_<%=name%>(*(dtype*)p1);
|
64
|
+
p1 += s1;
|
65
|
+
p2 += s2;
|
66
|
+
}
|
67
|
+
return;
|
68
|
+
//<% if need_align %>
|
69
|
+
}
|
70
|
+
}
|
71
|
+
for (i=0; i<n; i++) {
|
72
|
+
GET_DATA_STRIDE(p1,s1,dtype,x);
|
73
|
+
x = m_<%=name%>(x);
|
74
|
+
SET_DATA_STRIDE(p2,s2,dtype,x);
|
75
|
+
}
|
76
|
+
//<% end %>
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}
|
80
|
+
<% else %>
|
81
|
+
{
|
82
|
+
if (idx1) {
|
83
|
+
if (idx2) {
|
84
|
+
<%="cumo_#{c_iter}_index_index_kernel_launch"%>(p1,p2,idx1,idx2,n);
|
85
|
+
} else {
|
86
|
+
<%="cumo_#{c_iter}_index_stride_kernel_launch"%>(p1,p2,idx1,s2,n);
|
87
|
+
}
|
88
|
+
} else {
|
89
|
+
if (idx2) {
|
90
|
+
<%="cumo_#{c_iter}_stride_index_kernel_launch"%>(p1,p2,s1,idx2,n);
|
91
|
+
} else {
|
92
|
+
//<% if need_align %>
|
93
|
+
if (is_aligned(p1,sizeof(dtype)) &&
|
94
|
+
is_aligned(p2,sizeof(dtype)) ) {
|
95
|
+
if (s1 == sizeof(dtype) &&
|
96
|
+
s2 == sizeof(dtype) ) {
|
97
|
+
<%="cumo_#{c_iter}_contiguous_kernel_launch"%>(p1,p2,n);
|
98
|
+
return;
|
99
|
+
}
|
100
|
+
if (is_aligned_step(s1,sizeof(dtype)) &&
|
101
|
+
is_aligned_step(s2,sizeof(dtype)) ) {
|
102
|
+
//<% end %>
|
103
|
+
<%="cumo_#{c_iter}_stride_stride_kernel_launch"%>(p1,p2,s1,s2,n);
|
104
|
+
return;
|
105
|
+
//<% if need_align %>
|
106
|
+
}
|
107
|
+
}
|
108
|
+
<%="cumo_#{c_iter}_stride_stride_kernel_launch"%>(p1,p2,s1,s2,n);
|
109
|
+
//<% end %>
|
110
|
+
}
|
111
|
+
}
|
112
|
+
}
|
113
|
+
<% end %>
|
114
|
+
}
|
115
|
+
|
116
|
+
/*
|
117
|
+
Unary <%=name%>.
|
118
|
+
@overload <%=op_map%>
|
119
|
+
@return [Cumo::<%=class_name%>] <%=name%> of self.
|
120
|
+
*/
|
121
|
+
static VALUE
|
122
|
+
<%=c_func(0)%>(VALUE self)
|
123
|
+
{
|
124
|
+
ndfunc_arg_in_t ain[1] = {{cT,0}};
|
125
|
+
ndfunc_arg_out_t aout[1] = {{cT,0}};
|
126
|
+
ndfunc_t ndf = {<%=c_iter%>, FULL_LOOP, 1,1, ain,aout};
|
127
|
+
|
128
|
+
<% if name == 'map' %>
|
129
|
+
cumo_cuda_runtime_check_status(cudaDeviceSynchronize());
|
130
|
+
<% end %>
|
131
|
+
return na_ndloop(&ndf, 1, self);
|
132
|
+
}
|
@@ -0,0 +1,60 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t i;
|
5
|
+
char *p1, *p2;
|
6
|
+
ssize_t s1, s2;
|
7
|
+
size_t *idx1, *idx2;
|
8
|
+
dtype x;
|
9
|
+
<%=dtype%> y;
|
10
|
+
INIT_COUNTER(lp, i);
|
11
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
12
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
13
|
+
SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%>", "<%=type_name%>");
|
14
|
+
cumo_cuda_runtime_check_status(cudaDeviceSynchronize());
|
15
|
+
if (idx1) {
|
16
|
+
if (idx2) {
|
17
|
+
for (; i--;) {
|
18
|
+
GET_DATA_INDEX(p1,idx1,dtype,x);
|
19
|
+
y = m_<%=name%>(x);
|
20
|
+
SET_DATA_INDEX(p2,idx2,<%=dtype%>,y);
|
21
|
+
}
|
22
|
+
} else {
|
23
|
+
for (; i--;) {
|
24
|
+
GET_DATA_INDEX(p1,idx1,dtype,x);
|
25
|
+
y = m_<%=name%>(x);
|
26
|
+
SET_DATA_STRIDE(p2,s2,<%=dtype%>,y);
|
27
|
+
}
|
28
|
+
}
|
29
|
+
} else {
|
30
|
+
if (idx2) {
|
31
|
+
for (; i--;) {
|
32
|
+
GET_DATA_STRIDE(p1,s1,dtype,x);
|
33
|
+
y = m_<%=name%>(x);
|
34
|
+
SET_DATA_INDEX(p2,idx2,<%=dtype%>,y);
|
35
|
+
}
|
36
|
+
} else {
|
37
|
+
for (; i--;) {
|
38
|
+
GET_DATA_STRIDE(p1,s1,dtype,x);
|
39
|
+
y = m_<%=name%>(x);
|
40
|
+
SET_DATA_STRIDE(p2,s2,<%=dtype%>,y);
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
|
47
|
+
/*
|
48
|
+
<%=name%> of self.
|
49
|
+
@overload <%=name%>
|
50
|
+
@return [Cumo::<%=real_class_name%>] <%=name%> of self.
|
51
|
+
*/
|
52
|
+
static VALUE
|
53
|
+
<%=c_func(0)%>(VALUE self)
|
54
|
+
{
|
55
|
+
ndfunc_arg_in_t ain[1] = {{cT,0}};
|
56
|
+
ndfunc_arg_out_t aout[1] = {{<%=result_class%>,0}};
|
57
|
+
ndfunc_t ndf = { <%=c_iter%>, FULL_LOOP, 1, 1, ain, aout };
|
58
|
+
|
59
|
+
return na_ndloop(&ndf, 1, self);
|
60
|
+
}
|