#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include "example_utils.hpp"
IC = 32,
IH = 13,
IW = 13,
OC = 64,
KH = 3,
KW = 3,
PH_L = 1,
PH_R = 1,
PW_L = 1,
PW_R = 1,
SH = 4,
SW = 4,
OH = (IH - KH + PH_L + PH_R) / SH + 1,
OW = (IW - KW + PW_L + PW_R) / SW + 1;
std::vector<float> src_data(product(src_dims));
std::vector<float> weights_data(product(weights_dims));
std::vector<float> bias_data(OC);
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);
});
std::generate(weights_data.begin(), weights_data.end(), []() {
static int i = 0;
return std::sin(i++ * 2.f);
});
std::generate(bias_data.begin(), bias_data.end(), []() {
static int i = 0;
return std::tanh(i++);
});
auto user_src_mem =
memory({src_dims, dt::f32, tag::nchw},
engine);
auto user_weights_mem =
memory({weights_dims, dt::f32, tag::oihw},
engine);
auto user_dst_mem =
memory({dst_dims, dt::f32, tag::nchw},
engine);
auto conv_src_md =
memory::desc(src_dims, dt::f32, tag::any);
auto conv_weights_md =
memory::desc(weights_dims, dt::f32, tag::any);
auto conv_dst_md =
memory::desc(dst_dims, dt::f32, tag::any);
auto user_bias_md =
memory::desc(bias_dims, dt::f32, tag::a);
write_to_dnnl_memory(src_data.data(), user_src_mem);
write_to_dnnl_memory(weights_data.data(), user_weights_mem);
write_to_dnnl_memory(bias_data.data(), user_bias_mem);
user_bias_md, conv_dst_md, strides_dims, padding_dims_l,
padding_dims_r);
const float scale = 1.f;
const float alpha = 0.f;
const float beta = 0.f;
auto conv_pd
auto conv_src_mem = user_src_mem;
auto conv_weights_mem = user_weights_mem;
auto conv_dst_mem = user_dst_mem;
if (conv_pd.src_desc() != user_src_mem.get_desc()) {
reorder(user_src_mem, conv_src_mem)
.
execute(engine_stream, user_src_mem, conv_src_mem);
}
if (conv_pd.weights_desc() != user_weights_mem.
get_desc()) {
reorder(user_weights_mem, conv_weights_mem)
.
execute(engine_stream, user_weights_mem, conv_weights_mem);
}
if (conv_pd.dst_desc() != user_dst_mem.
get_desc()) {
}
std::unordered_map<int, memory> conv_args;
conv_prim.execute(engine_stream, conv_args);
if (conv_pd.dst_desc() != user_dst_mem.
get_desc()) {
reorder(conv_dst_mem, user_dst_mem)
.
execute(engine_stream, conv_dst_mem, user_dst_mem);
} else
user_dst_mem = conv_dst_mem;
read_from_dnnl_memory(dst_data.data(), user_dst_mem);
}
int main(int argc, char **argv) {
return handle_example_errors(
convolution_example, parse_engine_kind(argc, argv));
}