Skip to content
Snippets Groups Projects
Commit e3d685d3 authored by Yifan Zhao's avatar Yifan Zhao
Browse files

Some little dance with hpvm-rt-controller

parent 410a3660
No related branches found
No related tags found
No related merge requests found
......@@ -268,10 +268,12 @@ double ProfileInfo::getCurrentIterationComputeEnergy() {
void ProfileInfo::set_out_file_name(std::string &str) { out_file_name = str; }
void ProfileInfo::printToFile() {
INFO("Writing Runtime Profile Info File...\n");
std::ofstream s_out(out_file_name.c_str());
if (control_time_info.size() == 0)
return;
std::ofstream s_out(out_file_name.c_str());
if (!s_out) {
ERROR("Failed to open output file.");
abort();
......@@ -1390,14 +1392,14 @@ uint32_t *hpvm_rt_readLabelsBatch_cached(const char *labels_file, int start,
ERROR("Data file %s is not found. Aborting...\n", labels_file);
abort();
}
// Get number of labels
fseek(file, 0, SEEK_END);
long size = ftell(file);
fseek(file, 0, SEEK_SET); // return file pointer to beginning
// Allocate memory for labels
labels_from_file = (uint32_t *) malloc(size);
labels_from_file = (uint32_t *)malloc(size);
if (labels_from_file == NULL) {
ERROR("Memory allocation for labels unsucessfull. Aborting...\n");
abort();
......@@ -1474,7 +1476,6 @@ float hpvm_rt_computeAccuracy3(uint32_t *labels, void *result_ptr) {
return accuracy;
}
#define llvm_hpvm_invokeRtControl_BASE llvm_hpvm_invokeRtControl
//#define llvm_hpvm_invokeRtControl_ADJUST_PR llvm_hpvm_invokeRtControl
//#define llvm_hpvm_invokeRtControl_ITERATE llvm_hpvm_invokeRtControl
......
#include <fstream>
#include <string>
#include <array>
#include <hpvm.h>
......@@ -49,6 +50,11 @@ void fifo_write_batch(FILE *fp, void *output_ptr) {
fwrite(output->host_data, 1, output->size_in_bytes, fp);
}
void write_accuracy(float accuracy) {
std::ofstream fout("final_accuracy");
fout << std::fixed << accuracy;
}
{% for node in nodes %}
void var_{{node.idx}}_node(
{%- for n in range(node.input_size) -%}
......@@ -134,6 +140,7 @@ int main(){
// Keep this open so the other side knows we have more batches to write
auto* fp = open_fifo("{{fifo_path_w}}", "wb");
float total_accuracy = 0;
for (int i = 0; i < batch_count; i++){
int start = i * batch_size, end = start + batch_size;
void *{{input_name}} = readInputBatch(input_pth, 0, start, end, {{input_shape|join(', ')}});
......@@ -145,11 +152,15 @@ int main(){
void *result = static_cast<RootIn*>(args)->r.tensor;
hpvm_request_tensor(result, 0);
llvm_hpvm_invokeRtControl(result, labels_pth, start, end);
uint32_t* labels = readLabelsBatch3(labels_pth, start, end);
float accuracy = computeAccuracy3(labels, result);
total_accuracy += accuracy * batch_size;
fifo_write_batch(fp, result);
freeBatchMemory();
}
fclose(fp);
write_accuracy(total_accuracy / input_size);
__hpvm__cleanup();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment