This C++ API demonstrates how to create and execute a Reorder primitive.
Key optimizations included in this example:
- Primitive attributes for output scaling.
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include "example_utils.hpp"
IC = 3,
IH = 227,
IW = 227;
std::vector<float> src_data(product(src_dims));
std::vector<int8_t> dst_data(product(src_dims));
std::generate(src_data.begin(), src_data.end(), []() {
static int i = 0;
return std::cos(i++ / 10.f);
});
write_to_dnnl_memory(src_data.data(), src_mem);
std::vector<float> scales(IC);
std::generate(scales.begin(), scales.end(), []() {
static int i = 0;
return 64 + 5 * i++;
});
const int ic_dim = 1;
auto reorder_prim =
reorder(reorder_pd);
std::unordered_map<int, memory> reorder_args;
reorder_prim.execute(engine_stream, reorder_args);
engine_stream.wait();
read_from_dnnl_memory(dst_data.data(), dst_mem);
}
int main(int argc, char **argv) {
return handle_example_errors(
reorder_example, parse_engine_kind(argc, argv));
}