#include <cmath>
#include "example_utils.hpp"
using tag = memory::format_tag;
using dt = memory::data_type;
const memory::dim N = 3,
IC = 3,
IH = 227,
IW = 227;
memory::dims src_dims = {N, IC, IH, IW};
memory::dims dst_dims = {1, IC, 1, 1};
std::vector<float> src_data(product(src_dims));
std::vector<float> dst_data(product(dst_dims));
std::generate(src_data.begin(), src_data.end(), []() {
static int i = 0;
return std::cos(i++ / 10.f);
});
auto src_md = memory::desc(src_dims, dt::f32, tag::nchw);
auto dst_md = memory::desc(dst_dims, dt::f32, tag::nchw);
auto src_mem = memory(src_md, engine);
auto dst_mem = memory(dst_md, engine);
write_to_dnnl_memory(src_data.data(), src_mem);
algorithm::reduction_sum, src_md, dst_md, 0.f, 0.f);
auto reduction_pd = reduction::primitive_desc(reduction_d, engine);
auto reduction_prim = reduction(reduction_pd);
std::unordered_map<int, memory> reduction_args;
reduction_prim.execute(engine_stream, reduction_args);
engine_stream.wait();
read_from_dnnl_memory(dst_data.data(), dst_mem);
}
int main(int argc, char **argv) {
return handle_example_errors(
reduction_example, parse_engine_kind(argc, argv));
}
#define DNNL_ARG_DST
A special mnemonic for destination argument for primitives that have a single destination.
Definition: dnnl_types.h:2307
#define DNNL_ARG_SRC
A special mnemonic for source argument for primitives that have a single source.
Definition: dnnl_types.h:2283
@ reduction_d
reduction descriptor
@ dst_md
destination memory desc
@ src_md
source memory desc
oneDNN namespace
Definition: dnnl.hpp:74
An execution engine.
Definition: dnnl.hpp:869
kind
Kinds of engines.
Definition: dnnl.hpp:874
An execution stream.
Definition: dnnl.hpp:985