Skip to content

Commit 4459deb

Browse files
authored
Merge pull request #185 from lucat1/master
Allow installing the Coyote software library (and simulation)
2 parents 89bfbc1 + e46e40c commit 4459deb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+681
-313
lines changed

.github/workflows/run_simulation.yaml

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1212
# copies of the Software, and to permit persons to whom the Software is
1313
# furnished to do so, subject to the following conditions:
14-
14+
#
1515
# The above copyright notice and this permission notice shall be included in all
1616
# copies or substantial portions of the Software.
17-
17+
#
1818
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1919
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2020
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -52,16 +52,16 @@ jobs:
5252

5353
- name: Make simulation project
5454
run:
55-
cd examples/01_hello_world/build_sim && cmake ../hw && make sim
55+
cd examples/01_hello_world/build_sim && cmake -DFDEV_NAME=u55c ../hw && make sim
5656

5757
- name: Make software project
5858
run:
59-
cd examples/01_hello_world/build_sw && cmake ../sw -DSIM_DIR=../build_sim && make
59+
cd examples/01_hello_world/build_sw && cmake ../sw -DEN_SIM=ON && make
6060

6161
- name: Run simulation
62-
run:
63-
examples/01_hello_world/build_sw/bin/test -X 1024 -r 1 -s 0
64-
examples/01_hello_world/build_sw/bin/test -X 1024 -r 1 -s 1
62+
run: |
63+
COYOTE_SIM_DIR=examples/01_hello_world/build_sim/ examples/01_hello_world/build_sw/test -X 1024 -r 1 -s 0
64+
COYOTE_SIM_DIR=examples/01_hello_world/build_sim/ examples/01_hello_world/build_sw/test -X 1024 -r 1 -s 1
6565
6666
run-02-hls-vadd:
6767
environment: fpga-synth
@@ -76,15 +76,15 @@ jobs:
7676

7777
- name: Make simulation project
7878
run:
79-
cd examples/02_hls_vadd/build_sim && cmake ../hw && make sim
79+
cd examples/02_hls_vadd/build_sim && cmake -DFDEV_NAME=u55c ../hw && make sim
8080

8181
- name: Make software project
8282
run:
83-
cd examples/02_hls_vadd/build_sw && cmake ../sw -DSIM_DIR=../build_sim && make
83+
cd examples/02_hls_vadd/build_sw && cmake ../sw -DEN_SIM=ON && make
8484

8585
- name: Run simulation
86-
run:
87-
examples/02_hls_vadd/build_sw/bin/test
86+
run: |
87+
COYOTE_SIM_DIR=examples/02_hls_vadd/build_sim/ examples/02_hls_vadd/build_sw/test
8888
8989
run-04-user-interrupts:
9090
environment: fpga-synth
@@ -99,15 +99,15 @@ jobs:
9999

100100
- name: Make simulation project
101101
run:
102-
cd examples/04_user_interrupts/build_sim && cmake ../hw && make sim
102+
cd examples/04_user_interrupts/build_sim && cmake -DFDEV_NAME=u55c ../hw && make sim
103103

104104
- name: Make software project
105105
run:
106-
cd examples/04_user_interrupts/build_sw && cmake ../sw -DSIM_DIR=../build_sim && make
106+
cd examples/04_user_interrupts/build_sw && cmake ../sw -DEN_SIM=ON && make
107107

108108
- name: Run simulation
109-
run:
110-
examples/04_user_interrupts/build_sw/bin/test
109+
run: |
110+
COYOTE_SIM_DIR=examples/04_user_interrupts/build_sim/ examples/04_user_interrupts/build_sw/test
111111
112112
run-07-perf-fpga:
113113
environment: fpga-synth
@@ -118,17 +118,17 @@ jobs:
118118

