This example demonstrates memory format propagation, which is critical for deep learning applications performance.
#include <iostream>
#include <sstream>
#include <string>
#include "example_utils.hpp"
void memory_format_propagation_tutorial(
engine::kind engine_kind) {
const int N = 1, H = 14, W = 14, IC = 128, OC = 256, KH = 3, KW = 3;
);
);
);
auto pool_dst_md = conv_dst_md;
conv_src_md, conv_weights_md,
conv_dst_md,
{1, 1},
{1, 1}, {1, 1}},
eng);
conv_pd.dst_desc(), pool_dst_md,
{1, 1}, {KH, KW},
{1, 1}, {1, 1}},
eng);
eng);
eng);
eng);
bool need_reorder_src = conv_pd.src_desc() != src_mem.get_desc();
bool need_reorder_weights
bool need_reorder_dst = conv_pd.dst_desc() != dst_mem.
get_desc();
auto conv_src_mem
= need_reorder_src ?
memory(conv_pd.src_desc(), eng) : src_mem;
auto conv_weights_mem = need_reorder_weights
?
memory(conv_pd.weights_desc(), eng)
: weights_mem;
auto conv_dst_mem =
memory(conv_pd.dst_desc(), eng);
auto pool_dst_mem
if (need_reorder_src) {
auto reorder_src =
reorder(src_mem, conv_src_mem);
reorder_src.execute(
}
if (need_reorder_weights) {
auto reorder_weights =
reorder(weights_mem, conv_weights_mem);
reorder_weights.execute(s,
}
auto conv_scratchpad_mem =
memory(conv_pd.scratchpad_desc(), eng);
conv.execute(s,
pool.execute(
if (need_reorder_dst) {
auto reorder_dst =
reorder(pool_dst_mem, dst_mem);
reorder_dst.execute(
}
}
int main(int argc, char **argv) {
return handle_example_errors(
memory_format_propagation_tutorial, parse_engine_kind(argc, argv));
}