tensor_stream 0.3.0 → 0.4.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/.circleci/config.yml +7 -7
- data/CHANGELOG.md +13 -0
- data/Dockerfile +25 -0
- data/Rakefile +6 -0
- data/benchmark/benchmark.rb +16 -57
- data/benchmark_intel.txt +21 -0
- data/benchmark_nvidia.txt +33 -0
- data/lib/tensor_stream.rb +4 -173
- data/lib/tensor_stream/debugging/debugging.rb +20 -0
- data/lib/tensor_stream/evaluator/kernels/abs.cl +9 -5
- data/lib/tensor_stream/evaluator/kernels/add.cl +2 -4
- data/lib/tensor_stream/evaluator/kernels/argmax.cl +2 -9
- data/lib/tensor_stream/evaluator/kernels/argmin.cl +2 -9
- data/lib/tensor_stream/evaluator/kernels/cast.cl +3 -8
- data/lib/tensor_stream/evaluator/kernels/cond.cl.erb +1 -1
- data/lib/tensor_stream/evaluator/kernels/cos.cl +2 -1
- data/lib/tensor_stream/evaluator/kernels/div.cl.erb +2 -4
- data/lib/tensor_stream/evaluator/kernels/exp.cl +2 -1
- data/lib/tensor_stream/evaluator/kernels/gemm.cl +8 -39
- data/lib/tensor_stream/evaluator/kernels/log.cl +2 -1
- data/lib/tensor_stream/evaluator/kernels/log1p.cl +2 -1
- data/lib/tensor_stream/evaluator/kernels/max.cl +4 -49
- data/lib/tensor_stream/evaluator/kernels/mul.cl +2 -4
- data/lib/tensor_stream/evaluator/kernels/negate.cl +2 -9
- data/lib/tensor_stream/evaluator/kernels/pow.cl +4 -88
- data/lib/tensor_stream/evaluator/kernels/reciprocal.cl +2 -9
- data/lib/tensor_stream/evaluator/kernels/round.cl +2 -1
- data/lib/tensor_stream/evaluator/kernels/sigmoid.cl +2 -1
- data/lib/tensor_stream/evaluator/kernels/sigmoid_grad.cl +6 -5
- data/lib/tensor_stream/evaluator/kernels/sign.cl +12 -14
- data/lib/tensor_stream/evaluator/kernels/sin.cl +2 -1
- data/lib/tensor_stream/evaluator/kernels/softmax.cl +26 -0
- data/lib/tensor_stream/evaluator/kernels/softmax_grad.cl +46 -0
- data/lib/tensor_stream/evaluator/kernels/sqrt.cl +2 -1
- data/lib/tensor_stream/evaluator/kernels/square.cl +2 -8
- data/lib/tensor_stream/evaluator/kernels/sub.cl +2 -4
- data/lib/tensor_stream/evaluator/kernels/tan.cl +2 -1
- data/lib/tensor_stream/evaluator/kernels/tanh.cl +2 -1
- data/lib/tensor_stream/evaluator/kernels/tanh_grad.cl +2 -1
- data/lib/tensor_stream/evaluator/kernels/where.cl +2 -9
- data/lib/tensor_stream/evaluator/opencl_evaluator.rb +108 -58
- data/lib/tensor_stream/evaluator/opencl_template_helper.rb +40 -5
- data/lib/tensor_stream/evaluator/operation_helpers/array_ops_helper.rb +35 -0
- data/lib/tensor_stream/evaluator/ruby_evaluator.rb +30 -9
- data/lib/tensor_stream/graph_serializers/graphml.rb +1 -1
- data/lib/tensor_stream/graph_serializers/pbtext.rb +4 -0
- data/lib/tensor_stream/math_gradients.rb +6 -5
- data/lib/tensor_stream/nn/nn_ops.rb +18 -2
- data/lib/tensor_stream/ops.rb +237 -44
- data/lib/tensor_stream/tensor.rb +16 -2
- data/lib/tensor_stream/utils.rb +205 -0
- data/lib/tensor_stream/variable.rb +2 -1
- data/lib/tensor_stream/version.rb +1 -1
- data/samples/error.graphml +2755 -0
- data/{test_samples → samples}/iris.rb +18 -24
- data/samples/logistic_regression.rb +0 -1
- data/test_samples/raw_neural_net_sample.rb +80 -23
- metadata +11 -3
@@ -0,0 +1,20 @@
|
|
1
|
+
module TensorStream
|
2
|
+
module Debugging
|
3
|
+
extend TensorStream::OpHelper
|
4
|
+
|
5
|
+
def add_check_numerics_ops
|
6
|
+
graph = TensorStream.get_default_graph
|
7
|
+
nodes_to_process = graph.nodes.values.select { |node| node.is_a?(Operation) }
|
8
|
+
|
9
|
+
nodes_to_process.each do |node|
|
10
|
+
node.items = node.items.compact.collect do |item|
|
11
|
+
if TensorStream::Ops::FLOATING_POINT_TYPES.include?(item.data_type)
|
12
|
+
TensorStream.check_numerics(item, "#{node.name}/#{item.name}", name: "check/#{node.name}/#{item.name}" )
|
13
|
+
else
|
14
|
+
item
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,16 +1,20 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
% c_dtype = dtype_to_c_type(dtype)
|
2
|
+
% if TensorStream::Ops::FLOATING_POINT_TYPES.include?(dtype)
|
3
|
+
__kernel void abs_<%= dtype%>(const int M, const int N, __global const <%= c_dtype %> *A, __global <%= c_dtype %> *C) {
|
3
4
|
// Get the index of the current element to be processed
|
4
5
|
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
5
6
|
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
6
7
|
|
7
8
|
C[globalRow * N + globalCol] = fabs(A[globalRow * N + globalCol]);
|
8
9
|
}
|
9
|
-
|
10
|
-
|
10
|
+
% else
|
11
|
+
% %w[int int32].each do |dt|
|
12
|
+
__kernel void abs_<%= dt %>(const int M, const int N, __global const <%= c_dtype %> *A, __global <%= c_dtype %> *C) {
|
11
13
|
// Get the index of the current element to be processed
|
12
14
|
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
13
15
|
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
14
16
|
|
15
17
|
C[globalRow * N + globalCol] = fabs((float)A[globalRow * N + globalCol]);
|
16
|
-
}
|
18
|
+
}
|
19
|
+
% end
|
20
|
+
%end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
% %w[fp int].product(%w[add]).each do |dtype, fname|
|
2
1
|
% c_dtype = dtype_to_c_type(dtype)
|
3
|
-
% op = operator_to_c(
|
4
|
-
<%= render 'operand.cl', c_dtype: c_dtype, op: op, fname:
|
5
|
-
% end
|
2
|
+
% op = operator_to_c('add')
|
3
|
+
<%= render 'operand.cl', c_dtype: c_dtype, op: op, fname: 'add', dtype: dtype, result_t: c_dtype %>
|
@@ -1,12 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
4
|
-
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
5
|
-
|
6
|
-
C[globalRow * N + globalCol] = A[globalRow * N + globalCol] + B[globalRow * N + globalCol];
|
7
|
-
}
|
8
|
-
|
9
|
-
__kernel void argmax_int(const int M, const int N, const int switch_op, __global const int *A, __global const int *B, __global int *C) {
|
1
|
+
% c_dtype = dtype_to_c_type(dtype)
|
2
|
+
__kernel void argmax_<%= dtype %>(const int M, const int N, const int switch_op, __global const <%= c_dtype %> *A, __global const <%= c_dtype %> *B, __global <%= c_dtype %> *C) {
|
10
3
|
// Get the index of the current element to be processed
|
11
4
|
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
12
5
|
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
@@ -1,12 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
4
|
-
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
5
|
-
|
6
|
-
C[globalRow * N + globalCol] = A[globalRow * N + globalCol] + B[globalRow * N + globalCol];
|
7
|
-
}
|
8
|
-
|
9
|
-
__kernel void argmin_int(const int M, const int N, const int switch_op, __global const int *A, __global const int *B, __global int *C) {
|
1
|
+
% c_dtype = dtype_to_c_type(dtype)
|
2
|
+
__kernel void argmin_<%= dtype %>(const int M, const int N, const int switch_op, __global const <%= c_dtype %> *A, __global const <%= c_dtype %> *B, __global <%= c_dtype %> *C) {
|
10
3
|
// Get the index of the current element to be processed
|
11
4
|
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
12
5
|
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
@@ -1,12 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
4
|
-
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
5
|
-
|
6
|
-
C[globalRow * N + globalCol] = A[globalRow * N + globalCol];
|
7
|
-
}
|
1
|
+
% source_ctype = dtype_to_c_type(source_dt)
|
2
|
+
% target_ctype = dtype_to_c_type(target_dt)
|
8
3
|
|
9
|
-
|
4
|
+
__kernel void cast(const int M, const int N, __global const <%= source_ctype %> *A, __global <%= target_ctype %> *C) {
|
10
5
|
// Get the index of the current element to be processed
|
11
6
|
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
12
7
|
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
%
|
1
|
+
% ["#{dtype}"].product(%w[less less_equal equal not_equal greater greater_equal logical_and]).each do |dtype, fname|
|
2
2
|
% c_dtype = dtype_to_c_type(dtype)
|
3
3
|
% op = operator_to_c(fname)
|
4
4
|
<%= render 'bool_operand.cl', c_dtype: c_dtype, op: op, fname: fname, dtype: dtype, result_t: 'int' %>
|
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
% c_dtype = dtype_to_c_type(dtype)
|
2
|
+
__kernel void cos_<%= dtype %>(const int M, const int N, __global const <%= c_dtype %> *A, __global <%= c_dtype %> *C) {
|
2
3
|
// Get the index of the current element to be processed
|
3
4
|
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
4
5
|
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
@@ -1,5 +1,3 @@
|
|
1
|
-
% %w[fp int].product(%w[div]).each do |dtype, fname|
|
2
1
|
% c_dtype = dtype_to_c_type(dtype)
|
3
|
-
% op = operator_to_c(
|
4
|
-
<%= render 'operand.cl', c_dtype: c_dtype, op: op, fname:
|
5
|
-
% end
|
2
|
+
% op = operator_to_c('div')
|
3
|
+
<%= render 'operand.cl', c_dtype: c_dtype, op: op, fname: 'div', dtype: dtype, result_t: c_dtype %>
|
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
% c_dtype = dtype_to_c_type(dtype)
|
2
|
+
__kernel void exp_<%= dtype %>(const int M, const int N, __global const <%= c_dtype %> *A, __global <%= c_dtype %> *C) {
|
2
3
|
// Get the index of the current element to be processed
|
3
4
|
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
4
5
|
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
@@ -1,49 +1,18 @@
|
|
1
1
|
// First naive implementation
|
2
|
-
|
2
|
+
% c_dtype = dtype_to_c_type(dtype)
|
3
|
+
__kernel void gemm_<%= dtype %>(const int M, const int N, const int K,
|
3
4
|
const int A_transpose,
|
4
5
|
const int B_transpose,
|
5
|
-
const __global
|
6
|
-
const __global
|
7
|
-
__global
|
8
|
-
|
9
|
-
// Get the index of the current element to be processed
|
10
|
-
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
11
|
-
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
12
|
-
|
13
|
-
// Compute a single element (loop over K)
|
14
|
-
float acc = 0.0f;
|
15
|
-
for (int k=0; k<K; k++) {
|
16
|
-
int a_index = globalRow*K + k;
|
17
|
-
int b_index = k*N + globalCol;
|
18
|
-
|
19
|
-
if (A_transpose) {
|
20
|
-
a_index = M*k + globalRow;
|
21
|
-
}
|
22
|
-
|
23
|
-
if (B_transpose) {
|
24
|
-
b_index = globalCol*K + k;
|
25
|
-
}
|
26
|
-
acc += A[a_index] * B[b_index];
|
27
|
-
}
|
28
|
-
|
29
|
-
// Store the result
|
30
|
-
C[globalRow*N + globalCol] = acc;
|
31
|
-
}
|
6
|
+
const __global <%= c_dtype %>* A,
|
7
|
+
const __global <%= c_dtype %>* B,
|
8
|
+
__global <%= c_dtype %>* C) {
|
32
9
|
|
33
|
-
// First naive implementation
|
34
|
-
__kernel void gemm_int(const int M, const int N, const int K,
|
35
|
-
const int A_transpose,
|
36
|
-
const int B_transpose,
|
37
|
-
const __global int* A,
|
38
|
-
const __global int* B,
|
39
|
-
__global int* C) {
|
40
|
-
|
41
10
|
// Get the index of the current element to be processed
|
42
11
|
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
43
12
|
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
44
|
-
|
13
|
+
|
45
14
|
// Compute a single element (loop over K)
|
46
|
-
|
15
|
+
<%= c_dtype %> acc = 0.0f;
|
47
16
|
for (int k=0; k<K; k++) {
|
48
17
|
int a_index = globalRow*K + k;
|
49
18
|
int b_index = k*N + globalCol;
|
@@ -57,7 +26,7 @@ __kernel void gemm_int(const int M, const int N, const int K,
|
|
57
26
|
}
|
58
27
|
acc += A[a_index] * B[b_index];
|
59
28
|
}
|
60
|
-
|
29
|
+
|
61
30
|
// Store the result
|
62
31
|
C[globalRow*N + globalCol] = acc;
|
63
32
|
}
|
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
% c_dtype = dtype_to_c_type(dtype)
|
2
|
+
__kernel void log_<%= dtype %>(const int M, const int N, __global const <%= c_dtype %> *A, __global <%= c_dtype %> *C) {
|
2
3
|
// Get the index of the current element to be processed
|
3
4
|
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
4
5
|
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
% c_dtype = dtype_to_c_type(dtype)
|
2
|
+
__kernel void log1p_<%= dtype %>(const int M, const int N, __global const <%= c_dtype %> *A, __global <%= c_dtype %> *C) {
|
2
3
|
// Get the index of the current element to be processed
|
3
4
|
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
4
5
|
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
@@ -1,5 +1,6 @@
|
|
1
1
|
// same dimension add floating point op
|
2
|
-
|
2
|
+
% c_dtype = dtype_to_c_type(dtype)
|
3
|
+
__kernel void max_<%= dtype %>(const int M, const int N, const int switch_op, __global const <%= c_dtype %> *A, __global const <%= c_dtype %> *B, __global <%= c_dtype %> *C) {
|
3
4
|
// Get the index of the current element to be processed
|
4
5
|
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
5
6
|
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
@@ -8,7 +9,7 @@
|
|
8
9
|
}
|
9
10
|
|
10
11
|
// 1D + Scalar floating point add op
|
11
|
-
__kernel void
|
12
|
+
__kernel void max_c_<%= dtype %>(const int M, const int N, const int switch_op, __global const <%= c_dtype %> *A, __global const <%= c_dtype %> *B, __global <%= c_dtype %> *C) {
|
12
13
|
// Get the index of the current element to be processed
|
13
14
|
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
14
15
|
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
@@ -21,7 +22,7 @@
|
|
21
22
|
}
|
22
23
|
|
23
24
|
// 1D + Scalar floating point add op broadcast
|
24
|
-
__kernel void
|
25
|
+
__kernel void max_b_<%= dtype %>(const int M, const int N, const int M2, const int N2, const int switch_op, __global const <%= c_dtype %> *A, __global const <%= c_dtype %> *B, __global <%= c_dtype %> *C) {
|
25
26
|
// Get the index of the current element to be processed
|
26
27
|
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
27
28
|
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
@@ -42,50 +43,4 @@
|
|
42
43
|
} else {
|
43
44
|
C[globalRow * N + globalCol] = B[b_m_index * N2 + b_n_index] > A[globalRow * N + globalCol] ? B[b_m_index * N2 + b_n_index] : A[globalRow * N + globalCol];
|
44
45
|
}
|
45
|
-
}
|
46
|
-
|
47
|
-
// same dimension add floating point op
|
48
|
-
__kernel void max_int(const int M, const int N, const int switch_op, __global const int *A, __global const int *B, __global int *C) {
|
49
|
-
// Get the index of the current element to be processed
|
50
|
-
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
51
|
-
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
52
|
-
|
53
|
-
C[globalRow * N + globalCol] = A[globalRow * N + globalCol] > B[globalRow * N + globalCol] ? A[globalRow * N + globalCol] : B[globalRow * N + globalCol];
|
54
|
-
}
|
55
|
-
|
56
|
-
// 1D + Scalar floating point add op
|
57
|
-
__kernel void max_c_int(const int M, const int N, const int switch_op, __global const int *A, __global const int *B, __global int *C) {
|
58
|
-
// Get the index of the current element to be processed
|
59
|
-
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
60
|
-
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
61
|
-
|
62
|
-
if (switch_op == 0) {
|
63
|
-
C[globalRow * N + globalCol] = A[globalRow * N + globalCol] > B[0] ? A[globalRow * N + globalCol] : B[0];
|
64
|
-
} else {
|
65
|
-
C[globalRow * N + globalCol] = B[0] > A[globalRow * N + globalCol] ? B[0] : A[globalRow * N + globalCol];
|
66
|
-
}
|
67
|
-
}
|
68
|
-
|
69
|
-
// 1D + Scalar floating point add op broadcast
|
70
|
-
__kernel void max_b_int(const int M, const int N, const int M2, const int N2, const int switch_op, __global const int *A, __global const int *B, __global int *C) {
|
71
|
-
// Get the index of the current element to be processed
|
72
|
-
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
73
|
-
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
74
|
-
|
75
|
-
int b_m_index = globalRow;
|
76
|
-
int b_n_index = globalCol;
|
77
|
-
|
78
|
-
if ( b_m_index >= M2) {
|
79
|
-
b_m_index = b_m_index % M2;
|
80
|
-
};
|
81
|
-
|
82
|
-
if (b_n_index >= N2) {
|
83
|
-
b_n_index = b_n_index % N2;
|
84
|
-
}
|
85
|
-
|
86
|
-
if (switch_op == 0) {
|
87
|
-
C[globalRow * N + globalCol] = A[globalRow * N + globalCol] > B[b_m_index * N2 + b_n_index] ? A[globalRow * N + globalCol] : B[b_m_index * N2 + b_n_index];
|
88
|
-
} else {
|
89
|
-
C[globalRow * N + globalCol] = B[b_m_index * N2 + b_n_index] > A[globalRow * N + globalCol] ? B[b_m_index * N2 + b_n_index] : A[globalRow * N + globalCol];
|
90
|
-
}
|
91
46
|
}
|
@@ -1,5 +1,3 @@
|
|
1
|
-
% %w[fp int].product(%w[mul]).each do |dtype, fname|
|
2
1
|
% c_dtype = dtype_to_c_type(dtype)
|
3
|
-
% op = operator_to_c(
|
4
|
-
<%= render 'operand.cl', c_dtype: c_dtype, op: op, fname:
|
5
|
-
% end
|
2
|
+
% op = operator_to_c('mul')
|
3
|
+
<%= render 'operand.cl', c_dtype: c_dtype, op: op, fname: 'mul', dtype: dtype, result_t: c_dtype %>
|
@@ -1,12 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
4
|
-
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
5
|
-
|
6
|
-
C[globalRow * N + globalCol] = -A[globalRow * N + globalCol];
|
7
|
-
}
|
8
|
-
|
9
|
-
__kernel void negate_int(const int M, const int N, __global const int *A, __global int *C) {
|
1
|
+
% c_dtype = dtype_to_c_type(dtype)
|
2
|
+
__kernel void negate_<%= dtype %>(const int M, const int N, __global const <%= c_dtype %> *A, __global <%= c_dtype %> *C) {
|
10
3
|
// Get the index of the current element to be processed
|
11
4
|
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
12
5
|
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
@@ -1,5 +1,6 @@
|
|
1
1
|
// same dimension add floating point op
|
2
|
-
|
2
|
+
% c_dtype = dtype_to_c_type(dtype)
|
3
|
+
__kernel void pow_<%= dtype %>(const int M, const int N, const int switch_op, __global const <%= c_dtype %> *A, __global const <%= c_dtype %> *B, __global <%= c_dtype %> *C) {
|
3
4
|
// Get the index of the current element to be processed
|
4
5
|
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
5
6
|
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
@@ -8,7 +9,7 @@
|
|
8
9
|
}
|
9
10
|
|
10
11
|
// 1D + Scalar floating point add op
|
11
|
-
__kernel void
|
12
|
+
__kernel void pow_c_<%= dtype %>(const int M, const int N, const int switch_op, __global const <%= c_dtype %> *A, __global const <%= c_dtype %> *B, __global <%= c_dtype %> *C) {
|
12
13
|
// Get the index of the current element to be processed
|
13
14
|
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
14
15
|
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
@@ -21,7 +22,7 @@
|
|
21
22
|
}
|
22
23
|
|
23
24
|
// 1D + Scalar floating point add op broadcast
|
24
|
-
__kernel void
|
25
|
+
__kernel void pow_b_<%= dtype %>(const int M, const int N, const int M2, const int N2, const int switch_op, __global const <%= c_dtype %> *A, __global const <%= c_dtype %> *B, __global <%= c_dtype %> *C) {
|
25
26
|
// Get the index of the current element to be processed
|
26
27
|
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
27
28
|
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
@@ -42,89 +43,4 @@
|
|
42
43
|
} else {
|
43
44
|
C[globalRow * N + globalCol] = pow((float)B[b_m_index * N2 + b_n_index], (float)A[globalRow * N + globalCol]);
|
44
45
|
}
|
45
|
-
}
|
46
|
-
|
47
|
-
// same dimension add floating point op
|
48
|
-
__kernel void pow_int(const int M, const int N, const int switch_op, __global const int *A, __global const int *B, __global int *C) {
|
49
|
-
// Get the index of the current element to be processed
|
50
|
-
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
51
|
-
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
52
|
-
|
53
|
-
int acc = A[globalRow * N + globalCol];
|
54
|
-
const int count = B[globalRow * N + globalCol];
|
55
|
-
const int c = A[globalRow * N + globalCol];
|
56
|
-
|
57
|
-
if (count < 4) {
|
58
|
-
for(int i = 0; i < count - 1; i++) {
|
59
|
-
acc *= c;
|
60
|
-
}
|
61
|
-
C[globalRow * N + globalCol] = acc;
|
62
|
-
} else {
|
63
|
-
C[globalRow * N + globalCol] = pow((float)c, (float)count);
|
64
|
-
}
|
65
|
-
}
|
66
|
-
|
67
|
-
// 1D + Scalar floating point add op
|
68
|
-
__kernel void pow_c_int(const int M, const int N, const int switch_op, __global const int *A, __global const int *B, __global int *C) {
|
69
|
-
// Get the index of the current element to be processed
|
70
|
-
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
71
|
-
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
72
|
-
|
73
|
-
int acc, count, c;
|
74
|
-
if (switch_op == 0) {
|
75
|
-
acc = A[globalRow * N + globalCol];
|
76
|
-
count = B[0];
|
77
|
-
c = A[globalRow * N + globalCol];
|
78
|
-
} else {
|
79
|
-
acc = B[0];
|
80
|
-
count = A[globalRow * N + globalCol];
|
81
|
-
c = B[0];
|
82
|
-
}
|
83
|
-
if (count < 4) {
|
84
|
-
for(int i =0; i < count - 1; i++) {
|
85
|
-
acc *= c;
|
86
|
-
}
|
87
|
-
C[globalRow * N + globalCol] = acc;
|
88
|
-
} else {
|
89
|
-
C[globalRow * N + globalCol] = pow((float)c, (float)count);
|
90
|
-
}
|
91
|
-
}
|
92
|
-
|
93
|
-
// 1D + Scalar floating point add op broadcast
|
94
|
-
__kernel void pow_b_int(const int M, const int N, const int M2, const int N2, const int switch_op, __global const int *A, __global const int *B, __global int *C) {
|
95
|
-
// Get the index of the current element to be processed
|
96
|
-
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
97
|
-
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
98
|
-
|
99
|
-
int b_m_index = globalRow;
|
100
|
-
int b_n_index = globalCol;
|
101
|
-
|
102
|
-
if ( b_m_index >= M2) {
|
103
|
-
b_m_index = b_m_index % M2;
|
104
|
-
};
|
105
|
-
|
106
|
-
if (b_n_index >= N2) {
|
107
|
-
b_n_index = b_n_index % N2;
|
108
|
-
}
|
109
|
-
|
110
|
-
int acc, count, c;
|
111
|
-
|
112
|
-
if (switch_op == 0) {
|
113
|
-
acc = A[globalRow * N + globalCol];
|
114
|
-
count = B[b_m_index * N2 + b_n_index];
|
115
|
-
c = A[globalRow * N + globalCol];
|
116
|
-
} else {
|
117
|
-
acc = B[b_m_index * N2 + b_n_index];
|
118
|
-
count = A[globalRow * N + globalCol];
|
119
|
-
c = B[b_m_index * N2 + b_n_index];
|
120
|
-
}
|
121
|
-
|
122
|
-
if (count < 4) {
|
123
|
-
for (int i = 0; i < count - 1; i++) {
|
124
|
-
acc *= c;
|
125
|
-
}
|
126
|
-
C[globalRow * N + globalCol] = acc;
|
127
|
-
} else {
|
128
|
-
C[globalRow * N + globalCol] = pow((float)c, (float)count);
|
129
|
-
}
|
130
46
|
}
|
@@ -1,12 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
4
|
-
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|
5
|
-
|
6
|
-
C[globalRow * N + globalCol] = 1.0f / A[globalRow * N + globalCol];
|
7
|
-
}
|
8
|
-
|
9
|
-
__kernel void reciprocal_int(const int M, const int N, __global const int *A, __global int *C) {
|
1
|
+
% c_dtype = dtype_to_c_type(dtype)
|
2
|
+
__kernel void reciprocal_<%= dtype %>(const int M, const int N, __global const <%= c_dtype %> *A, __global <%= c_dtype %> *C) {
|
10
3
|
// Get the index of the current element to be processed
|
11
4
|
const int globalRow = get_global_id(0); // Row ID of C (0..M)
|
12
5
|
const int globalCol = get_global_id(1); // Col ID of C (0..N)
|