File size: 2,099 Bytes
aaed8c9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | #ifndef MYPROJECT_BRIDGE_H_
#define MYPROJECT_BRIDGE_H_
#include "firmware/myproject.h"
#include "firmware/nnet_utils/nnet_helpers.h"
#include <algorithm>
#include <map>
// hls-fpga-machine-learning insert bram
namespace nnet {
bool trace_enabled = false;
std::map<std::string, void *> *trace_outputs = NULL;
size_t trace_type_size = sizeof(double);
} // namespace nnet
extern "C" {
struct trace_data {
const char *name;
void *data;
};
void allocate_trace_storage(size_t element_size) {
nnet::trace_enabled = true;
nnet::trace_outputs = new std::map<std::string, void *>;
nnet::trace_type_size = element_size;
}
void free_trace_storage() {
for (std::map<std::string, void *>::iterator i = nnet::trace_outputs->begin(); i != nnet::trace_outputs->end(); i++) {
void *ptr = i->second;
free(ptr);
}
nnet::trace_outputs->clear();
delete nnet::trace_outputs;
nnet::trace_outputs = NULL;
nnet::trace_enabled = false;
}
void collect_trace_output(struct trace_data *c_trace_outputs) {
int ii = 0;
for (std::map<std::string, void *>::iterator i = nnet::trace_outputs->begin(); i != nnet::trace_outputs->end(); i++) {
c_trace_outputs[ii].name = i->first.c_str();
c_trace_outputs[ii].data = i->second;
ii++;
}
}
// hls-fpga-machine-learning insert tb_input_writer
// Wrapper of top level function for Python bridge
void myproject_float(
float *x,
float *layer40_out
) {
hls::stream<input_t> x_ap("x");
nnet::convert_data<float, input_t, 1*64*64*1>(x, x_ap);
hls::stream<result_t> layer40_out_ap("layer40_out");
myproject(x_ap,layer40_out_ap);
nnet::convert_data<result_t, float, 64*64*1>(layer40_out_ap, layer40_out);
}
void myproject_double(
double *x,
double *layer40_out
) {
hls::stream<input_t> x_ap("x");
nnet::convert_data<double, input_t, 1*64*64*1>(x, x_ap);
hls::stream<result_t> layer40_out_ap("layer40_out");
myproject(x_ap,layer40_out_ap);
nnet::convert_data<result_t, double, 64*64*1>(layer40_out_ap, layer40_out);
}
}
#endif
|