Commit 8ace7fb5 authored by Scott Thornton's avatar Scott Thornton
Browse files

Fixed up clang tidy checks and formatting

parent 121ded22
...@@ -263,7 +263,7 @@ struct reshape ...@@ -263,7 +263,7 @@ struct reshape
struct gemm struct gemm
{ {
std::string name() const { return "gemm";} std::string name() const { return "gemm"; }
shape compute_shape(std::vector<shape> inputs) const shape compute_shape(std::vector<shape> inputs) const
{ {
check_shapes{inputs}.has(2).same_type(); check_shapes{inputs}.has(2).same_type();
...@@ -271,7 +271,7 @@ struct gemm ...@@ -271,7 +271,7 @@ struct gemm
const shape& b = inputs.at(1); const shape& b = inputs.at(1);
auto t = a.type(); 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"); RTG_THROW("Inner dimensions do not match");
return {t, {a.lens()[0], b.lens()[1]}}; return {t, {a.lens()[0], b.lens()[1]}};
} }
...@@ -298,12 +298,12 @@ struct unary ...@@ -298,12 +298,12 @@ struct unary
struct identity : unary struct identity : unary
{ {
std::string name() const {return "identity"; } std::string name() const { return "identity"; }
}; };
struct abs : unary struct abs : unary
{ {
std::string name() const {return "abs"; } std::string name() const { return "abs"; }
}; };
struct exp : unary struct exp : unary
...@@ -313,52 +313,52 @@ struct exp : unary ...@@ -313,52 +313,52 @@ struct exp : unary
struct sin : unary struct sin : unary
{ {
std::string name() const {return "sin"; } std::string name() const { return "sin"; }
}; };
struct cos : unary struct cos : unary
{ {
std::string name() const {return "cos"; } std::string name() const { return "cos"; }
}; };
struct tan : unary struct tan : unary
{ {
std::string name() const {return "tan"; } std::string name() const { return "tan"; }
}; };
struct asin : unary struct asin : unary
{ {
std::string name() const {return "asin"; } std::string name() const { return "asin"; }
}; };
struct acos : unary struct acos : unary
{ {
std::string name() const {return "acos"; } std::string name() const { return "acos"; }
}; };
struct atan : unary struct atan : unary
{ {
std::string name() const {return "atan"; } std::string name() const { return "atan"; }
}; };
struct softmax : unary struct softmax : unary
{ {
std::string name() const {return "softmax"; } std::string name() const { return "softmax"; }
}; };
struct tanh : unary struct tanh : unary
{ {
std::string name() const {return "tanh"; } std::string name() const { return "tanh"; }
}; };
struct sigmoid : unary struct sigmoid : unary
{ {
std::string name() const {return "sigmoid"; } std::string name() const { return "sigmoid"; }
}; };
struct neg : unary struct neg : unary
{ {
std::string name() const {return "neg"; } std::string name() const { return "neg"; }
}; };
struct flatten struct flatten
......
...@@ -8,7 +8,10 @@ namespace rtg { ...@@ -8,7 +8,10 @@ namespace rtg {
namespace cpu { namespace cpu {
template <typename T> template <typename T>
T zero(const T&) { return T(0); } T zero(const T&)
{
return T(0);
}
struct cpu_convolution struct cpu_convolution
{ {
...@@ -55,10 +58,7 @@ struct cpu_reshape ...@@ -55,10 +58,7 @@ struct cpu_reshape
{ {
reshape op; reshape op;
std::string name() const { return "cpu::reshape"; } std::string name() const { return "cpu::reshape"; }
shape compute_shape(std::vector<shape> inputs) const shape compute_shape(std::vector<shape> inputs) const { return op.compute_shape(inputs); }
{
return op.compute_shape(inputs);
}
argument compute(shape output_shape, std::vector<argument> args) const argument compute(shape output_shape, std::vector<argument> args) const
{ {
...@@ -70,10 +70,7 @@ struct cpu_gemm ...@@ -70,10 +70,7 @@ struct cpu_gemm
{ {
gemm op; gemm op;
std::string name() const { return "cpu::gemm"; } std::string name() const { return "cpu::gemm"; }
shape compute_shape(std::vector<shape> inputs) const shape compute_shape(std::vector<shape> inputs) const { return op.compute_shape(inputs); }
{
return op.compute_shape(inputs);
}
argument compute(shape output_shape, std::vector<argument> args) const argument compute(shape output_shape, std::vector<argument> args) const
{ {
...@@ -86,18 +83,23 @@ struct cpu_gemm ...@@ -86,18 +83,23 @@ struct cpu_gemm
auto a = amat.data(); auto a = amat.data();
auto b = bmat.data(); auto b = bmat.data();
auto c = cmat.data(); auto c = cmat.data();
for (int ii = 0; ii < m; ii++) { for(int ii = 0; ii < m; ii++)
for (int jj = 0; jj < n; jj++) { {
c[ii*n+jj] = 0; for(int jj = 0; jj < n; jj++)
{
c[ii * n + jj] = 0;
} }
} }
for (int ii = 0; ii < m; ii++) { for(int ii = 0; ii < m; ii++)
for (int kk = 0; kk < k; kk++) { {
auto aik = a[ii*k+kk]; for(int kk = 0; kk < k; kk++)
auto* bkj = &b[kk*n]; {
auto* cij = &c[ii*n]; auto aik = a[ii * k + kk];
for (int jj = 0; jj < n; jj++, cij++, bkj++) { auto* bkj = &b[kk * n];
*cij += aik*(*bkj); auto* cij = &c[ii * n];
for(int jj = 0; jj < n; jj++, cij++, bkj++)
{
*cij += aik * (*bkj);
} }
} }
} }
...@@ -108,80 +110,119 @@ struct cpu_gemm ...@@ -108,80 +110,119 @@ struct cpu_gemm
struct identity_op struct identity_op
{ {
std::string name() const {return "cpu::identity"; } std::string name() const { return "cpu::identity"; }
auto fcn() const { return [](auto x) { return x; }; } auto fcn() const
{
return [](auto x) { return x; };
}
}; };
struct abs_op struct abs_op
{ {
std::string name() const {return "cpu::abs"; } std::string name() const { return "cpu::abs"; }
auto fcn() const { return [](auto x) { return std::abs(x); }; } auto fcn() const
{
return [](auto x) { return std::abs(x); };
}
}; };
struct exp_op struct exp_op
{ {
std::string name() const {return "cpu::exp"; } std::string name() const { return "cpu::exp"; }
auto fcn() const { return [](auto x) { return std::exp(x); }; } auto fcn() const
{
return [](auto x) { return std::exp(x); };
}
}; };
struct sin_op struct sin_op
{ {
std::string name() const {return "cpu::sin"; } std::string name() const { return "cpu::sin"; }
auto fcn() const { return [](auto x) { return std::sin(x); }; } auto fcn() const
{
return [](auto x) { return std::sin(x); };
}
}; };
struct cos_op struct cos_op
{ {
std::string name() const {return "cpu::cos"; } std::string name() const { return "cpu::cos"; }
auto fcn() const { return [](auto x) { return std::cos(x); }; } auto fcn() const
{
return [](auto x) { return std::cos(x); };
}
}; };
struct tan_op struct tan_op
{ {
std::string name() const {return "cpu::tan"; } std::string name() const { return "cpu::tan"; }
auto fcn() const { return [](auto x) { return std::tan(x); }; } auto fcn() const
{
return [](auto x) { return std::tan(x); };
}
}; };
struct asin_op struct asin_op
{ {
std::string name() const {return "cpu::asin"; } std::string name() const { return "cpu::asin"; }
auto fcn() const { return [](auto x) { return std::asin(x); }; } auto fcn() const
{
return [](auto x) { return std::asin(x); };
}
}; };
struct acos_op struct acos_op
{ {
std::string name() const {return "cpu::acos"; } std::string name() const { return "cpu::acos"; }
auto fcn() const { return [](auto x) { return std::acos(x); }; } auto fcn() const
{
return [](auto x) { return std::acos(x); };
}
}; };
struct atan_op struct atan_op
{ {
std::string name() const {return "cpu::atan"; } std::string name() const { return "cpu::atan"; }
auto fcn() const { return [](auto x) { return std::atan(x); }; } auto fcn() const
{
return [](auto x) { return std::atan(x); };
}
}; };
struct tanh_op struct tanh_op
{ {
std::string name() const {return "cpu::tanh"; } std::string name() const { return "cpu::tanh"; }
auto fcn() const { return [](auto x) { return std::tanh(x); }; } auto fcn() const
{
return [](auto x) { return std::tanh(x); };
}
}; };
struct sigmoid_op struct sigmoid_op
{ {
std::string name() const {return "cpu::sigmoid"; } std::string name() const { return "cpu::sigmoid"; }
auto fcn() const { return [](auto x) { return 1.f/(1.f + std::exp(-x)); }; } auto fcn() const
{
return [](auto x) { return 1.f / (1.f + std::exp(-x)); };
}
}; };
struct neg_op struct neg_op
{ {
std::string name() const {return "cpu::neg"; } std::string name() const { return "cpu::neg"; }
auto fcn() const { return [](auto x) { return -x; }; } auto fcn() const
{
return [](auto x) { return -x; };
}
}; };
struct relu_op struct relu_op
{ {
std::string name() const {return "cpu::relu"; } std::string name() const { return "cpu::relu"; }
auto fcn() const { return [](auto x) { return x > 0 ? x : 0; }; } auto fcn() const
{
return [](auto x) { return x > 0 ? x : 0; };
}
}; };
template <typename Op> template <typename Op>
...@@ -215,27 +256,27 @@ struct softmax2d ...@@ -215,27 +256,27 @@ struct softmax2d
auto nc = input.get_shape().lens()[1]; auto nc = input.get_shape().lens()[1];
auto nh = input.get_shape().lens()[2]; auto nh = input.get_shape().lens()[2];
auto nw = input.get_shape().lens()[3]; auto nw = input.get_shape().lens()[3];
for (int b = 0; b < nb; b++) { dfor(nb, nh, nw)([&](std::size_t b, std::size_t i, std::size_t j) {
for (int i = 0; i < nh; i++) {
for (int j = 0; j < nw; j++) {
value_type cmax = std::numeric_limits<value_type>::lowest(); 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)); cmax = std::max(cmax, input(b, c, i, j));
} }
for (int c = 0; c < nc; c++) { for(int c = 0; c < nc; c++)
output(b, c, i, j) = std::exp(input(b, c, i, j)-cmax); {
output(b, c, i, j) = std::exp(input(b, c, i, j) - cmax);
} }
value_type sum = value_type(0); 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); sum += output(b, c, i, j);
} }
for (int c = 0; c < nc; c++) { for(int c = 0; c < nc; c++)
output(b, c, i, j) = output(b, c, i, j)/sum; {
} output(b, c, i, j) = output(b, c, i, j) / sum;
}
}
} }
}); });
});
return result; return result;
} }
}; };
...@@ -243,32 +284,44 @@ struct softmax2d ...@@ -243,32 +284,44 @@ struct softmax2d
struct add_op struct add_op
{ {
std::string name() const { return "add"; } 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 struct sub_op
{ {
std::string name() const { return "sub"; } 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 struct mul_op
{ {
std::string name() const { return "mul"; } 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 struct div_op
{ {
std::string name() const { return "div"; } 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> template <typename Op>
struct cpu_binary struct cpu_binary
{ {
Op op; 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(); } shape compute_shape(std::vector<shape> inputs) const { return inputs.front(); }
argument compute(shape output_shape, std::vector<argument> args) const argument compute(shape output_shape, std::vector<argument> args) const
{ {
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment