File size: 2,464 Bytes
17db41a | 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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
#pragma once
#include "logging.h"
#include "device_functions-generated.h"
#include "model_interface.h"
#include "raii_wrapper.h"
#include "model.h"
#include "macros.h"
#include <algorithm>
#include <deque>
#include <fstream>
#include <iostream>
#include <string>
#include <unordered_map>
#include <math.h>
namespace ait {
// Model is the class that actually performs inference. It owns memory for
// intermediate tensors and dynamic dimensions. Constants are owned by
// the model's owning container object, and input/output memory is owned
// by the user.
// Once an inference run has started, it is not safe to re-use the Model
// until the run has finished!
class ConstantFolder : public ModelBase<ConstantFolder> {
public:
ConstantFolder(
size_t blob_size,
size_t workspace_size,
size_t unique_workspace_size,
size_t num_inputs,
size_t num_outputs,
size_t num_unbound_constants,
uint8_t* constants,
AITemplateAllocator& allocator)
: ModelBase(
blob_size,
workspace_size,
unique_workspace_size,
num_inputs,
num_outputs,
num_unbound_constants,
constants,
allocator) {
auto* blob_ptr = static_cast<uint8_t*>(blob_.get());
}
void SetUpInputsOutputs() {
}
void ResetConstants(uint8_t* constants) {
/*
* This can be called if we want to use a different piece of memory
* for the constants to be consumed.
*/
}
void DeviceToDeviceCopies(StreamType stream) {
}
void RunImpl(StreamType stream) {
DeviceToDeviceCopies(stream);
}
void ProfileImpl(StreamType stream, size_t iters, const std::string& filename) {
std::ofstream ss(filename);
if (!ss) {
throw std::runtime_error(std::string("Could not open file ") + filename);
}
ss << "{\n";
ss << "}\n";
DeviceToDeviceCopies(stream);
std::cout << "AIT per op profiling finished." << std::endl;
}
static std::unique_ptr<ConstantFolder> Create(
AITemplateAllocator& allocator,
uint8_t* constants
) {
return std::make_unique<ConstantFolder>(
0,
0,
0,
0,
0,
0,
constants,
allocator
);
}
private:
};
} // namespace ait |