Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
8ace7fb5
Commit
8ace7fb5
authored
Jun 15, 2018
by
Scott Thornton
Browse files
Fixed up clang tidy checks and formatting
parent
121ded22
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
463 additions
and
406 deletions
+463
-406
src/include/rtg/operators.hpp
src/include/rtg/operators.hpp
+26
-26
src/targets/cpu/cpu_target.cpp
src/targets/cpu/cpu_target.cpp
+173
-120
test/cpu_ops_test.cpp
test/cpu_ops_test.cpp
+264
-260
No files found.
src/include/rtg/operators.hpp
View file @
8ace7fb5
...
...
@@ -263,7 +263,7 @@ struct reshape
struct
gemm
{
std
::
string
name
()
const
{
return
"gemm"
;}
std
::
string
name
()
const
{
return
"gemm"
;
}
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
{
check_shapes
{
inputs
}.
has
(
2
).
same_type
();
...
...
@@ -271,7 +271,7 @@ struct gemm
const
shape
&
b
=
inputs
.
at
(
1
);
auto
t
=
a
.
type
();
if
(
a
.
lens
()[
1
]
!=
b
.
lens
()[
0
])
if
(
a
.
lens
()[
1
]
!=
b
.
lens
()[
0
])
RTG_THROW
(
"Inner dimensions do not match"
);
return
{
t
,
{
a
.
lens
()[
0
],
b
.
lens
()[
1
]}};
}
...
...
@@ -298,12 +298,12 @@ struct unary
struct
identity
:
unary
{
std
::
string
name
()
const
{
return
"identity"
;
}
std
::
string
name
()
const
{
return
"identity"
;
}
};
struct
abs
:
unary
{
std
::
string
name
()
const
{
return
"abs"
;
}
std
::
string
name
()
const
{
return
"abs"
;
}
};
struct
exp
:
unary
...
...
@@ -313,52 +313,52 @@ struct exp : unary
struct
sin
:
unary
{
std
::
string
name
()
const
{
return
"sin"
;
}
std
::
string
name
()
const
{
return
"sin"
;
}
};
struct
cos
:
unary
{
std
::
string
name
()
const
{
return
"cos"
;
}
std
::
string
name
()
const
{
return
"cos"
;
}
};
struct
tan
:
unary
{
std
::
string
name
()
const
{
return
"tan"
;
}
std
::
string
name
()
const
{
return
"tan"
;
}
};
struct
asin
:
unary
{
std
::
string
name
()
const
{
return
"asin"
;
}
std
::
string
name
()
const
{
return
"asin"
;
}
};
struct
acos
:
unary
{
std
::
string
name
()
const
{
return
"acos"
;
}
std
::
string
name
()
const
{
return
"acos"
;
}
};
struct
atan
:
unary
{
std
::
string
name
()
const
{
return
"atan"
;
}
std
::
string
name
()
const
{
return
"atan"
;
}
};
struct
softmax
:
unary
{
std
::
string
name
()
const
{
return
"softmax"
;
}
std
::
string
name
()
const
{
return
"softmax"
;
}
};
struct
tanh
:
unary
{
std
::
string
name
()
const
{
return
"tanh"
;
}
std
::
string
name
()
const
{
return
"tanh"
;
}
};
struct
sigmoid
:
unary
{
std
::
string
name
()
const
{
return
"sigmoid"
;
}
std
::
string
name
()
const
{
return
"sigmoid"
;
}
};
struct
neg
:
unary
{
std
::
string
name
()
const
{
return
"neg"
;
}
std
::
string
name
()
const
{
return
"neg"
;
}
};
struct
flatten
...
...
src/targets/cpu/cpu_target.cpp
View file @
8ace7fb5
...
...
@@ -8,7 +8,10 @@ namespace rtg {
namespace
cpu
{
template
<
typename
T
>
T
zero
(
const
T
&
)
{
return
T
(
0
);
}
T
zero
(
const
T
&
)
{
return
T
(
0
);
}
struct
cpu_convolution
{
...
...
@@ -55,10 +58,7 @@ struct cpu_reshape
{
reshape
op
;
std
::
string
name
()
const
{
return
"cpu::reshape"
;
}
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
{
return
op
.
compute_shape
(
inputs
);
}
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
{
return
op
.
compute_shape
(
inputs
);
}
argument
compute
(
shape
output_shape
,
std
::
vector
<
argument
>
args
)
const
{
...
...
@@ -70,10 +70,7 @@ struct cpu_gemm
{
gemm
op
;
std
::
string
name
()
const
{
return
"cpu::gemm"
;
}
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
{
return
op
.
compute_shape
(
inputs
);
}
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
{
return
op
.
compute_shape
(
inputs
);
}
argument
compute
(
shape
output_shape
,
std
::
vector
<
argument
>
args
)
const
{
...
...
@@ -86,18 +83,23 @@ struct cpu_gemm
auto
a
=
amat
.
data
();
auto
b
=
bmat
.
data
();
auto
c
=
cmat
.
data
();
for
(
int
ii
=
0
;
ii
<
m
;
ii
++
)
{
for
(
int
jj
=
0
;
jj
<
n
;
jj
++
)
{
c
[
ii
*
n
+
jj
]
=
0
;
for
(
int
ii
=
0
;
ii
<
m
;
ii
++
)
{
for
(
int
jj
=
0
;
jj
<
n
;
jj
++
)
{
c
[
ii
*
n
+
jj
]
=
0
;
}
}
for
(
int
ii
=
0
;
ii
<
m
;
ii
++
)
{
for
(
int
kk
=
0
;
kk
<
k
;
kk
++
)
{
auto
aik
=
a
[
ii
*
k
+
kk
];
auto
*
bkj
=
&
b
[
kk
*
n
];
auto
*
cij
=
&
c
[
ii
*
n
];
for
(
int
jj
=
0
;
jj
<
n
;
jj
++
,
cij
++
,
bkj
++
)
{
*
cij
+=
aik
*
(
*
bkj
);
for
(
int
ii
=
0
;
ii
<
m
;
ii
++
)
{
for
(
int
kk
=
0
;
kk
<
k
;
kk
++
)
{
auto
aik
=
a
[
ii
*
k
+
kk
];
auto
*
bkj
=
&
b
[
kk
*
n
];
auto
*
cij
=
&
c
[
ii
*
n
];
for
(
int
jj
=
0
;
jj
<
n
;
jj
++
,
cij
++
,
bkj
++
)
{
*
cij
+=
aik
*
(
*
bkj
);
}
}
}
...
...
@@ -108,80 +110,119 @@ struct cpu_gemm
struct
identity_op
{
std
::
string
name
()
const
{
return
"cpu::identity"
;
}
auto
fcn
()
const
{
return
[](
auto
x
)
{
return
x
;
};
}
std
::
string
name
()
const
{
return
"cpu::identity"
;
}
auto
fcn
()
const
{
return
[](
auto
x
)
{
return
x
;
};
}
};
struct
abs_op
{
std
::
string
name
()
const
{
return
"cpu::abs"
;
}
auto
fcn
()
const
{
return
[](
auto
x
)
{
return
std
::
abs
(
x
);
};
}
std
::
string
name
()
const
{
return
"cpu::abs"
;
}
auto
fcn
()
const
{
return
[](
auto
x
)
{
return
std
::
abs
(
x
);
};
}
};
struct
exp_op
{
std
::
string
name
()
const
{
return
"cpu::exp"
;
}
auto
fcn
()
const
{
return
[](
auto
x
)
{
return
std
::
exp
(
x
);
};
}
std
::
string
name
()
const
{
return
"cpu::exp"
;
}
auto
fcn
()
const
{
return
[](
auto
x
)
{
return
std
::
exp
(
x
);
};
}
};
struct
sin_op
{
std
::
string
name
()
const
{
return
"cpu::sin"
;
}
auto
fcn
()
const
{
return
[](
auto
x
)
{
return
std
::
sin
(
x
);
};
}
std
::
string
name
()
const
{
return
"cpu::sin"
;
}
auto
fcn
()
const
{
return
[](
auto
x
)
{
return
std
::
sin
(
x
);
};
}
};
struct
cos_op
{
std
::
string
name
()
const
{
return
"cpu::cos"
;
}
auto
fcn
()
const
{
return
[](
auto
x
)
{
return
std
::
cos
(
x
);
};
}
std
::
string
name
()
const
{
return
"cpu::cos"
;
}
auto
fcn
()
const
{
return
[](
auto
x
)
{
return
std
::
cos
(
x
);
};
}
};
struct
tan_op
{
std
::
string
name
()
const
{
return
"cpu::tan"
;
}
auto
fcn
()
const
{
return
[](
auto
x
)
{
return
std
::
tan
(
x
);
};
}
std
::
string
name
()
const
{
return
"cpu::tan"
;
}
auto
fcn
()
const
{
return
[](
auto
x
)
{
return
std
::
tan
(
x
);
};
}
};
struct
asin_op
{
std
::
string
name
()
const
{
return
"cpu::asin"
;
}
auto
fcn
()
const
{
return
[](
auto
x
)
{
return
std
::
asin
(
x
);
};
}
std
::
string
name
()
const
{
return
"cpu::asin"
;
}
auto
fcn
()
const
{
return
[](
auto
x
)
{
return
std
::
asin
(
x
);
};
}
};
struct
acos_op
{
std
::
string
name
()
const
{
return
"cpu::acos"
;
}
auto
fcn
()
const
{
return
[](
auto
x
)
{
return
std
::
acos
(
x
);
};
}
std
::
string
name
()
const
{
return
"cpu::acos"
;
}
auto
fcn
()
const
{
return
[](
auto
x
)
{
return
std
::
acos
(
x
);
};
}
};
struct
atan_op
{
std
::
string
name
()
const
{
return
"cpu::atan"
;
}
auto
fcn
()
const
{
return
[](
auto
x
)
{
return
std
::
atan
(
x
);
};
}
std
::
string
name
()
const
{
return
"cpu::atan"
;
}
auto
fcn
()
const
{
return
[](
auto
x
)
{
return
std
::
atan
(
x
);
};
}
};
struct
tanh_op
{
std
::
string
name
()
const
{
return
"cpu::tanh"
;
}
auto
fcn
()
const
{
return
[](
auto
x
)
{
return
std
::
tanh
(
x
);
};
}
std
::
string
name
()
const
{
return
"cpu::tanh"
;
}
auto
fcn
()
const
{
return
[](
auto
x
)
{
return
std
::
tanh
(
x
);
};
}
};
struct
sigmoid_op
{
std
::
string
name
()
const
{
return
"cpu::sigmoid"
;
}
auto
fcn
()
const
{
return
[](
auto
x
)
{
return
1.
f
/
(
1.
f
+
std
::
exp
(
-
x
));
};
}
std
::
string
name
()
const
{
return
"cpu::sigmoid"
;
}
auto
fcn
()
const
{
return
[](
auto
x
)
{
return
1.
f
/
(
1.
f
+
std
::
exp
(
-
x
));
};
}
};
struct
neg_op
{
std
::
string
name
()
const
{
return
"cpu::neg"
;
}
auto
fcn
()
const
{
return
[](
auto
x
)
{
return
-
x
;
};
}
std
::
string
name
()
const
{
return
"cpu::neg"
;
}
auto
fcn
()
const
{
return
[](
auto
x
)
{
return
-
x
;
};
}
};
struct
relu_op
{
std
::
string
name
()
const
{
return
"cpu::relu"
;
}
auto
fcn
()
const
{
return
[](
auto
x
)
{
return
x
>
0
?
x
:
0
;
};
}
std
::
string
name
()
const
{
return
"cpu::relu"
;
}
auto
fcn
()
const
{
return
[](
auto
x
)
{
return
x
>
0
?
x
:
0
;
};
}
};
template
<
typename
Op
>
...
...
@@ -215,27 +256,27 @@ struct softmax2d
auto
nc
=
input
.
get_shape
().
lens
()[
1
];
auto
nh
=
input
.
get_shape
().
lens
()[
2
];
auto
nw
=
input
.
get_shape
().
lens
()[
3
];
for
(
int
b
=
0
;
b
<
nb
;
b
++
)
{
for
(
int
i
=
0
;
i
<
nh
;
i
++
)
{
for
(
int
j
=
0
;
j
<
nw
;
j
++
)
{
dfor
(
nb
,
nh
,
nw
)([
&
](
std
::
size_t
b
,
std
::
size_t
i
,
std
::
size_t
j
)
{
value_type
cmax
=
std
::
numeric_limits
<
value_type
>::
lowest
();
for
(
int
c
=
0
;
c
<
nc
;
c
++
)
{
for
(
int
c
=
0
;
c
<
nc
;
c
++
)
{
cmax
=
std
::
max
(
cmax
,
input
(
b
,
c
,
i
,
j
));
}
for
(
int
c
=
0
;
c
<
nc
;
c
++
)
{
output
(
b
,
c
,
i
,
j
)
=
std
::
exp
(
input
(
b
,
c
,
i
,
j
)
-
cmax
);
for
(
int
c
=
0
;
c
<
nc
;
c
++
)
{
output
(
b
,
c
,
i
,
j
)
=
std
::
exp
(
input
(
b
,
c
,
i
,
j
)
-
cmax
);
}
value_type
sum
=
value_type
(
0
);
for
(
int
c
=
0
;
c
<
nc
;
c
++
)
{
for
(
int
c
=
0
;
c
<
nc
;
c
++
)
{
sum
+=
output
(
b
,
c
,
i
,
j
);
}
for
(
int
c
=
0
;
c
<
nc
;
c
++
)
{
output
(
b
,
c
,
i
,
j
)
=
output
(
b
,
c
,
i
,
j
)
/
sum
;
}
}
}
for
(
int
c
=
0
;
c
<
nc
;
c
++
)
{
output
(
b
,
c
,
i
,
j
)
=
output
(
b
,
c
,
i
,
j
)
/
sum
;
}
});
});
return
result
;
}
};
...
...
@@ -243,32 +284,44 @@ struct softmax2d
struct
add_op
{
std
::
string
name
()
const
{
return
"add"
;
}
auto
fcn
()
const
{
return
[](
auto
x
,
auto
y
)
{
return
x
+
y
;};}
auto
fcn
()
const
{
return
[](
auto
x
,
auto
y
)
{
return
x
+
y
;
};
}
};
struct
sub_op
{
std
::
string
name
()
const
{
return
"sub"
;
}
auto
fcn
()
const
{
return
[](
auto
x
,
auto
y
)
{
return
x
-
y
;};}
auto
fcn
()
const
{
return
[](
auto
x
,
auto
y
)
{
return
x
-
y
;
};
}
};
struct
mul_op
{
std
::
string
name
()
const
{
return
"mul"
;
}
auto
fcn
()
const
{
return
[](
auto
x
,
auto
y
)
{
return
x
*
y
;};}
auto
fcn
()
const
{
return
[](
auto
x
,
auto
y
)
{
return
x
*
y
;
};
}
};
struct
div_op
{
std
::
string
name
()
const
{
return
"div"
;
}
auto
fcn
()
const
{
return
[](
auto
x
,
auto
y
)
{
return
x
/
y
;};}
auto
fcn
()
const
{
return
[](
auto
x
,
auto
y
)
{
return
x
/
y
;
};
}
};
template
<
typename
Op
>
struct
cpu_binary
{
Op
op
;
std
::
string
name
()
const
{
op
.
name
();
}
std
::
string
name
()
const
{
return
op
.
name
();
}
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
{
return
inputs
.
front
();
}
argument
compute
(
shape
output_shape
,
std
::
vector
<
argument
>
args
)
const
{
...
...
test/cpu_ops_test.cpp
View file @
8ace7fb5
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment