15 #include "fletchgen/basic_types.h"
17 #include <cerata/api.h>
18 #include <cerata/vhdl/vhdl.h>
19 #include <fletcher/common.h>
28 using cerata::integer;
29 using cerata::parameter;
41 VEC_FACTORY(int16, 16)
42 VEC_FACTORY(uint16, 16)
43 VEC_FACTORY(int32, 32)
44 VEC_FACTORY(uint32, 32)
45 VEC_FACTORY(int64, 64)
46 VEC_FACTORY(uint64, 64)
47 VEC_FACTORY(float8, 8)
48 VEC_FACTORY(float16, 16)
49 VEC_FACTORY(float32, 32)
50 VEC_FACTORY(float64, 64)
51 VEC_FACTORY(date32, 32)
52 VEC_FACTORY(date64, 64)
53 VEC_FACTORY(time32, 32)
54 VEC_FACTORY(time64, 64)
55 VEC_FACTORY(timestamp, 64)
56 VEC_FACTORY(decimal128, 128)
59 VEC_FACTORY(offset, 32)
63 static std::shared_ptr<ClockDomain> result = std::make_shared<ClockDomain>(
"kcd");
67 std::shared_ptr<ClockDomain>
bus_cd() {
68 static std::shared_ptr<ClockDomain> result = std::make_shared<ClockDomain>(
"bcd");
73 std::shared_ptr<Type>
cr() {
74 static std::shared_ptr<Type> result = record(
"cr", {
76 field(
"reset", bit())});
77 result->meta[cerata::vhdl::meta::NO_INSERT_SIGNAL] =
"true";
81 std::shared_ptr<Type>
valid(
int width,
bool on_primitive) {
82 if (width > 1 || on_primitive) {
83 return vector(
"valid", width);
89 std::shared_ptr<Type>
ready(
int width,
bool on_primitive) {
90 if (width > 1 || on_primitive) {
91 return vector(
"ready", width);
98 std::shared_ptr<Type>
data(
int width) {
99 std::shared_ptr<Type> result = vector(
"data", width);
106 std::shared_ptr<Type>
length(
int width) {
107 std::shared_ptr<Type> result = vector(
"length", width);
113 std::shared_ptr<Type>
count(
int width) {
114 std::shared_ptr<Type> result = vector(width);
121 std::shared_ptr<Type>
dvalid(
int width,
bool on_primitive) {
122 if (width > 1 || on_primitive) {
123 return vector(
"dvalid", width);
125 return bit(
"dvalid");
129 std::shared_ptr<Type>
last(
int width,
bool on_primitive) {
130 std::shared_ptr<Type> result;
131 if (width > 1 || on_primitive) {
132 result = vector(
"last", width);
134 result = bit(
"last");
141 auto fwt =
dynamic_cast<const arrow::FixedWidthType *
>(&arrow_type);
142 if (fwt ==
nullptr) {
143 FLETCHER_LOG(ERROR,
"Not a fixed-width Arrow type: " + arrow_type.ToString());
145 return fwt->bit_width();
151 switch (arrow_type->id()) {
152 case arrow::Type::UINT8:
return uint8();
153 case arrow::Type::UINT16:
return uint16();
154 case arrow::Type::UINT32:
return uint32();
155 case arrow::Type::UINT64:
return uint64();
156 case arrow::Type::INT8:
return int8();
157 case arrow::Type::INT16:
return int16();
158 case arrow::Type::INT32:
return int32();
159 case arrow::Type::INT64:
return int64();
160 case arrow::Type::HALF_FLOAT:
return float16();
161 case arrow::Type::FLOAT:
return float32();
162 case arrow::Type::DOUBLE:
return float64();
163 case arrow::Type::BOOL:
return bool_();
164 case arrow::Type::DATE32:
return date32();
165 case arrow::Type::DATE64:
return date64();
166 case arrow::Type::TIME32:
return time32();
167 case arrow::Type::TIME64:
return time64();
168 case arrow::Type::TIMESTAMP:
return timestamp();
169 case arrow::Type::DECIMAL:
return decimal128();
170 default:
throw std::runtime_error(
"Unsupported Arrow DataType: " + arrow_type->ToString());
173 auto fwt = std::dynamic_pointer_cast<arrow::FixedWidthType>(arrow_type);
174 if (fwt ==
nullptr) {
175 FLETCHER_LOG(ERROR,
"Not a fixed-width Arrow type: " + arrow_type->ToString());
177 return cerata::vector(epc * fwt->bit_width());
181 std::optional<cerata::Port *>
GetClockResetPort(cerata::Graph *graph,
const ClockDomain &domain) {
182 for (
auto crn : graph->GetNodes()) {
183 if (crn->type()->IsEqual(*
cr()) && crn->IsPort()) {
185 if (crn->AsPort()->domain().get() == &domain) {
186 return crn->AsPort();
Contains all classes and functions related to Fletchgen.
std::shared_ptr< ClockDomain > kernel_cd()
Fletcher accelerator clock domain.
std::shared_ptr< Type > valid(int width, bool on_primitive)
Fletcher valid.
std::shared_ptr< Type > cr()
Fletcher clock/reset;.
std::shared_ptr< Type > data(int width)
Fletcher data.
std::shared_ptr< Type > ConvertFixedWidthType(const std::shared_ptr< arrow::DataType > &arrow_type, int epc)
Convert a fixed-width arrow::DataType to a fixed-width Fletcher Type.
std::shared_ptr< Type > ready(int width, bool on_primitive)
Fletcher ready.
std::shared_ptr< Type > dvalid(int width, bool on_primitive)
Fletcher dvalid.
std::shared_ptr< Type > length(int width)
Fletcher length.
std::shared_ptr< Type > count(int width)
Fletcher count.
int GetFixedWidthTypeBitWidth(const arrow::DataType &arrow_type)
Returns the bit-width of a fixed-width Arrow type. Throws if it's not a fixed-width type.
std::shared_ptr< ClockDomain > bus_cd()
Fletcher bus clock domain.
std::shared_ptr< Type > last(int width, bool on_primitive)
Fletcher last.
std::optional< cerata::Port * > GetClockResetPort(cerata::Graph *graph, const ClockDomain &domain)
Return the clock/reset port of a graph for a specific clock domain, if it exists.