119119
- name: Environment set-up
120120
run:
121-
mkdir examples/07_perf_local/build_sim && mkdir examples/07_perf_local/build_sw && sudo apt-get install libboost-all-dev
121+
mkdir examples/07_perf_fpga/build_sim && mkdir examples/07_perf_fpga/build_sw && sudo apt-get install libboost-all-dev
122122

123123
- name: Make simulation project
124124
run:
125-
cd examples/07_perf_local/build_sim && cmake ../hw && make sim
125+
cd examples/07_perf_fpga/build_sim && cmake -DFDEV_NAME=u55c ../hw && make sim
126126

127127
- name: Make software project
128128
run:
129-
cd examples/07_perf_local/build_sw && cmake ../sw -DSIM_DIR=../build_sim && make
129+
cd examples/07_perf_fpga/build_sw && cmake ../sw -DEN_SIM=ON && make
130130

131131
- name: Run simulation
132-
run:
133-
examples/07_perf_local/build_sw/bin/test -X 1024 -r 1 -o 0
134-
examples/07_perf_local/build_sw/bin/test -X 1024 -r 1 -o 1
132+
run: |
133+
COYOTE_SIM_DIR=examples/07_perf_fpga/build_sim/ examples/07_perf_fpga/build_sw/test -X 1024 -r 1 -o 0
134+
COYOTE_SIM_DIR=examples/07_perf_fpga/build_sim/ examples/07_perf_fpga/build_sw/test -X 1024 -r 1 -o 1

cmake/FindCoyoteSW.cmake

Lines changed: 20 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -24,161 +24,25 @@
2424
# SOFTWARE.
2525
######################################################################################
2626

