1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
import ctypes
from _base import _LIB
import ndarray as _nd
def array_set(arr, value):
assert isinstance(arr, _nd.NDArray)
_LIB.DLGpuArraySet(arr.handle, ctypes.c_float(value))
def broadcast_to(in_arr, out_arr):
assert isinstance(in_arr, _nd.NDArray)
assert isinstance(out_arr, _nd.NDArray)
_LIB.DLGpuBroadcastTo(in_arr.handle, out_arr.handle)
def reduce_sum_axis_zero(in_arr, out_arr):
assert isinstance(in_arr, _nd.NDArray)
assert isinstance(out_arr, _nd.NDArray)
_LIB.DLGpuReduceSumAxisZero(in_arr.handle, out_arr.handle)
def matrix_elementwise_add(matA, matB, matC):
assert isinstance(matA, _nd.NDArray)
assert isinstance(matB, _nd.NDArray)
assert isinstance(matC, _nd.NDArray)
_LIB.DLGpuMatrixElementwiseAdd(matA.handle, matB.handle, matC.handle)
def matrix_elementwise_add_by_const(in_mat, val, out_mat):
assert isinstance(in_mat, _nd.NDArray)
assert isinstance(out_mat, _nd.NDArray)
_LIB.DLGpuMatrixElementwiseAddByConst(
in_mat.handle, ctypes.c_float(val), out_mat.handle)
def matrix_elementwise_multiply(matA, matB, matC):
assert isinstance(matA, _nd.NDArray)
assert isinstance(matB, _nd.NDArray)
assert isinstance(matC, _nd.NDArray)
_LIB.DLGpuMatrixElementwiseMultiply(
matA.handle, matB.handle, matC.handle)
def matrix_elementwise_multiply_by_const(in_mat, val, out_mat):
assert isinstance(in_mat, _nd.NDArray)
assert isinstance(out_mat, _nd.NDArray)
_LIB.DLGpuMatrixMultiplyByConst(
in_mat.handle, ctypes.c_float(val), out_mat.handle)
def matrix_multiply(matA, transA, matB, transB, matC):
assert isinstance(matA, _nd.NDArray)
assert isinstance(matB, _nd.NDArray)
assert isinstance(matC, _nd.NDArray)
_LIB.DLGpuMatrixMultiply(
matA.handle, transA, matB.handle, transB, matC.handle)
def relu(in_arr, out_arr):
assert isinstance(in_arr, _nd.NDArray)
assert isinstance(out_arr, _nd.NDArray)
_LIB.DLGpuRelu(in_arr.handle, out_arr.handle)
def relu_gradient(in_arr, in_grad_arr, out_arr):
assert isinstance(in_arr, _nd.NDArray)
assert isinstance(in_grad_arr, _nd.NDArray)
assert isinstance(out_arr, _nd.NDArray)
_LIB.DLGpuReluGradient(in_arr.handle, in_grad_arr.handle, out_arr.handle)
def softmax(in_arr, out_arr):
assert isinstance(in_arr, _nd.NDArray)
assert isinstance(out_arr, _nd.NDArray)
_LIB.DLGpuSoftmax(in_arr.handle, out_arr.handle)
def softmax_cross_entropy(in_arr_a, in_arr_b, out_arr):
assert isinstance(in_arr_a, _nd.NDArray)
assert isinstance(in_arr_b, _nd.NDArray)
assert isinstance(out_arr, _nd.NDArray)
_LIB.DLGpuSoftmaxCrossEntropy(
in_arr_a.handle, in_arr_b.handle, out_arr.handle)
|