This C++ API example demonstrates how to create and execute a Sum primitive.
Key optimizations included in this example:
- Identical memory formats for source (src) and destination (dst) tensors.
#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<float> dst_data(product(src_dims));
std::generate(src_data.begin(), src_data.end(), []() {
static int i = 0;
return std::cos(i++ / 10.f);
});
const int num_src = 10;
std::vector<float> scales(num_src);
std::generate(
scales.begin(), scales.end(), [](int n = 0) { return sin(n); });
std::vector<memory::desc>
src_md;
std::vector<memory> src_mem;
for (int n = 0; n < num_src; ++n) {
write_to_dnnl_memory(src_data.data(), mem);
src_mem.push_back(mem);
}
auto sum_prim =
sum(sum_pd);
std::unordered_map<int, memory> sum_args;
for (int n = 0; n < num_src; ++n) {
}
sum_prim.execute(engine_stream, sum_args);
engine_stream.wait();
read_from_dnnl_memory(dst_data.data(), dst_mem);
}
int main(int argc, char **argv) {
return handle_example_errors(sum_example, parse_engine_kind(argc, argv));
}