-
Notifications
You must be signed in to change notification settings - Fork 31
/
design.cc
111 lines (92 loc) · 3.62 KB
/
design.cc
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
// Copyright 2018 Delft University of Technology
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <cerata/api.h>
#include <string>
#include <deque>
#include "fletcher/common.h"
#include "fletchgen/design.h"
#include "fletchgen/recordbatch.h"
namespace fletchgen {
using cerata::OutputSpec;
/// Short-hand for vector of RecordBatches.
using RBVector = std::vector<std::shared_ptr<arrow::RecordBatch>>;
static std::optional<std::shared_ptr<arrow::RecordBatch>> GetRecordBatchWithName(const RBVector &batches,
const std::string &name) {
for (const auto &b : batches) {
if (fletcher::GetMeta(*b->schema(), "fletcher_name") == name) {
return b;
}
}
return std::nullopt;
}
fletchgen::Design fletchgen::Design::GenerateFrom(const std::shared_ptr<Options> &opts) {
Design ret;
ret.options = opts;
// Attempt to create a SchemaSet from all schemas that can be detected in the options.
FLETCHER_LOG(INFO, "Creating SchemaSet.");
ret.schema_set = SchemaSet::Make(ret.options->kernel_name);
// Add all schemas from the list of schema files
for (const auto &arrow_schema : ret.options->schemas) {
ret.schema_set->AppendSchema(arrow_schema);
}
// Add all schemas from the recordbatches and add all recordbatches.
for (const auto &recordbatch : ret.options->recordbatches) {
ret.schema_set->AppendSchema(recordbatch->schema());
}
ret.schema_set->Sort();
// Now that we have every Schema, for every Schema, figure out if there is a RecordBatch in the input options.
// If there is, add a description of the RecordBatch to this design.
// If there isn't, create a virtual RecordBatch based on the schema.
for (const auto &fletcher_schema : ret.schema_set->schemas()) {
auto rb = GetRecordBatchWithName(ret.options->recordbatches, fletcher_schema->name());
fletcher::RecordBatchDescription rbd;
if (rb) {
fletcher::RecordBatchAnalyzer rba(&rbd);
rba.Analyze(**rb);
} else {
fletcher::SchemaAnalyzer sa(&rbd);
sa.Analyze(*fletcher_schema->arrow_schema());
}
ret.batch_desc.push_back(rbd);
}
// Generate the hardware structure through Mantle and extract all subcomponents.
FLETCHER_LOG(INFO, "Generating Mantle...");
ret.mantle = Mantle::Make(ret.schema_set);
ret.kernel = ret.mantle->kernel();
for (const auto &recordbatch_component : ret.mantle->recordbatch_components()) {
ret.recordbatches.push_back(recordbatch_component);
}
return ret;
}
std::deque<cerata::OutputSpec> Design::GetOutputSpec() {
std::deque<OutputSpec> result;
OutputSpec omantle, okernel;
// Mantle
omantle.comp = mantle;
omantle.meta[cerata::vhdl::metakeys::OVERWRITE_FILE] = "true";
result.push_back(omantle);
// Kernel
okernel.comp = kernel;
okernel.meta[cerata::vhdl::metakeys::OVERWRITE_FILE] = "false";
result.push_back(okernel);
// Readers
for (const auto &reader : recordbatches) {
OutputSpec oreader;
oreader.comp = reader;
oreader.meta[cerata::vhdl::metakeys::OVERWRITE_FILE] = "true";
result.push_back(oreader);
}
return result;
}
} // namespace fletchgen