Commit 84af2e9e authored by Paul's avatar Paul
Browse files

Formatting

parent 5f04935f
...@@ -84,8 +84,10 @@ bool shape::packed() const { return this->m_packed; } ...@@ -84,8 +84,10 @@ bool shape::packed() const { return this->m_packed; }
bool shape::broadcasted() const bool shape::broadcasted() const
{ {
assert(this->lens().size() == this->strides().size()); assert(this->lens().size() == this->strides().size());
return std::accumulate( return std::accumulate(this->strides().begin(),
this->strides().begin(), this->strides().end(), std::size_t{1}, std::multiplies<std::size_t>()) == 0; this->strides().end(),
std::size_t{1},
std::multiplies<std::size_t>()) == 0;
} }
std::size_t shape::element_space() const std::size_t shape::element_space() const
......
...@@ -105,33 +105,37 @@ struct miopen_add ...@@ -105,33 +105,37 @@ struct miopen_add
argument compute(shape output_shape, std::vector<argument> args) const argument compute(shape output_shape, std::vector<argument> args) const
{ {
if(args[2].get_shape().broadcasted()) { if(args[2].get_shape().broadcasted())
{
argument result{output_shape}; argument result{output_shape};
visit_all(result, from_gpu(args[1]), from_gpu(args[2]))([&](auto output, auto input1, auto input2) { visit_all(result, from_gpu(args[1]), from_gpu(args[2]))(
shape_for_each(output.get_shape(), [&](const auto& idx) { [&](auto output, auto input1, auto input2) {
shape_for_each(output.get_shape(), [&](const auto& idx) {
output(idx.begin(), idx.end()) = output(idx.begin(), idx.end()) =
input1(idx.begin(), idx.end()) + input2(idx.begin(), idx.end()); input1(idx.begin(), idx.end()) + input2(idx.begin(), idx.end());
}); });
}); });
return to_gpu(result); return to_gpu(result);
} else { }
float alpha = 1, beta = 0; else
auto a_desc = make_tensor(args[1].get_shape()); {
auto b_desc = make_tensor(args[2].get_shape()); float alpha = 1, beta = 0;
auto c_desc = make_tensor(output_shape); auto a_desc = make_tensor(args[1].get_shape());
miopenOpTensor(args[0].implicit(), auto b_desc = make_tensor(args[2].get_shape());
miopenTensorOpAdd, auto c_desc = make_tensor(output_shape);
&alpha, miopenOpTensor(args[0].implicit(),
a_desc.get(), miopenTensorOpAdd,
args[1].implicit(), &alpha,
&alpha, a_desc.get(),
b_desc.get(), args[1].implicit(),
args[2].implicit(), &alpha,
&beta, b_desc.get(),
c_desc.get(), args[2].implicit(),
args[3].implicit()); &beta,
return args[3]; c_desc.get(),
args[3].implicit());
return args[3];
} }
} }
}; };
......
...@@ -114,7 +114,7 @@ struct capture ...@@ -114,7 +114,7 @@ struct capture
}; };
template <class T, class F> template <class T, class F>
void failed(T x, const char* msg, const char * func, const char* file, int line, F f) void failed(T x, const char* msg, const char* func, const char* file, int line, F f)
{ {
if(!x.value()) if(!x.value())
{ {
...@@ -163,11 +163,18 @@ void run_test() ...@@ -163,11 +163,18 @@ void run_test()
} // namespace test } // namespace test
// NOLINTNEXTLINE // NOLINTNEXTLINE
#define CHECK(...) \ #define CHECK(...) \
test::failed(test::capture{}->*__VA_ARGS__, #__VA_ARGS__, __PRETTY_FUNCTION__, __FILE__, __LINE__, [] {}) test::failed( \
test::capture{}->*__VA_ARGS__, #__VA_ARGS__, __PRETTY_FUNCTION__, __FILE__, __LINE__, [] { \
})
// NOLINTNEXTLINE // NOLINTNEXTLINE
#define EXPECT(...) \ #define EXPECT(...) \
test::failed(test::capture{}->*__VA_ARGS__, #__VA_ARGS__, __PRETTY_FUNCTION__, __FILE__, __LINE__, &std::abort) test::failed(test::capture{}->*__VA_ARGS__, \
#__VA_ARGS__, \
__PRETTY_FUNCTION__, \
__FILE__, \
__LINE__, \
&std::abort)
// NOLINTNEXTLINE // NOLINTNEXTLINE
#define STATUS(...) EXPECT((__VA_ARGS__) == 0) #define STATUS(...) EXPECT((__VA_ARGS__) == 0)
......
...@@ -77,8 +77,8 @@ struct test_add_broadcast ...@@ -77,8 +77,8 @@ struct test_add_broadcast
{ {
rtg::program p; rtg::program p;
rtg::shape s{rtg::shape::float_type, {3}}; rtg::shape s{rtg::shape::float_type, {3}};
auto x = p.add_parameter("x", {rtg::shape::float_type, {2, 2, 3}}); auto x = p.add_parameter("x", {rtg::shape::float_type, {2, 2, 3}});
auto y = p.add_parameter("y", {rtg::shape::float_type, {2, 2}}); auto y = p.add_parameter("y", {rtg::shape::float_type, {2, 2}});
auto by = p.add_instruction(rtg::broadcast{0}, x, y); auto by = p.add_instruction(rtg::broadcast{0}, x, y);
p.add_instruction(rtg::add{}, x, by); p.add_instruction(rtg::add{}, x, by);
return p; return p;
......
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