Fletchgen
The Fletcher Design Generator
recordbatch.h
1 // Copyright 2018-2019 Delft University of Technology
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <arrow/api.h>
18 #include <cerata/api.h>
19 #include <fletcher/common.h>
20 
21 #include <utility>
22 #include <string>
23 #include <vector>
24 #include <memory>
25 
26 #include "fletchgen/utils.h"
27 #include "fletchgen/basic_types.h"
28 #include "fletchgen/schema.h"
29 #include "fletchgen/bus.h"
30 
31 namespace fletchgen {
32 
33 using cerata::Port;
34 using cerata::Component;
35 using cerata::Instance;
36 using fletcher::Mode;
37 using cerata::default_domain;
38 
52 struct FieldPort : public Port {
54  enum Function {
57  UNLOCK
59 
61  std::shared_ptr<FletcherSchema> fletcher_schema_;
63  std::shared_ptr<arrow::Field> field_;
65  bool profile_ = false;
66 
78  FieldPort(std::string name,
79  Function function,
80  std::shared_ptr<arrow::Field> field,
81  std::shared_ptr<FletcherSchema> fletcher_schema,
82  std::shared_ptr<cerata::Type> type,
83  Port::Dir dir,
84  std::shared_ptr<ClockDomain> domain,
85  bool profile)
86  : Port(std::move(name), std::move(type), dir, std::move(domain)),
87  function_(function),
88  fletcher_schema_(std::move(fletcher_schema)),
89  field_(std::move(field)),
90  profile_(profile) {}
91 
93  std::shared_ptr<Object> Copy() const override;
94 };
95 
104 std::shared_ptr<FieldPort> arrow_port(const std::shared_ptr<FletcherSchema> &fletcher_schema,
105  const std::shared_ptr<arrow::Field> &field,
106  bool reverse,
107  const std::shared_ptr<ClockDomain> &domain = default_domain());
118 std::shared_ptr<FieldPort> command_port(const std::shared_ptr<FletcherSchema> &schema,
119  const std::shared_ptr<arrow::Field> &field,
120  const std::shared_ptr<Node> &index_width,
121  const std::shared_ptr<Node> &tag_width,
122  std::optional<std::shared_ptr<Node>> addr_width = std::nullopt,
123  const std::shared_ptr<ClockDomain> &domain = default_domain());
124 
133 std::shared_ptr<FieldPort> unlock_port(const std::shared_ptr<FletcherSchema> &schema,
134  const std::shared_ptr<arrow::Field> &field,
135  const std::shared_ptr<Node> &tag_width,
136  const std::shared_ptr<ClockDomain> &domain = default_domain());
137 
150 struct RecordBatch : public Component {
151  public:
153  RecordBatch(const std::string &name,
154  const std::shared_ptr<FletcherSchema> &fletcher_schema,
155  fletcher::RecordBatchDescription batch_desc);
157  std::vector<std::shared_ptr<FieldPort>> GetFieldPorts(const std::optional<FieldPort::Function> &function = {}) const;
159  fletcher::RecordBatchDescription batch_desc() const { return batch_desc_; }
163  Mode mode() const { return mode_; }
164 
165  protected:
173  void AddArrays(const std::shared_ptr<FletcherSchema> &fletcher_schema);
174 
176  std::vector<Instance *> array_instances_;
178  std::shared_ptr<FletcherSchema> fletcher_schema_;
180  Mode mode_ = Mode::READ;
182  fletcher::RecordBatchDescription batch_desc_;
183 
184  private:
185  void ConnectBusPorts(Instance *array, const std::string &prefix, cerata::NodeMap *rebinding);
186 };
187 
189 std::shared_ptr<RecordBatch> record_batch(const std::string &name,
190  const std::shared_ptr<FletcherSchema> &fletcher_schema,
191  const fletcher::RecordBatchDescription &batch_desc);
192 
193 } // namespace fletchgen
Contains all classes and functions related to Fletchgen.
Definition: array.cc:29
Component * array(Mode mode)
Return a Cerata component model of an Array(Reader/Writer).
Definition: array.cc:139
std::shared_ptr< FieldPort > arrow_port(const std::shared_ptr< FletcherSchema > &fletcher_schema, const std::shared_ptr< arrow::Field > &field, bool reverse, const std::shared_ptr< ClockDomain > &domain)
Construct a field-derived port for Arrow data.
Definition: recordbatch.cc:199
std::shared_ptr< FieldPort > unlock_port(const std::shared_ptr< FletcherSchema > &schema, const std::shared_ptr< arrow::Field > &field, const std::shared_ptr< Node > &tag_width, const std::shared_ptr< ClockDomain > &domain)
Construct a field-derived unlock port.
Definition: recordbatch.cc:235
std::shared_ptr< RecordBatch > record_batch(const std::string &name, const std::shared_ptr< FletcherSchema > &fletcher_schema, const fletcher::RecordBatchDescription &batch_desc)
Make a new RecordBatch(Reader/Writer) component, based on a Fletcher schema.
Definition: recordbatch.cc:190
std::shared_ptr< FieldPort > command_port(const std::shared_ptr< FletcherSchema > &schema, const std::shared_ptr< arrow::Field > &field, const std::shared_ptr< Node > &index_width, const std::shared_ptr< Node > &tag_width, std::optional< std::shared_ptr< Node >> addr_width, const std::shared_ptr< ClockDomain > &domain)
Construct a field-derived command port.
Definition: recordbatch.cc:218
A port derived from an Arrow field.
Definition: recordbatch.h:52
std::shared_ptr< arrow::Field > field_
The Arrow field this port was derived from.
Definition: recordbatch.h:63
std::shared_ptr< FletcherSchema > fletcher_schema_
The Fletcher schema this port was derived from.
Definition: recordbatch.h:61
std::shared_ptr< Object > Copy() const override
Create a deep-copy of the FieldPort.
Definition: recordbatch.cc:245
FieldPort(std::string name, Function function, std::shared_ptr< arrow::Field > field, std::shared_ptr< FletcherSchema > fletcher_schema, std::shared_ptr< cerata::Type > type, Port::Dir dir, std::shared_ptr< ClockDomain > domain, bool profile)
Construct a new port derived from an Arrow field.
Definition: recordbatch.h:78
bool profile_
Whether this field port should be profiled.
Definition: recordbatch.h:65
Function
Enumeration of FieldPort functions.
Definition: recordbatch.h:54
@ UNLOCK
Port that signals the kernel a command was completed.
Definition: recordbatch.h:57
@ ARROW
Port with Arrow data.
Definition: recordbatch.h:55
@ COMMAND
Port to issue commands to the generated interface.
Definition: recordbatch.h:56
enum fletchgen::FieldPort::Function function_
The function of this FieldPort.
A RecordBatch aggregating ArrayReaders/Writers.
Definition: recordbatch.h:150
std::shared_ptr< FletcherSchema > fletcher_schema_
Fletcher schema implemented by this RecordBatch(Reader/Writer)
Definition: recordbatch.h:178
Mode mode() const
Return the mode (read or write) of this RecordBatch.
Definition: recordbatch.h:163
std::vector< std::shared_ptr< FieldPort > > GetFieldPorts(const std::optional< FieldPort::Function > &function={}) const
Obtain all ports derived from an Arrow field with a specific function.
Definition: recordbatch.cc:158
RecordBatch(const std::string &name, const std::shared_ptr< FletcherSchema > &fletcher_schema, fletcher::RecordBatchDescription batch_desc)
RecordBatch constructor.
Definition: recordbatch.cc:35
FletcherSchema * schema()
Return the Fletcher schema this RecordBatch component is based on.
Definition: recordbatch.h:161
fletcher::RecordBatchDescription batch_desc_
The RecordBatch description.
Definition: recordbatch.h:182
std::vector< Instance * > array_instances_
A mapping from ArrayReader/Writer instances to their bus ports.
Definition: recordbatch.h:176
void AddArrays(const std::shared_ptr< FletcherSchema > &fletcher_schema)
Adds all ArrayReaders/Writers, un-concatenates ports and connects it to the top-level of this compone...
Definition: recordbatch.cc:53
Mode mode_
Whether to read or write from/to the in-memoRecordBatch.
Definition: recordbatch.h:180
fletcher::RecordBatchDescription batch_desc() const
Return the description of the RecordBatch this component is based on.
Definition: recordbatch.h:159