Skip to content

Commit 57c9d2b

Browse files
committed
Import Intel(R) FPGA Runtime for OpenCL(TM) Software Technology
1 parent ca2aaa4 commit 57c9d2b

File tree

165 files changed

+72253
-29
lines changed

Some content is hidden

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

165 files changed

+72253
-29
lines changed

.clang-format

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright (C) 2021 Intel Corporation
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
4+
BasedOnStyle: LLVM

CMakeLists.txt

Lines changed: 279 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,279 @@
1+
# Copyright (C) 2021 Intel Corporation
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
4+
cmake_minimum_required(VERSION 3.10)
5+
6+
project(fpga-runtime C CXX)
7+
8+
# Enforce keeping the source directory clean by building in a separate
9+
# directory. This avoids unnecessary corner cases, e.g., copying files
10+
# from source to binary directory with identical relative paths.
11+
if(PROJECT_BINARY_DIR STREQUAL PROJECT_SOURCE_DIR)
12+
message(FATAL_ERROR "build directory must be different from source directory")
13+
endif()
14+
15+
# We exclusively support Ninja as the generator used to build the project.
16+
if(NOT CMAKE_GENERATOR STREQUAL "Ninja")
17+
message(FATAL_ERROR "unsupported cmake generator, please use `cmake -G Ninja`")
18+
endif()
19+
20+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/modules")
21+
22+
find_package(Elf REQUIRED)
23+
find_package(ZLIB)
24+
find_package(Git)
25+
26+
set(CMAKE_THREAD_PREFER_PTHREAD ON)
27+
find_package(Threads REQUIRED)
28+
29+
math(EXPR ACL_TARGET_BIT "${CMAKE_SIZEOF_VOID_P} * 8")
30+
message(STATUS "Target pointer size in bits: ${ACL_TARGET_BIT}")
31+
32+
################################################################################
33+
### Modified Default flags
34+
################################################################################
35+
# Use "multithread-specific and DLL-specific version of the run-time library" (Windows)
36+
# There's a better way for CMake >= 3.15
37+
# See https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html
38+
if(WIN32 AND "${CMAKE_BUILD_TYPE}" STREQUAL "")
39+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MD")
40+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MD")
41+
endif()
42+
43+
# Flag for coverage scans
44+
option(ACL_CODE_COVERAGE "Build with coverage" OFF)
45+
message(STATUS "Build with coverage: ${ACL_CODE_COVERAGE}")
46+
if(ACL_CODE_COVERAGE)
47+
if(CMAKE_COMPILER_IS_GNUCXX)
48+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
49+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
50+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
51+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
52+
else()
53+
message(FATAL_ERROR "cannot build with coverage tools due to unsupported CXX compiler")
54+
endif()
55+
endif()
56+
57+
################################################################################
58+
### Modified Debug flags
59+
################################################################################
60+
# pkg_editor_test and acl_test have trouble with the debug version of the multithread Windows runtime library
61+
# There's a better way for CMake >= 3.15
62+
# See https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html
63+
string(REGEX REPLACE "/MDd" "/MD" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
64+
string(REGEX REPLACE "/MDd" "/MD" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
65+
# pkg_editor_test errors out if we enable runtime error checking
66+
string(REGEX REPLACE "( /RTC1$|/RTC1 )" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
67+
string(REGEX REPLACE "( /RTC1$|/RTC1 )" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
68+
69+
# -DNDEBUG will disable calls to assert() in our unit tests
70+
foreach(flags
71+
CMAKE_C_FLAGS_RELWITHDEBINFO
72+
CMAKE_CXX_FLAGS_RELWITHDEBINFO
73+
CMAKE_C_FLAGS_RELEASE
74+
CMAKE_CXX_FLAGS_RELEASE
75+
CMAKE_C_FLAGS_MINSIZEREL
76+
CMAKE_CXX_FLAGS_MINSIZEREL
77+
)
78+
string(REGEX REPLACE "(^|[ \t])[/-][dD][ \t]*NDEBUG($|[ \t])" " " "${flags}" "${${flags}}")
79+
endforeach()
80+
81+
# Windows debug builds frequently crash mspdbsrv.exe, resulting in fatal
82+
# error C1090: PDB API call failed, error code '23': (0x000006BA). Work
83+
# around this unresolved issue by disabling separate PDB files (`/Zi`)
84+
# and instead embedding debugging symbols in object files (`/Z7`).
85+
#
86+
# https://bugs.chromium.org/p/chromium/issues/detail?id=659439
87+
# https://developercommunity.visualstudio.com/t/c1090-pdb-api-call-failed-error-code-23/48897
88+
# https://docs.microsoft.com/en-us/cpp/build/reference/z7-zi-zi-debug-information-format?view=msvc-160
89+
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
90+
foreach(flags
91+
CMAKE_C_FLAGS_DEBUG
92+
CMAKE_CXX_FLAGS_DEBUG
93+
CMAKE_C_FLAGS_RELWITHDEBINFO
94+
CMAKE_CXX_FLAGS_RELWITHDEBINFO
95+
)
96+
string(REGEX REPLACE "(^|[ \t])/Zi($|[ \t])" " /Z7 " "${flags}" "${${flags}}")
97+
endforeach()
98+
endif()
99+
100+
# https://clang.llvm.org/docs/AddressSanitizer.html
101+
option(ACL_WITH_ASAN "Build with address sanitizer" OFF)
102+
message(STATUS "Build with address sanitizer: ${ACL_WITH_ASAN}")
103+
if(ACL_WITH_ASAN)
104+
foreach(lang C CXX)
105+
if(CMAKE_${lang}_COMPILER_ID MATCHES "^(Clang|GNU)$")
106+
set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
107+
else()
108+
message(FATAL_ERROR "cannot build with address sanitizer due to unsupported ${lang} compiler")
109+
endif()
110+
endforeach()
111+
endif()
112+
113+
include(CTest)
114+
115+
# Get CMAKE_INSTALL_<dir> variables to enable custom library, binary, and include paths
116+
# See https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html
117+
include(GNUInstallDirs)
118+
119+
# acl_hostxml includes acl.h, but we don't want to create a cyclic dependency,
120+
# so we create a header only library here
121+
add_library(acl_headers INTERFACE)
122+
target_include_directories(acl_headers INTERFACE include)
123+
124+
# Generate header containing the runtime version. The OUTPUT file *.phony is in
125+
# fact never written and ensures ninja always considers this target out of date.
126+
add_custom_command(
127+
OUTPUT
128+
"${CMAKE_BINARY_DIR}/include/acl_version.h"
129+
"${CMAKE_BINARY_DIR}/include/acl_version.h.phony"
130+
DEPENDS "${CMAKE_SOURCE_DIR}/include/acl_version.h.in"
131+
COMMAND "${CMAKE_COMMAND}"
132+
-D "ACL_VERSION_INPUT_FILE=${CMAKE_SOURCE_DIR}/include/acl_version.h.in"
133+
-D "ACL_VERSION_OUTPUT_FILE=${CMAKE_BINARY_DIR}/include/acl_version.h"
134+
-D "GIT_FOUND=${GIT_FOUND}"
135+
-D "GIT_EXECUTABLE=${GIT_EXECUTABLE}"
136+
-P "${CMAKE_CURRENT_LIST_DIR}/cmake/scripts/version.cmake"
137+
)
138+
139+
add_library(acl_objs OBJECT
140+
"${CMAKE_BINARY_DIR}/include/acl_version.h"
141+
src/acl_auto_configure.cpp
142+
src/acl_bsp_io.cpp
143+
src/acl_command.cpp
144+
src/acl_command_queue.cpp
145+
src/acl_context.cpp
146+
src/acl_device.cpp
147+
src/acl_device_binary.cpp
148+
src/acl_device_op.cpp
149+
src/acl_device_program_info.cpp
150+
src/acl_event.cpp
151+
src/acl_globals.cpp
152+
src/acl_hal.cpp
153+
src/acl_hal_mmd.cpp
154+
src/acl_hostch.cpp
155+
src/acl_icd_dispatch.cpp
156+
src/acl_kernel.cpp
157+
src/acl_kernel_if.cpp
158+
src/acl_mem.cpp
159+
src/acl_offline_hal.cpp
160+
src/acl_platform.cpp
161+
src/acl_pll.cpp
162+
src/acl_printf.cpp
163+
src/acl_profiler.cpp
164+
src/acl_program.cpp
165+
src/acl_sampler.cpp
166+
src/acl_shared_aligned_ptr.cpp
167+
src/acl_support.cpp
168+
src/acl_svm.cpp
169+
src/acl_thread.cpp
170+
src/acl_usm.cpp
171+
src/check_copy_overlap.c
172+
)
173+
set_target_properties(acl_objs PROPERTIES
174+
CXX_EXTENSIONS OFF
175+
POSITION_INDEPENDENT_CODE ON
176+
)
177+
target_compile_features(acl_objs PRIVATE cxx_std_11)
178+
# These compile_definitions need to be public, since we're building an OBJECT library (?)
179+
target_compile_definitions(acl_objs PUBLIC
180+
_GLIBCXX_USE_CXX11_ABI=0
181+
ACL_SUPPORT_DOUBLE=0
182+
ACL_HAS_STDLIB_STDIO
183+
CL_USE_DEPRECATED_OPENCL_1_0_APIS=1
184+
CL_USE_DEPRECATED_OPENCL_1_1_APIS=1
185+
CL_USE_DEPRECATED_OPENCL_1_2_APIS=1
186+
CL_TARGET_OPENCL_VERSION=200
187+
)
188+
target_include_directories(acl_objs PUBLIC include)
189+
target_include_directories(acl_objs PRIVATE
190+
"${CMAKE_BINARY_DIR}/include"
191+
src
192+
)
193+
# "Linking" libraries to an OBJECT library is the preferred approach, but it is supported only after CMake 3.12
194+
# The oldest CMake version we need to support is 3.10
195+
# As older OS support becomes deprecated and we don't need to worry about CMake < 3.12, we can change this
196+
# See: https://cmake.org/cmake/help/v3.12/command/target_link_libraries.html#linking-object-libraries
197+
target_include_directories(acl_objs PRIVATE
198+
"${CMAKE_SOURCE_DIR}/lib/acl_check_sys_cmd/include"
199+
"${CMAKE_SOURCE_DIR}/lib/acl_hash/include"
200+
"${CMAKE_SOURCE_DIR}/lib/acl_threadsupport/include"
201+
"${CMAKE_SOURCE_DIR}/lib/pkg_editor/include"
202+
)
203+
204+
add_library(acl SHARED $<TARGET_OBJECTS:acl_objs>)
205+
set_property(TARGET acl PROPERTY OUTPUT_NAME "alteracl")
206+
target_link_libraries(acl PRIVATE acl_check_sys_cmd acl_hash acl_threadsupport pkg_editor)
207+
if(UNIX)
208+
# we need this flag to expose symbols, otherwise linking will fail with:
209+
# "relocation against protected symbol X can not be used when making a shared object"
210+
set_target_properties(acl PROPERTIES LINK_FLAGS "-Wl,-Bsymbolic")
211+
endif()
212+
213+
set_property(TARGET acl PROPERTY PUBLIC_HEADER
214+
include/acl.h
215+
include/acl_auto.h
216+
include/acl_auto_configure.h
217+
include/acl_auto_configure_version.h
218+
include/acl_context.h
219+
include/acl_device_binary.h
220+
include/acl_globals.h
221+
include/acl_hal.h
222+
include/acl_hal_mmd.h
223+
include/acl_hostch.h
224+
include/acl_icd_dispatch.h
225+
include/acl_shared_aligned_ptr.h
226+
include/acl_support.h
227+
include/acl_thread.h
228+
include/acl_types.h
229+
include/acl_util.h
230+
include/acl_visibility.h
231+
)
232+
233+
set_property(TARGET acl PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON)
234+
235+
install(TARGETS acl
236+
COMPONENT acl
237+
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
238+
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
239+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
240+
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
241+
)
242+
243+
# Workaround for CL/[name].h and MMD/[name].h headers
244+
# There's a better way for CMake >= 3.15
245+
# Change this to be a header-only library and use PUBLIC_HEADER
246+
# see https://cmake.org/cmake/help/latest/command/add_library.html#interface-libraries
247+
248+
install(FILES
249+
include/CL/cl.h
250+
include/CL/cl_d3d10.h
251+
include/CL/cl_d3d11.h
252+
include/CL/cl_dx9_media_sharing.h
253+
include/CL/cl_dx9_media_sharing_intel.h
254+
include/CL/cl_egl.h
255+
include/CL/cl_ext.h
256+
include/CL/cl_ext_intel.h
257+
include/CL/cl_ext_intelfpga.h
258+
include/CL/cl_gl.h
259+
include/CL/cl_gl_ext.h
260+
include/CL/cl_half.h
261+
include/CL/cl_icd.h
262+
include/CL/cl_platform.h
263+
include/CL/cl_va_api_media_sharing_intel.h
264+
include/CL/cl_version.h
265+
include/CL/opencl.h
266+
include/CL/opencl.hpp
267+
COMPONENT CL
268+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/CL"
269+
)
270+
271+
install(FILES
272+
include/MMD/aocl_mmd.h
273+
include/MMD/aocl_mmd_deprecated.h
274+
COMPONENT MMD
275+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/MMD"
276+
)
277+
278+
add_subdirectory(lib)
279+
add_subdirectory(test)

LICENSE

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Intel(R) FPGA Runtime for OpenCL(TM) Software Technology
2+
========================================================
3+
4+
Copyright (C) 2010-2021 Intel Corporation
5+
SPDX-License-Identifier: BSD-3-Clause
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are met:
9+
10+
1. Redistributions of source code must retain the above copyright notice, this
11+
list of conditions and the following disclaimer.
12+
13+
2. Redistributions in binary form must reproduce the above copyright notice,
14+
this list of conditions and the following disclaimer in the documentation
15+
and/or other materials provided with the distribution.
16+
17+
3. Neither the name of the copyright holder nor the names of its
18+
contributors may be used to endorse or promote products derived from
19+
this software without specific prior written permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
25+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
33+
Software from third parties
34+
===========================
35+
36+
The Intel(R) FPGA Runtime for OpenCL(TM) Software Technology includes software
37+
from third parties which are subject to their respective license terms that are
38+
provided in either or both of these two forms:
39+
40+
1. A separate `COPYING` or `LICENSE` file stating the license terms which
41+
apply to all files in that directory and its subdirectories, with the
42+
exception of files stating other license terms at the top of the file.
43+
44+
2. The license terms are stated at the top of the file.

cmake/modules/FindElf.cmake

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright (C) 2021 Intel Corporation
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
4+
find_path(Elf_INCLUDE_DIR NAMES libelf/libelf.h libelf.h)
5+
6+
if(Elf_INCLUDE_DIR AND EXISTS "${Elf_INCLUDE_DIR}/libelf/libelf.h")
7+
set(Elf_HAVE_LIBELF_LIBELF TRUE)
8+
else()
9+
set(Elf_HAVE_LIBELF_LIBELF FALSE)
10+
endif()
11+
12+
find_library(Elf_LIBRARY NAMES elf libelf)
13+
14+
mark_as_advanced(Elf_INCLUDE_DIR Elf_LIBRARY)
15+
16+
include(FindPackageHandleStandardArgs)
17+
find_package_handle_standard_args(Elf REQUIRED_VARS Elf_INCLUDE_DIR Elf_LIBRARY)
18+
19+
if(Elf_FOUND)
20+
add_library(Elf::Elf UNKNOWN IMPORTED)
21+
set_target_properties(Elf::Elf PROPERTIES
22+
IMPORTED_LINK_INTERFACE_LANGUAGES C
23+
IMPORTED_LOCATION "${Elf_LIBRARY}"
24+
INTERFACE_INCLUDE_DIRECTORIES "${Elf_INCLUDE_DIR}"
25+
INTERFACE_COMPILE_DEFINITIONS "$<$<BOOL:${Elf_HAVE_LIBELF_LIBELF}>:HAVE_LIBELF_LIBELF>"
26+
)
27+
endif()

cmake/scripts/version.cmake

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright (C) 2021 Intel Corporation
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
4+
# This script generates a header containing the runtime version based on the
5+
# output of git describe, which generates a human readable name for a commit.
6+
7+
# Use upper case to signal that this is a placeholder value.
8+
set(ACL_GIT_COMMIT "UNKNOWN")
9+
10+
# The extraction of the git commit is strictly optional; if a failure occurs
11+
# due to any reason, the placeholder value for ACL_GIT_COMMIT must be retained.
12+
if(GIT_FOUND)
13+
execute_process(
14+
COMMAND "${GIT_EXECUTABLE}" describe --always --dirty --first-parent --long
15+
RESULT_VARIABLE ACL_GIT_DESCRIBE_RESULT
16+
OUTPUT_VARIABLE ACL_GIT_DESCRIBE_OUTPUT
17+
OUTPUT_STRIP_TRAILING_WHITESPACE
18+
)
19+
20+
if(ACL_GIT_DESCRIBE_RESULT EQUAL 0 AND ACL_GIT_DESCRIBE_OUTPUT)
21+
set(ACL_GIT_COMMIT "${ACL_GIT_DESCRIBE_OUTPUT}")
22+
endif()
23+
endif()
24+
25+
# This only writes the output file when the content has changed, which in turn
26+
# only triggers a rebuild of dependent source files when the commit changes.
27+
configure_file(
28+
"${ACL_VERSION_INPUT_FILE}"
29+
"${ACL_VERSION_OUTPUT_FILE}"
30+
@ONLY
31+
)

include/CL/.clang-format

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright (C) 2021 Intel Corporation
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
4+
DisableFormat: true
5+
SortIncludes: false

0 commit comments

Comments
 (0)