27-
############################################
28-
# COYOTE SOFTWARE PACKAGE #
29-
############################################
30-
# @brief Set-up all the necessary libs, includes and source file compile the Coyote software
31-
32-
cmake_minimum_required(VERSION 3.5)
33-
34-
##############################
35-
# USER OPTIONS #
36-
#############################
37-
# Build with AVX support
38-
set(EN_AVX "1" CACHE STRING "AVX enabled.")
39-
40-
# Build with support for ROCm (AMD GPUs)
41-
set(EN_GPU "0" CACHE STRING "AMD GPU enabled.")
42-
43-
##############################
44-
# BUILD CONFIG #
45-
#############################
46-
set(CYT_LANG CXX)
47-
48-
set(EN_SIM 0 CACHE STRING "Build for simulation.")
49-
set(SIM_DIR "" CACHE STRING "Directory that contains simulation project.")
50-
string(COMPARE EQUAL "${SIM_DIR}" "" result)
51-
if(NOT result)
52-
set(EN_SIM 1)
53-
endif()
54-
55-
# Find GPU libraries
56-
if(EN_GPU)
57-
if(NOT DEFINED ROCM_PATH)
58-
if(DEFINED ENV{ROCM_PATH})
59-
set(ROCM_PATH $ENV{ROCM_PATH} CACHE PATH "Path to which ROCM has been installed")
60-
elseif(DEFINED ENV{HIP_PATH})
61-
set(ROCM_PATH "$ENV{HIP_PATH}/.." CACHE PATH "Path to which ROCM has been installed")
62-
else()
63-
set(ROCM_PATH "/opt/rocm" CACHE PATH "Path to which ROCM has been installed")
64-
endif()
65-
endif()
66-
67-
file(STRINGS "${ROCM_PATH}/.info/version" ROCM_VERSION)
68-
message("-- Found ROCm: ${ROCM_VERSION}")
69-
70-
if (NOT DEFINED CMAKE_CXX_COMPILER)
71-
set(CMAKE_CXX_COMPILER ${ROCM_PATH}/bin/hipcc)
72-
endif()
73-
74-
if(NOT DEFINED HIP_PATH)
75-
if(NOT DEFINED ENV{HIP_PATH})
76-
set(HIP_PATH "/opt/rocm/hip" CACHE PATH "Path to which HIP has been installed")
77-
else()
78-
set(HIP_PATH $ENV{HIP_PATH} CACHE PATH "Path to which HIP has been installed")
79-
endif()
80-
endif()
81-
82-
if(NOT DEFINED HCC_PATH)
83-
if(DEFINED ENV{HCC_PATH})
84-
set(HCC_PATH $ENV{HCC_PATH} CACHE PATH "Path to which HCC has been installed")
85-
else()
86-
set(HCC_PATH "${ROCM_PATH}/hcc" CACHE PATH "Path to which HCC has been installed")
87-
endif()
88-
set(HCC_HOME "${HCC_PATH}")
89-
endif()
90-
91-
if(NOT DEFINED HIP_CLANG_PATH)
92-
if(NOT DEFINED ENV{HIP_CLANG_PATH})
93-
set(HIP_CLANG_PATH "${ROCM_PATH}/llvm/bin" CACHE PATH "Path to which HIP compatible clang binaries have been installed")
94-
else()
95-
set(HIP_CLANG_PATH $ENV{HIP_CLANG_PATH} CACHE PATH "Path to which HIP compatible clang binaries have been installed")
96-
endif()
97-
endif()
98-
99-
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${HIP_PATH}/cmake" )
100-
list(APPEND CMAKE_PREFIX_PATH
101-
"${HIP_PATH}/lib/cmake"
102-
"${HIP_PATH}/../lib/cmake"
103-
)
104-
105-
find_package(HIP QUIET)
106-
if(HIP_FOUND)
107-
message(STATUS "Found HIP: " ${HIP_VERSION})
108-
else()
109-
message(FATAL_ERROR "Could not find HIP. Ensure that HIP is either installed in /opt/rocm/hip or the variable HIP_PATH is set to point to the right location.")
110-
endif()
111-
find_package(hip REQUIRED)
112-
113-
set(CYT_LANG ${CYT_LANG} HIP)
114-
endif()
115-
116-
# Create a Coyote lib
117-
project(
118-
Coyote
119-
VERSION 2.0.0
120-
DESCRIPTION "Coyote library"
121-
LANGUAGES ${CYT_LANG}
27+
message(WARNING "FindCoyoteSW is deprecated. Instead, you can choose one of two options:\n"
28+
"1. If you're including Coyote as a git submodule, you can use the add_subdirectory(...)"
29+
" directive in CMake. As an example, the following snippet of FindCoyoteSW:\n"
30+
" set(CYT_DIR \$\{CMAKE_SOURCE_DIR\}/../coyote)\n"
31+
" set(CMAKE_MODULE_PATH \$\{CMAKE_MODULE_PATH\} \$\{CYT_DIR\}/cmake)\n"
32+
" find_package(CoyoteSW REQUIRED)\n"
33+
"can be replaced with:\n"
34+
" add_subdirectory(../coyote/sw coyote)\n"
35+
"Please refer to the add_subdirectory documentation for more details.\n"
36+
"2. If you're integrating Coyote into third-party software, it's likely that dependencies"
37+
" are managed out-of-tree, and thus submodules are not used. In that case, you can install"
38+
" coyote as a system library (by building the CMake project in sw/ and running `make install`)"
39+
" and use CMake's find_package functionality as follows:"
40+
"\n"
41+
" find_package(Coyote REQUIRED)\n"
42+
"In both cases, you can then link Coyote into your project using:"
43+
"\n"
44+
" target_link_libraries(<project> PRIVATE Coyote)\n"
45+
" target_include_directories(<project> PRIVATE \$\{COYOTE_INCLUDE_DIRS\})\n"
12246
)
123-
set(CMAKE_DEBUG_POSTFIX d)
124-
125-
# Specify C++ standard, compile time options
126-
set(CMAKE_CXX_STANDARD 17)
127-
set(CMAKE_CXX_STANDARD_REQUIRED True)
128-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -march=native -O3")
129-
130-
# Source files, includes
131-
file(GLOB CYT_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/../sw/src/*.cpp")
132-
if(EN_SIM)
133-
list(FILTER CYT_SOURCES EXCLUDE REGEX ".*cThread\\.cpp$")
134-
file(GLOB SIM_SOURCES "${CMAKE_CURRENT_LIST_DIR}/../sim/sw/src/*.cpp")
135-
list(APPEND CYT_SOURCES ${SIM_SOURCES})
136-
endif()
137-
add_library(Coyote SHARED ${CYT_SOURCES})
138-
139-
# Output directories
140-
if (NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
141-
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
142-
endif()
143-
144-
if (NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
145-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
146-
endif()
147-
148-
# Header includes
149-
set(CYT_INCLUDE_PATH ${CMAKE_CURRENT_LIST_DIR}/../sw/include)
150-
if(EN_SIM)
151-
list(APPEND CYT_INCLUDE_PATH ${CMAKE_CURRENT_LIST_DIR}/../sim/sw/include)
152-
endif()
153-
target_include_directories(Coyote PUBLIC ${CYT_INCLUDE_PATH})
154-
target_link_directories(Coyote PUBLIC /usr/local/lib)
155-
156-
# Additional libraries
157-
find_package(Boost COMPONENTS program_options REQUIRED)
158-
target_link_libraries(Coyote PUBLIC ${Boost_LIBRARIES})
159-
160-
# Additional flags, depending on AVX or GPU support
161-
if(EN_AVX)
162-
target_compile_definitions(Coyote PUBLIC EN_AVX)
163-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
164-
endif()
165-
166-
if(EN_GPU)
167-
target_compile_definitions(Coyote PUBLIC EN_GPU)
168-
169-
# Include GPU directories
170-
target_include_directories(Coyote
171-
PUBLIC
172-
$<BUILD_INTERFACE:${ROCM_PATH}/include>
173-
$<BUILD_INTERFACE:${ROCM_PATH}/include/hsa>
174-
)
175-
176-
# Add GPU libraries
177-
target_link_libraries(Coyote PUBLIC hip::device numa pthread drm drm_amdgpu rt dl hsa-runtime64 hsakmt)
178-
179-
endif()
180-
if (EN_SIM)
181-
target_compile_definitions(Coyote PUBLIC SIM_DIR="${SIM_DIR}")
182-
endif()
183-
18447

48+
add_subdirectory(${CYT_DIR}/sw)

docs/source/intro/quick-start.rst

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,23 @@ For some ideas of projects that were based on Coyote, check out the :ref:`public
335335
Simulating vFPGAs
336336
-----------------------
337337
A more comprehensive documentation for the simulation environment can be found at ``sim/README.md``.
338-
To get started with the simulation target for the software library, execute ``make sim`` after initializing the hardware build directory with ``cmake`` and add the SIM_DIR flag to the ``cmake`` call of the software build directory:
338+
To get started with the simulation target for the software library, execute ``make sim`` after initializing the hardware build directory with ``cmake``.
339+
To include and use the simulation software library, youh should change your CMake
340+
`add_subdirectory` or `find_package`:
339341

340-
.. code-block:: bash
342+
.. code-block:: cmake
341343
342-
cmake <CMakeLists.txt_location> -DSIM_DIR=<sim_build_dir>...
344+
add_subdirectory(path/to/coyote/sim/sw coyote) # Changed from add_subdirectory(path/to/coyote/sw coyote)
345+
# or
346+
find_package(CoyoteSimulation) # Changed from find_package(Coyote)
343347
344348
After building the software with ``make``, the binary may be executed the same as if a programmed FPGA was available.
349+
You must point the program to the ``build_hw`` directory where you ran ``make sim`` via the ``COYOTE_SIM_DIR`` environment variable.
350+
For example, if our project builds a ``test`` executable, you should run it as:
351+
352+
.. code-block:: bash
353+
COYOTE_SIM_DIR=path/to/build_hw test <args...>
354+
345355
It will automatically start Vivado in the background and start the testbench environment to simulate the vFPGA.
346356

347357
Besides this simulation target for the Coyote C++ library, a Python unit test framework is available that is documented in detail in ``sim/unit-test/README.md``.

examples/01_hello_world/sw/CMakeLists.txt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,26 @@
3030
cmake_minimum_required(VERSION 3.5)
3131
project(example_01_hello_world)
3232

33-
set(CYT_DIR ${CMAKE_SOURCE_DIR}/../../../)
34-
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CYT_DIR}/cmake)
35-
find_package(CoyoteSW REQUIRED)
33+
if(NOT CMAKE_BUILD_TYPE)
34+
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
35+
endif()
3636

37-
message("*** Coyote Example 1: Hello World! [Software] ***")
37+
option(EN_SIM "Enable simulation mode for Coyote" OFF)
38+
39+
if(EN_SIM)
40+
add_subdirectory(../../../sim/sw ${CMAKE_BINARY_DIR}/coyote)
41+
else()
42+
add_subdirectory(../../../sw ${CMAKE_BINARY_DIR}/coyote)
43+
endif()
3844

3945
# Directory containing the executable(s) to be compiled
4046
set(TARGET_DIR "${CMAKE_SOURCE_DIR}/src/")
4147

4248
# Create build targets and link against required libraries
4349
set(EXEC test)
4450
add_executable(${EXEC} ${TARGET_DIR}/main.cpp)
51+
4552
target_link_libraries(${EXEC} PUBLIC Coyote)
46-
target_link_directories(${EXEC} PUBLIC /usr/local/lib)
53+
54+
find_package(Boost REQUIRED COMPONENTS program_options)
55+
target_link_libraries(${EXEC} PUBLIC Boost::program_options)

examples/01_hello_world/sw/src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
#include <boost/program_options.hpp>
3232

3333
// Coyote-specific includes
34-
#include "cBench.hpp"
35-
#include "cThread.hpp"
34+
#include <coyote/cBench.hpp>
35+
#include <coyote/cThread.hpp>
3636

3737
// Constants
3838
#define N_LATENCY_REPS 1

examples/02_hls_vadd/sw/CMakeLists.txt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,17 @@
2828
cmake_minimum_required(VERSION 3.5)
2929
project(example_02_hls_vadd)
3030

31-
set(CYT_DIR ${CMAKE_SOURCE_DIR}/../../../)
32-
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CYT_DIR}/cmake)
33-
find_package(CoyoteSW REQUIRED)
31+
if(NOT CMAKE_BUILD_TYPE)
32+
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
33+
endif()
34+
35+
option(EN_SIM "Enable simulation mode for Coyote" OFF)
36+
37+
if(EN_SIM)
38+
add_subdirectory(../../../sim/sw ${CMAKE_BINARY_DIR}/coyote)
39+
else()
40+
add_subdirectory(../../../sw ${CMAKE_BINARY_DIR}/coyote)
41+
endif()
3442

3543
message("*** Coyote Example 2: HLS Vector Addition [Software] ***")
3644

@@ -40,5 +48,8 @@ set(TARGET_DIR "${CMAKE_SOURCE_DIR}/src/")
4048
# Create build targets and link against required libraries
4149
set(EXEC test)
4250
add_executable(${EXEC} ${TARGET_DIR}/main.cpp)
51+
4352
target_link_libraries(${EXEC} PUBLIC Coyote)
44-
target_link_directories(${EXEC} PUBLIC /usr/local/lib)
53+
54+
find_package(Boost REQUIRED COMPONENTS program_options)
55+
target_link_libraries(${EXEC} PUBLIC Boost::program_options)

examples/02_hls_vadd/sw/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include <boost/program_options.hpp>
3232

3333
// Coyote-specific includes
34-
#include "cThread.hpp"
34+
#include <coyote/cThread.hpp>
3535

3636
// Default vFPGA to assign cThreads to
3737
#define DEFAULT_VFPGA_ID 0

0 commit comments

Comments
 (0)