#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include "example_utils.hpp"
T = 6,
C = 12,
G = 4,
L = 4,
D = 1;
std::vector<float> src_layer_data(product(src_dims));
std::vector<float> weights_layer_data(product(weights_dims));
std::vector<float> weights_iter_data(product(weights_dims));
std::vector<float> dst_layer_data(product(dst_dims));
std::vector<float> bias_data(product(bias_dims));
std::generate(src_layer_data.begin(), src_layer_data.end(), []() {
static int i = 0;
return std::cos(i++ / 10.f);
});
std::generate(weights_layer_data.begin(), weights_layer_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 src_layer_md =
memory::desc(src_dims, dt::f32, tag::tnc);
auto dst_layer_md =
memory::desc(dst_dims, dt::f32, tag::tnc);
auto user_weights_layer_mem
auto user_weights_iter_mem
write_to_dnnl_memory(src_layer_data.data(), src_layer_mem);
write_to_dnnl_memory(bias_data.data(), bias_mem);
write_to_dnnl_memory(weights_layer_data.data(), user_weights_layer_mem);
write_to_dnnl_memory(weights_iter_data.data(), user_weights_iter_mem);
auto lstm_weights_layer_md =
memory::desc(weights_dims, dt::f32, tag::any);
auto lstm_weights_iter_md =
memory::desc(weights_dims, dt::f32, tag::any);
src_iter_c_md, lstm_weights_layer_md, lstm_weights_iter_md, bias_md,
dst_layer_md, dst_iter_md, dst_iter_c_md);
auto lstm_weights_layer_mem = user_weights_layer_mem;
auto lstm_weights_iter_mem = user_weights_iter_mem;
if (lstm_pd.weights_desc() != user_weights_layer_mem.get_desc()) {
lstm_weights_layer_mem =
memory(lstm_pd.weights_desc(),
engine);
reorder(user_weights_layer_mem, lstm_weights_layer_mem)
.
execute(engine_stream, user_weights_layer_mem,
lstm_weights_layer_mem);
}
if (lstm_pd.weights_iter_desc() != user_weights_iter_mem.
get_desc()) {
lstm_weights_iter_mem =
memory(lstm_pd.weights_iter_desc(),
engine);
reorder(user_weights_iter_mem, lstm_weights_iter_mem)
.
execute(engine_stream, user_weights_iter_mem,
lstm_weights_iter_mem);
}
auto src_iter_mem =
memory(lstm_pd.src_iter_desc(),
engine);
auto src_iter_c_mem =
memory(lstm_pd.src_iter_c_desc(),
engine);
auto weights_iter_mem =
memory(lstm_pd.weights_iter_desc(),
engine);
auto dst_iter_mem =
memory(lstm_pd.dst_iter_desc(),
engine);
auto dst_iter_c_mem =
memory(lstm_pd.dst_iter_c_desc(),
engine);
auto workspace_mem =
memory(lstm_pd.workspace_desc(),
engine);
std::unordered_map<int, memory> lstm_args;
lstm_prim.execute(engine_stream, lstm_args);
read_from_dnnl_memory(dst_layer_data.data(), dst_layer_mem);
}
int main(int argc, char **argv) {
return handle_example_errors(lstm_example, parse_engine_kind(argc, argv));
}