Skip to content

Commit

Permalink
Add VivadoHLS target feature.
Browse files Browse the repository at this point in the history
Use this feature to infer whether to use HLS codegen.
It fixes #7
  • Loading branch information
jingpu committed Jun 15, 2017
1 parent 4d1d8d3 commit dcb51ee
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 46 deletions.
6 changes: 6 additions & 0 deletions src/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ enum class DeviceAPI {
GLSL,
OpenGLCompute,
Metal,
//----- HLS Modification Begins -----//
HLS,
//----- HLS Modification Ends -------//
Hexagon
};

Expand All @@ -331,6 +334,9 @@ const DeviceAPI all_device_apis[] = {DeviceAPI::None,
DeviceAPI::GLSL,
DeviceAPI::OpenGLCompute,
DeviceAPI::Metal,
//----- HLS Modification Begins -----//
DeviceAPI::HLS,
//----- HLS Modification Ends -------//
DeviceAPI::Hexagon};

namespace Internal {
Expand Down
5 changes: 5 additions & 0 deletions src/IRPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ ostream &operator<<(ostream &out, const DeviceAPI &api) {
case DeviceAPI::Metal:
out << "<Metal>";
break;
//----- HLS Modification Begins -----//
case DeviceAPI::HLS:
out << "<HLS>";
break;
//----- HLS Modification Ends -------//
case DeviceAPI::Hexagon:
out << "<Hexagon>";
break;
Expand Down
39 changes: 16 additions & 23 deletions src/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,29 +372,22 @@ void Module::compile(const Outputs &output_files) const {
if (!output_files.c_source_name.empty()) {
debug(1) << "Module.compile(): c_source_name " << output_files.c_source_name << "\n";
std::ofstream file(output_files.c_source_name);
Internal::CodeGen_C cg(file,
target(),
target().has_feature(Target::CPlusPlusMangling) ?
Internal::CodeGen_C::CPlusPlusImplementation : Internal::CodeGen_C::CImplementation);
cg.compile(*this);
}
if (!output_files.hls_source_name.empty()) {
debug(1) << "Module.compile(): hls_source_name " << output_files.hls_source_name << "\n";
std::ofstream file(output_files.hls_source_name);
Internal::CodeGen_HLS_Testbench cg(file,
target(),
target().has_feature(Target::CPlusPlusMangling) ?
Internal::CodeGen_C::CPlusPlusImplementation : Internal::CodeGen_C::CImplementation);
cg.compile(*this);
}
if (!output_files.zynq_c_source_name.empty()) {
debug(1) << "Module.compile(): zynq_c_source_name " << output_files.zynq_c_source_name << "\n";
std::ofstream file(output_files.zynq_c_source_name);
Internal::CodeGen_Zynq_C cg(file,
target(),
target().has_feature(Target::CPlusPlusMangling) ?
Internal::CodeGen_C::CPlusPlusImplementation : Internal::CodeGen_C::CImplementation);
cg.compile(*this);
//----- HLS Modification Begins -----//
CodeGen_C::OutputKind output_kind =
target().has_feature(Target::CPlusPlusMangling)
? CodeGen_C::CPlusPlusImplementation
: CodeGen_C::CImplementation;
CodeGen_C *cg;
if (target().has_feature(Target::VivadoHLS)) {
cg = new CodeGen_HLS_Testbench(file, target(), output_kind);
} else if (target().has_feature(Target::Zynq)) {
cg = new CodeGen_Zynq_C(file, target(), output_kind);
} else {
cg = new CodeGen_C(file, target(), output_kind);
}
cg->compile(*this);
delete cg;
//----- HLS Modification Ends -------//
}
if (!output_files.stmt_name.empty()) {
debug(1) << "Module.compile(): stmt_name " << output_files.stmt_name << "\n";
Expand Down
16 changes: 0 additions & 16 deletions src/Outputs.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,6 @@ struct Outputs {
return updated;
}

/** Make a new Outputs struct that emits everything this one does
* and also a HLS C source file with the given name. */
Outputs hls_source(const std::string &hls_source_name) {
Outputs updated = *this;
updated.hls_source_name = hls_source_name;
return updated;
}

/** Make a new Outputs struct that emits everything this one does
* and also a Zynq C source file with the given name. */
Outputs zynq_c_source(const std::string &zynq_c_source_name) {
Outputs updated = *this;
updated.zynq_c_source_name = zynq_c_source_name;
return updated;
}

/** Make a new Outputs struct that emits everything this one does
* and also a stmt file with the given name. */
Outputs stmt(const std::string &stmt_name) const {
Expand Down
13 changes: 8 additions & 5 deletions src/Pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,22 +206,25 @@ void Pipeline::compile_to_c(const string &filename,
m.compile(Outputs().c_source(output_name(filename, m, ".c")));
}


//----- HLS Modification Begins -----//
void Pipeline::compile_to_hls(const string &filename,
const vector<Argument> &args,
const string &fn_name,
const Target &target) {
Module m = compile_to_module(args, fn_name, target);
m.compile(Outputs().hls_source(output_name(filename, m, ".cpp")));
Target new_target = target.with_feature(Target::VivadoHLS);
Module m = compile_to_module(args, fn_name, new_target);
m.compile(Outputs().c_source(output_name(filename, m, ".cpp")));
}

void Pipeline::compile_to_zynq_c(const string &filename,
const vector<Argument> &args,
const string &fn_name,
const Target &target) {
Module m = compile_to_module(args, fn_name, target);
m.compile(Outputs().zynq_c_source(output_name(filename, m, ".c")));
Target new_target = target.with_feature(Target::Zynq);
Module m = compile_to_module(args, fn_name, new_target);
m.compile(Outputs().c_source(output_name(filename, m, ".c")));
}
//----- HLS Modification Ends -------//

void Pipeline::print_loop_nest() {
user_assert(defined()) << "Can't print loop nest of undefined Pipeline.\n";
Expand Down
3 changes: 3 additions & 0 deletions src/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ const std::map<std::string, Target::Feature> feature_name_map = {
{"profile", Target::Profile},
{"no_runtime", Target::NoRuntime},
{"metal", Target::Metal},
//----- HLS Modification Begins -----//
{"vivado_hls", Target::VivadoHLS},
{"zynq", Target::Zynq},
//----- HLS Modification Ends -------//
{"mingw", Target::MinGW},
{"c_plus_plus_name_mangling", Target::CPlusPlusMangling},
{"large_buffers", Target::LargeBuffers},
Expand Down
3 changes: 3 additions & 0 deletions src/Target.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ struct Target {
Profile = halide_target_feature_profile,
NoRuntime = halide_target_feature_no_runtime,
Metal = halide_target_feature_metal,
//----- HLS Modification Begins -----//
VivadoHLS = halide_target_feature_vivado_hls,
Zynq = halide_target_feature_zynq,
//----- HLS Modification Ends -------//
MinGW = halide_target_feature_mingw,
CPlusPlusMangling = halide_target_feature_c_plus_plus_mangling,
LargeBuffers = halide_target_feature_large_buffers,
Expand Down
5 changes: 3 additions & 2 deletions src/runtime/HalideRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -944,8 +944,9 @@ typedef enum halide_target_feature_t {
halide_target_feature_hvx_v65 = 47, ///< Enable Hexagon v65 architecture.
halide_target_feature_hvx_v66 = 48, ///< Enable Hexagon v66 architecture.
//----- HLS Modification Begins -----//
halide_target_feature_zynq = 49, // Enable Xilinx Zynq runtime.
halide_target_feature_end = 50 ///< A sentinel. Every target is considered to have this feature, and setting this feature does nothing.
halide_target_feature_vivado_hls = 49, ///< Enable Vivado HLS code generation.
halide_target_feature_zynq = 50, ///< Enable Xilinx Zynq runtime.
halide_target_feature_end = 51 ///< A sentinel. Every target is considered to have this feature, and setting this feature does nothing.
//----- HLS Modification Ends -------//
} halide_target_feature_t;

Expand Down

0 comments on commit dcb51ee

Please sign in to comment.