{"id":42105466,"url":"https://github.com/definelicht/hlslib","last_synced_at":"2026-01-26T13:13:52.360Z","repository":{"id":38359499,"uuid":"122331780","full_name":"definelicht/hlslib","owner":"definelicht","description":"A collection of extensions for Vitis and Intel FPGA OpenCL to improve developer quality of life.","archived":false,"fork":false,"pushed_at":"2025-01-20T20:51:43.000Z","size":591,"stargazers_count":311,"open_issues_count":5,"forks_count":58,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-01-20T21:39:29.413Z","etag":null,"topics":["cmake","fpga","high-level-synthesis","hpc","intel-fpga","intel-fpga-opencl","sdaccel","vitis","vivado-hls","xilinx"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/definelicht.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-21T12:10:04.000Z","updated_at":"2025-01-20T20:49:57.000Z","dependencies_parsed_at":"2024-04-23T08:39:06.199Z","dependency_job_id":null,"html_url":"https://github.com/definelicht/hlslib","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/definelicht/hlslib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/definelicht%2Fhlslib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/definelicht%2Fhlslib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/definelicht%2Fhlslib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/definelicht%2Fhlslib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/definelicht","download_url":"https://codeload.github.com/definelicht/hlslib/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/definelicht%2Fhlslib/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28779166,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T11:46:04.308Z","status":"ssl_error","status_checked_at":"2026-01-26T11:46:02.664Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cmake","fpga","high-level-synthesis","hpc","intel-fpga","intel-fpga-opencl","sdaccel","vitis","vivado-hls","xilinx"],"created_at":"2026-01-26T13:13:51.551Z","updated_at":"2026-01-26T13:13:52.351Z","avatar_url":"https://github.com/definelicht.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"_Do you use hlslib? Please consider [citing us](https://arxiv.org/abs/1910.04436), and let us know so we can feature your project in the list of examples._\n\n## Quick introduction\n\nhlslib is a collection of C++ headers, CMake files, and examples, aimed at improving the quality of life of HLS developers. The current repertoire primarily supports Vitis and Vitis HLS (formerly SDAccel and Vivado HLS), with some support for Intel FPGA OpenCL. An extended abstract describing the project is [available here](https://arxiv.org/abs/1910.04436).\n\nThis project is developed at the [Scalable Parallel Computing Lab](https://spcl.inf.ethz.ch/) (SPCL) at ETH Zurich (see our [github](https://github.com/spcl)).\n\n#### How do I install it?\n\nThere are a few ways:\n- Grab the headers and/or CMake files you need and stick them in your project.\n- Install hlslib using the standard CMake installation procedure to a location of your choice.\n- Clone this repository into your project as a git submodule and integrate it, with or without CMake.\n\n#### How do I use it?\n\nJust `#include` the header(s) you are interested in, and/or put the CMake files somewhere in your project directory and\nadd their path to your `${CMAKE_MODULE_PATH}`. You can see an example [here](https://github.com/spcl/gemm_hls)!\n\nOfficially supported versions of Vitis currently include 2021.2, 2021.1, 2020.2, 2020.1, and 2019.2. Older versions (including SDx and SDAccel) _might_ work, but should be used at your own discretion.\n\n## Feature overview\n\nWe have Doxygen! Set the CMake flag `HLSLIB_BUILD_DOCUMENTATION=ON` to generate the docs.\n\nA brief overview of hlslib features is given below.\n\n#### CMake integration\n\nFor integrating the Xilinx or Intel HLS tools in your project, the `FindVitis.cmake` and `FindIntelFPGAOpenCL.cmake` are provided in the `cmake` subdirectory. The scripts will set all necessary variables required to build both host and device code. It also provides the `add_vitis_kernel` and `add_vitis_program` functions, which will produce targets for building hardware emulation, hardware, and high-level synthesis.\n\nExample `CMakeLists.txt`:\n```cmake\nset(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} hlslib/cmake)\nfind_package(Vitis REQUIRED)\n\nadd_executable(MyHostExecutable src/MyHostExecutable.cpp)\ninclude_directories(${Vitis_INCLUDE_DIRS})\ntarget_link_libraries(MyHostExecutable ${Vitis_LIBRARIES})\n\n# Will populate the \"hw\", \"hw_emu\", and \"synthesis\" targets\nadd_vitis_kernel(MyKernel FILES src/MyKernel.cpp)\nadd_vitis_program(MyKernel xilinx_u250_gen3x16_xdma_3_1_202020_1)\n```\n\nKernels can then be built with:\n\n```bash\nmake hw\n```\n\nThe `add_vitis_kernel` and `add_vitis_program` functions takes a number of optional arguments that can be used to configure the hardware targets:\n\n```cmake\nadd_vitis_kernel(MyKernel\n                 FILES src/MyKernel.cpp src/MyKernelHelper.cpp\n                 # All flags below this are optional keywords, and any\n                 # combination of them can be specified/not specified.\n                 KERNEL MyKernelName  # If different from target name\n                 HLS_FLAGS \"-DMY_IMPORTANT_DEFINITION -O2\"\n                 DEPENDS include/MyHeader.h include/OtherDependency.h\n                 INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include hlslib/include\n                 PORT_MAPPING \"ddr0:DDR[0]\" \"ddr1:DDR[1]\")\nadd_vitis_kernel(MyOtherKernel\n                 FILES src/MyOtherKernel.cpp)\nadd_vitis_program(MyProgram\n                  xilinx_u250_gen3x16_xdma_3_1_202020_1  # Name of Vitis platform\n                  # All flags below this are optional keywords, and any\n                  # combination of them can be specified/not specified.\n                  KERNELS MyKernel       # If KERNELS is not specified, the function checks for a kernel\n                          MyOtherKernel  # with the same name as specified for the program\n                  # Connect multiple linked kernels using streaming interfaces\n                  CONNECTIVITY \"MyKernel_1.stream_out:MyOtherKernel_1.stream_in\"\n                  CLOCK 400  # Target a different clock frequency than the default\n                  CONFIG scripts/my_config.cfg  # Given as --config to Vitis\n                  SAVE_TEMPS ON  # Forwards --save-temps to Vitis\n                  BUILD_FLAGS \"-Os --export_script\"\n                  DEBUGGING ON  # Enables Chipscope debugging on all interfaces\n                  PROFILING ON)  # Enables profiling for stalls, data transfers, and execution\n```\n\n#### DataPack\n\nThe `hlslib::DataPack` class located in `hlslib/xilinx/DataPack.h` facilitates SIMD-style vectorization, and makes it easy to build wide data paths in your code.\n\nExamples usage:\n```cpp\nhlslib::DataPack\u003cfloat, 4\u003e Foo(hlslib::DataPack\u003cfloat, 4\u003e \u0026a,\n                               hlslib::DataPack\u003cfloat, 4\u003e \u0026b) {\n  #pragma HLS INLINE     \n  auto add = a + b; // Vector addition\n  add[0] = add[1];  // Indexing for both reads and writes\n  return 0.5 * add; // Element-wise multiplication by a scalar\n}\n```\n\n#### Simulation\n\nFor kernels with multiple processing elements (PEs) executing in parallel, the `hlslib/xilinx/Simulation.h` adds some convenient macros to simulate this behavior, by wrapping each PE in a thread executed in parallel, all of which are joined when the program terminates.\n\nExample usage:\n```cpp\nHLSLIB_DATAFLOW_INIT();\nhlslib::Stream\u003cData_t\u003e pipes[kStages + 1];\nHLSLIB_DATAFLOW_FUNCTION(MemoryToStream, memory_in, pipes[0]);\nfor (int i = 0; i \u003c kStages; ++i) {\n  #pragma HLS UNROLL\n  HLSLIB_DATAFLOW_FUNCTION(PE, pipes[i], pipes[i + 1]); // Launches new C++ thread\n}\nHLSLIB_DATAFLOW_FUNCTION(StreamToMemory, pipes[kStages], memory_out);\nHLSLIB_DATAFLOW_FINALIZE(); // In simulation mode, joins threads created as dataflow functions.\n```\n\nWhen building programs using the simulation features, you must link against a thread library (e.g., pthreads).\n\n#### Stream\n\nWhile Vivado HLS provides the `hls::stream` class, it is somewhat lacking in features, in particular when simulating multiple processing elements. The `hlslib::Stream` class in `hlslib/xilinx/Stream.h` compiles to Vivado HLS streams, but provides a richer interface. hlslib streams are:\n- thread-safe during simulation, allowing producer and consumer to be executed in parallel;\n- bounded, simulating the finite capacity of hardware FIFOs, allowing easier detection of deadlocks in software; and\n- self-contained, allowing the stream depth and implementation (e.g., using LUTRAM or BRAM) to be specified directly in the object, without excess pragmas.\n\nExample usage:\n```cpp\nvoid Bar(hlslib::Stream\u003cint\u003e \u0026a, hlslib::Stream\u003cint\u003e \u0026b, int N) {\n  for (int i = 0; i \u003c N; ++i) {\n    #pragma HLS PIPELINE II=1\n    auto read = a.Pop(); // Queue-like interface\n    b.Push(read + 1);\n  }\n}\n\nvoid Foo(hlslib::Stream\u003cint\u003e \u0026in_stream, // Specifying stream depth is optional\n         hlslib::Stream\u003cint\u003e \u0026out_stream, int N) {\n  #pragma HLS DATAFLOW\n  \n  hlslib::Stream\u003cint, 4\u003e foo_pipe; // Implements a FIFO of depth 4\n  \n  // Dataflow functions running in parallel\n  HLSLIB_DATAFLOW_INIT();\n  HLSLIB_DATAFLOW_FUNCTION(Bar, in_stream, foo_pipe, N);\n  HLSLIB_DATAFLOW_FUNCTION(Bar, foo_pipe, out_stream, N);\n  HLSLIB_DATAFLOW_FINALIZE();\n}\n```\n\n#### OpenCL host code\n\nTo greatly reduce the amount of boilerplate code required to create and launch OpenCL kernels, and to handle FPGA-specific configuration required by the vendors, hlslib provides a C++14 convenience interface in `hlslib/xilinx/OpenCL.h` and `hlslib/intel/OpenCL.h` for Xilinx and Intel FPGA OpenCL, respectively.\n\nExample usage:\n```cpp\nusing hlslib::ocl;\nContext context;\nstd::vector\u003cfloat\u003e input_host(N, 5);   \nstd::vector\u003cfloat\u003e output_host(N, 5);\nauto input_device = context.MakeBuffer\u003cfloat, Access::read\u003e(\n    MemoryBank::bank0, input_host.cbegin(), input_end.cend());\nauto output_device = context.MakeBuffer\u003cfloat, Access::write\u003e(MemoryBank::bank1, N);\nauto program = context.MakeProgram(\"MyKernel.xclbin\");\nauto kernel = program.MakeKernel(\"MyKernel\", input_device, output_device, N);\nkernel.ExecuteTask();\noutput_device.CopyToHost(output_host.begin());\n```\n\n#### Other features\n\nVarious other features are provided, including:\n* Classes to flatten loop nests and keep track of indices (`include/hlslib/xilinx/Flatten.h`), both for bounds known at runtime (`hlslib::Flatten`) and bounds known at compile-time (`hlslib::ConstFlatten`). Example usage can be found in `xilinx_test/kernels/Flatten.cpp`.\n* Various compile-time functions commonly used when designing hardware, such as log2, in `include/hlslib/xilinx/Utility.h`.\n* A template tcl-file that can be used with CMake or another templating engine to produce a high-level synthesis script.\n* `xilinx_test/CMakeLists.txt` that builds a number of tests to verify hlslib functionality, doubling as a reference for how to integrate HLS projects with CMake using the provided module files .\n* An example of how to use the Simulation and Stream headers, at `xilinx_test/kernels/MultiStageAdd.cpp`, both as a host-only simulation (`xilinx_test/test/TestMultiStageAdd.cpp`), and as a hardware kernel (`xilinx_test/host/RunMultiStageAdd.cpp`). \n* `include/hlslib/xilinx/Accumulate.h`, which includes a streaming implementation of accumulation, including for type/operator combinations with a non-zero latency (such as floating point addition). Example kernels of usage for both integer and floating point types are included as `xilinx_test/kernel/AccumulateInt.cpp` and `xilinx_test/kernel/AccumulateFloat.cpp`, respectively. \n* `include/hlslib/xilinx/Operators.h`, which includes some commonly used operators as functors to be plugged into templated functions such as `TreeReduce` and `Accumulate`.\n* `include/hlslib/xilinx/Axi.h`, which implements the AXI Stream interface and the bus interfaces required by the DataMover IP, enabling the use of a command stream-based memory interface for HLS kernels if packaged as an RTL kernel where the DataMover IP is connected to the AXI interfaces.\n\nSome of these headers depend on others. Please refer to the source code.\n\n### Ubuntu packages\n\nOn Ubuntu, the following package might need to be installed to run hardware emulation:\n\n```\nsudo apt install libc6-dev-i386\n```\n\n## Projects using hlslib\n\n- [Matrix multiplication code](https://github.com/spcl/gemm_hls) [1]: Uses a wide range of hlslib features, including simulation, streams, vectors, CMake integration, and OpenCL wrapper code.\n- [SMI](https://github.com/spcl/SMI) [2]: Streaming message passing library for inter-FPGA communication in OpenCL. Uses hlslib for OpenCL host code.\n- [HelmGemm](https://ieeexplore.ieee.org/document/8825124/) [3]: uses the simulation features of hlslib, and incorporates the matrix multiplication code above.\n- [DaCe](https://github.com/spcl/dace) [4]: A data-centric parallel programming framework targeting a wide range of architectures, including both Intel and Xilinx FPGAs. Uses hlslib for CMake integration, OpenCL host code, vectors, streams, and simulation.\n- [REVD](https://arxiv.org/abs/2102.00294) [5]: Uses hlslib streaming and simulation features to accelerate the deconvolution workloads of GANs with reverse looping optimizations on Xilinx FPGAs.\n\n_If you use hlslib in your project, please let us know, so we can add you to the list._\n\n## Bugs and feature requests\n\nPlease use the issue tracker.\n\n## Publication\n\nIf your project uses hlslib, please consider citing us:\n\n**BibTeX:**\n```\n@article{hlslib,\n  title={{hlslib}: Software Engineering for Hardware Design},\n  author={de~Fine~Licht, Johannes and Hoefler, Torsten},\n  journal={arXiv:1910.04436},\n  year={2019}\n}\n```\n\n**Plain text:**\n```\nJ. de Fine Licht and T. Hoefler, \"hlslib: Software Engineering for Hardware Design\", arXiv:1910.04436 (2019).\n```\n\n## References\n\n- [1] Johannes de Fine Licht, Grzegorz Kwasniewski, and Torsten Hoefler. _\"Flexible Communication Avoiding Matrix Multiplication on FPGA with High-Level Synthesis\"_, in Proceedings of 28th ACM/SIGDA International Symposium on Field-Programmable Gate Arrays (FPGA'20).\n- [2] Tiziano De Matteis, Johannes de Fine Licht, Jakub Beránek, and Torsten Hoefler. _\"Streaming Message Interface: High-Performance Distributed Memory Programming on Reconfigurable Hardware\"_, in Proceedings of the International Conference for High Performance Computing, Networking, Storage and Analysis (SC'19).\n- [3] Dionysios Diamantopoulos, and Christoph Hagleitner. _\"HelmGemm: Managing GPUs and FPGAs for transprecision GEMM workloads in containerized environments.\"_, in Proceedings of the 2019 IEEE 30th International Conference on Application-specific Systems, Architectures and Processors (ASAP'19).\n- [4] Tal Ben-Nun, Johannes de Fine Licht, Alexandros Nikolaos Ziogas, Timo Schneider, and Torsten Hoefler. _\"Stateful Dataflow Multigraphs: A Data-Centric Model for High-Performance Parallel Programs\"_, in Proceedings of the International Conference for High Performance Computing, Networking, Storage and Analysis (SC'19).\n- [5] Ian Colbert, Jake Daly, Ken Kreutz-Delgado, and Srinjoy Das. _\"A Competitive Edge: Can FPGAs Beat GPUs at DCNN Inference Acceleration in Resource-Limited Edge Computing Applications?\"_, arXiv:2102.00294.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdefinelicht%2Fhlslib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdefinelicht%2Fhlslib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdefinelicht%2Fhlslib/lists"}