#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include "example_utils.hpp"
using tag = memory::format_tag;
using dt = memory::data_type;
const memory::dim N = 3,
IC = 3,
IH = 27,
IW = 27,
KH = 11,
KW = 11,
PH_L = 0,
PH_R = 0,
PW_L = 0,
PW_R = 0,
SH = 4,
SW = 4,
DH = 1,
DW = 1;
const memory::dim OH = (IH - ((KH - 1) * DH + KH) + PH_L + PH_R) / SH + 1;
const memory::dim OW = (IW - ((KW - 1) * DW + KW) + PW_L + PW_R) / SW + 1;
memory::dims src_dims = {N, IC, IH, IW};
memory::dims dst_dims = {N, IC, OH, OW};
memory::dims kernel_dims = {KH, KW};
memory::dims strides_dims = {SH, SW};
memory::dims padding_dims_l = {PH_L, PW_L};
memory::dims padding_dims_r = {PH_R, PW_R};
memory::dims dilation = {DH, DW};
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);
write_to_dnnl_memory(src_data.data(), src_mem);
auto pooling_d = pooling_v2_forward::desc(prop_kind::forward_training,
algorithm::pooling_max,
src_md,
dst_md, strides_dims, kernel_dims,
dilation, padding_dims_l, padding_dims_r);
auto workspace_mem = memory(pooling_pd.workspace_desc(),
engine);
auto pooling_prim = pooling_v2_forward(pooling_pd);
std::unordered_map<int, memory> pooling_args;
pooling_prim.execute(engine_stream, pooling_args);
read_from_dnnl_memory(dst_data.data(), dst_mem);
}
int main(int argc, char **argv) {
return handle_example_errors(
pooling_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_WORKSPACE
Workspace tensor argument.
Definition: dnnl_types.h:2366
#define DNNL_ARG_SRC
A special mnemonic for source argument for primitives that have a single source.
Definition: dnnl_types.h:2283
@ dst_md
destination memory desc
@ pooling_d
pooling descriptor
@ 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
stream & wait()
Waits for all primitives executing in the stream to finish.
Definition: dnnl.hpp:1025