From bf51d3a60dac58dbc7a1db1be768ba362f1f1280 Mon Sep 17 00:00:00 2001 From: Maksim Levental Date: Wed, 19 Jun 2024 10:49:04 +0100 Subject: [PATCH] Add aie-rt and bootgen as submodules (1/n) (#419) --- .gitmodules | 6 + build_tools/ci/build_test_cpp.sh | 2 +- runtime/src/iree-amd-aie/CMakeLists.txt | 9 +- .../iree-amd-aie/aie_runtime/CMakeLists.txt | 152 ++++ .../aie_runtime/FindOpenSSL.cmake | 804 ++++++++++++++++++ .../aie_runtime/iree_aie_runtime.cc | 7 + .../aie_runtime/iree_aie_runtime.h | 37 + .../aie_runtime/test/CMakeLists.txt | 32 + .../aie_runtime/test/cdo_dump.txt | 217 +++++ .../src/iree-amd-aie/aie_runtime/test/pi.elf | Bin 0 -> 8436 bytes .../iree-amd-aie/aie_runtime/test/utest.cxx | 107 +++ third_party/aie-rt | 1 + third_party/bootgen | 1 + 13 files changed, 1373 insertions(+), 2 deletions(-) create mode 100644 runtime/src/iree-amd-aie/aie_runtime/CMakeLists.txt create mode 100644 runtime/src/iree-amd-aie/aie_runtime/FindOpenSSL.cmake create mode 100644 runtime/src/iree-amd-aie/aie_runtime/iree_aie_runtime.cc create mode 100644 runtime/src/iree-amd-aie/aie_runtime/iree_aie_runtime.h create mode 100644 runtime/src/iree-amd-aie/aie_runtime/test/CMakeLists.txt create mode 100644 runtime/src/iree-amd-aie/aie_runtime/test/cdo_dump.txt create mode 100644 runtime/src/iree-amd-aie/aie_runtime/test/pi.elf create mode 100755 runtime/src/iree-amd-aie/aie_runtime/test/utest.cxx create mode 160000 third_party/aie-rt create mode 160000 third_party/bootgen diff --git a/.gitmodules b/.gitmodules index 1d9d9813c..89be5eb0e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,9 @@ [submodule "third_party/mlir-aie"] path = third_party/mlir-aie url = https://github.com/nod-ai/mlir-aie.git +[submodule "third_party/aie-rt"] + path = third_party/aie-rt + url = https://github.com/stephenneuendorffer/aie-rt.git +[submodule "third_party/bootgen"] + path = third_party/bootgen + url = https://github.com/Xilinx/bootgen.git diff --git a/build_tools/ci/build_test_cpp.sh b/build_tools/ci/build_test_cpp.sh index ea083d503..adbe52f5f 100644 --- a/build_tools/ci/build_test_cpp.sh +++ b/build_tools/ci/build_test_cpp.sh @@ -87,7 +87,7 @@ cmake --build "$build_dir" --target iree-install-dist echo "CTest" echo "-----" -ctest --test-dir "$build_dir" -R amd-aie +ctest --test-dir "$build_dir" -R amd-aie --output-on-failure # Show ccache stats. ccache --show-stats diff --git a/runtime/src/iree-amd-aie/CMakeLists.txt b/runtime/src/iree-amd-aie/CMakeLists.txt index 8f3f7e32d..bfa015081 100644 --- a/runtime/src/iree-amd-aie/CMakeLists.txt +++ b/runtime/src/iree-amd-aie/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright 2023 The IREE Authors +# Copyright 2024 The IREE Authors # # Licensed under the Apache License v2.0 with LLVM Exceptions. # See https://llvm.org/LICENSE.txt for license information. @@ -13,3 +13,10 @@ endif() # (.vmfb file), and so the schema sub-directory is required even when not # building the XRT driver code. add_subdirectory(schemas) + +# Contains libiree_aie_runtime, i.e., suitably encapsulated calls to aie-rt. +# Note, "runtime" is currently a misnomer as all such calls are made at +# compile/configuration time; the name is inspired by aie-rt itself +# (where rt stands for runtime) and the fact that in the future, the plan is indeed +# to make these same calls at runtime. +add_subdirectory(aie_runtime) diff --git a/runtime/src/iree-amd-aie/aie_runtime/CMakeLists.txt b/runtime/src/iree-amd-aie/aie_runtime/CMakeLists.txt new file mode 100644 index 000000000..5128bfc5c --- /dev/null +++ b/runtime/src/iree-amd-aie/aie_runtime/CMakeLists.txt @@ -0,0 +1,152 @@ +# Copyright 2024 The IREE Authors +# +# Licensed under the Apache License v2.0 with LLVM Exceptions. See +# https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# ############################################################################## +# Prerequisites +# ############################################################################## + +if(NOT ${CMAKE_SIZEOF_VOID_P} EQUAL 8) + message( + FATAL_ERROR + "Building on 32bit platforms/toolchains is not supported; if you are seeing this on windows, " + "it's possible you have opened the win32 developer shell rather than the x64 developer shell." + ) +endif() + +# We use our own, slightly modified, FindOpenSSL because of issues in +# CMake's distribution of the same for versions prior to 3.29. +# https://gitlab.kitware.com/cmake/cmake/-/issues/25702 +find_package(OpenSSL) +if(NOT DEFINED OPENSSL_FOUND OR NOT ${OPENSSL_FOUND}) + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") + find_package(OpenSSL) + if(NOT DEFINED USE_IREE_AMD_AIE_FIND_OPENSSL OR NOT ${USE_IREE_AMD_AIE_FIND_OPENSSL}) + message(FATAL_ERROR "Didn't pickup/use adjacent FindOpenSSL.cmake") + endif() + if(NOT DEFINED OPENSSL_FOUND OR NOT ${OPENSSL_FOUND}) + message(FATAL_ERROR "OpenSSL not found") + endif() +endif() +message(STATUS "OpenSSL include directories:" ${OPENSSL_INCLUDE_DIR}) + +# ############################################################################## +# Bootgen +# ############################################################################## + +set(_bootgen_source_dir ${IREE_AMD_AIE_SOURCE_DIR}/third_party/bootgen) +file(GLOB _bootgen_sources "${_bootgen_source_dir}/*.c" + "${_bootgen_source_dir}/*.cpp") +list(REMOVE_ITEM _bootgen_sources "${_bootgen_source_dir}/main.cpp") + +add_library(bootgen-lib STATIC ${_bootgen_sources}) +if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + target_compile_definitions(bootgen-lib PUBLIC YY_NO_UNISTD_H) +elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU") + set(bootgen_warning_ignores + -Wno-cast-qual + -Wno-covered-switch-default + -Wno-date-time + -Wno-deprecated-copy + -Wno-deprecated-declarations + -Wno-deprecated-register + -Wno-dynamic-class-memaccess + -Wno-implicit-fallthrough + -Wno-incompatible-function-pointer-types + -Wno-incompatible-pointer-types-discards-qualifiers + -Wno-misleading-indentation + -Wno-non-virtual-dtor + -Wno-overloaded-virtual + -Wno-pointer-bool-conversion + -Wno-register + -Wno-reorder + -Wno-sign-compare + -Wno-suggest-override + -Wno-tautological-overlap-compare + -Wno-unused) +endif() +target_compile_options(bootgen-lib PRIVATE ${bootgen_warning_ignores}) +target_include_directories(bootgen-lib PUBLIC ${_bootgen_source_dir} + ${OPENSSL_INCLUDE_DIR}) +target_compile_definitions(bootgen-lib PUBLIC OPENSSL_USE_APPLINK) +target_link_libraries(bootgen-lib PUBLIC OpenSSL::SSL OpenSSL::applink) + +# malloc.h is deprecated and should not be used +# https://stackoverflow.com/a/56463133 If you want to use malloc, then include +# stdlib.h +file(READ ${_bootgen_source_dir}/cdo-npi.c FILE_CONTENTS) +string(REPLACE "#include " "" FILE_CONTENTS "${FILE_CONTENTS}") +file(WRITE ${_bootgen_source_dir}/cdo-npi.c "${FILE_CONTENTS}") + +file(READ ${_bootgen_source_dir}/cdo-alloc.c FILE_CONTENTS) +string(REPLACE "#include " "" FILE_CONTENTS "${FILE_CONTENTS}") +file(WRITE ${_bootgen_source_dir}/cdo-alloc.c "${FILE_CONTENTS}") + +# ############################################################################## +# cdo-drver +# ############################################################################## + +add_library(cdo_driver STATIC ${_bootgen_source_dir}/cdo-driver/cdo_driver.c) +target_include_directories(cdo_driver PUBLIC ${_bootgen_source_dir}/cdo-driver) +set_target_properties(cdo_driver PROPERTIES LINKER_LANGUAGE C) +iree_install_targets( + TARGETS cdo_driver + COMPONENT IREEBundledLibraries + EXPORT_SET Compiler +) + +# ############################################################################## +# aie-rt +# ############################################################################## + +set(_aie_rt_source_dir ${IREE_AMD_AIE_SOURCE_DIR}/third_party/aie-rt) +set(_aie_rt_binary_include_dir ${CMAKE_BINARY_DIR}/include) + +include(${_aie_rt_source_dir}/fal/cmake/collect.cmake) +# We would prefer not to actually include the aie-rt directory +# (i.e., prefer not to run their CMake) but there are configure/install +# commands in the CMake there that perform the "installs" of the +# build/include/xaiengine headers. +add_subdirectory(${_aie_rt_source_dir}/driver/src iree_aie_runtime) + +get_target_property(_aie_runtime_compile_options aienginev2 COMPILE_OPTIONS) +list(REMOVE_ITEM _aie_runtime_compile_options -D__AIEBAREMETAL__) +set_target_properties( + aienginev2 + PROPERTIES COMPILE_OPTIONS + "${_aie_runtime_compile_options};${bootgen_warning_ignores}") +target_compile_definitions(aienginev2 PRIVATE ${XAIE_DEBUG} __AIECDO__) +# For +target_include_directories(aienginev2 PRIVATE SYSTEM ${_bootgen_source_dir}) +target_link_libraries(aienginev2 PRIVATE cdo_driver) + +iree_install_targets( + TARGETS aienginev2 + COMPONENT IREEBundledLibraries + EXPORT_SET Compiler +) + +# ############################################################################## +# iree-aie-runtime-static +# ############################################################################## + +iree_cc_library( + NAME + iree_aie_runtime_static + HDRS + iree_aie_runtime.h + SRCS + iree_aie_runtime.cc + INCLUDES + ${_aie_rt_binary_include_dir} + # For + ${_bootgen_source_dir} + PUBLIC +) + +target_link_libraries(iree-amd-aie_aie_runtime_iree_aie_runtime_static + PRIVATE aienginev2) + +add_subdirectory(test) diff --git a/runtime/src/iree-amd-aie/aie_runtime/FindOpenSSL.cmake b/runtime/src/iree-amd-aie/aie_runtime/FindOpenSSL.cmake new file mode 100644 index 000000000..43b6d31d3 --- /dev/null +++ b/runtime/src/iree-amd-aie/aie_runtime/FindOpenSSL.cmake @@ -0,0 +1,804 @@ +################################################################################################### +# THIS IS A PATCHED VERSION FROM https://gitlab.kitware.com/cmake/cmake/-/issues/25702#note_1485779 +# SEE https://gitlab.kitware.com/cmake/cmake/-/issues/25702#note_1485760 +################################################################################################### + +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +FindOpenSSL +----------- + +Find the OpenSSL encryption library. + +This module finds an installed OpenSSL library and determines its version. + +.. versionadded:: 3.19 + When a version is requested, it can be specified as a simple value or as a + range. For a detailed description of version range usage and capabilities, + refer to the :command:`find_package` command. + +.. versionadded:: 3.18 + Support for OpenSSL 3.0. + +Optional COMPONENTS +^^^^^^^^^^^^^^^^^^^ + +.. versionadded:: 3.12 + +This module supports two optional COMPONENTS: ``Crypto`` and ``SSL``. Both +components have associated imported targets, as described below. + +Imported Targets +^^^^^^^^^^^^^^^^ + +.. versionadded:: 3.4 + +This module defines the following :prop_tgt:`IMPORTED` targets: + +``OpenSSL::SSL`` + The OpenSSL ``ssl`` library, if found. +``OpenSSL::Crypto`` + The OpenSSL ``crypto`` library, if found. +``OpenSSL::applink`` + .. versionadded:: 3.18 + + The OpenSSL ``applink`` components that might be need to be compiled into + projects under MSVC. This target is available only if found OpenSSL version + is not less than 0.9.8. By linking this target the above OpenSSL targets can + be linked even if the project has different MSVC runtime configurations with + the above OpenSSL targets. This target has no effect on platforms other than + MSVC. + +NOTE: Due to how ``INTERFACE_SOURCES`` are consumed by the consuming target, +unless you certainly know what you are doing, it is always preferred to link +``OpenSSL::applink`` target as ``PRIVATE`` and to make sure that this target is +linked at most once for the whole dependency graph of any library or +executable: + +.. code-block:: cmake + + target_link_libraries(myTarget PRIVATE OpenSSL::applink) + +Otherwise you would probably encounter unexpected random problems when building +and linking, as both the ISO C and the ISO C++ standard claims almost nothing +about what a link process should be. + +Result Variables +^^^^^^^^^^^^^^^^ + +This module will set the following variables in your project: + +``OPENSSL_FOUND`` + System has the OpenSSL library. If no components are requested it only + requires the crypto library. +``OPENSSL_INCLUDE_DIR`` + The OpenSSL include directory. +``OPENSSL_CRYPTO_LIBRARY`` + The OpenSSL crypto library. +``OPENSSL_CRYPTO_LIBRARIES`` + The OpenSSL crypto library and its dependencies. +``OPENSSL_SSL_LIBRARY`` + The OpenSSL SSL library. +``OPENSSL_SSL_LIBRARIES`` + The OpenSSL SSL library and its dependencies. +``OPENSSL_LIBRARIES`` + All OpenSSL libraries and their dependencies. +``OPENSSL_VERSION`` + This is set to ``$major.$minor.$revision$patch`` (e.g. ``0.9.8s``). +``OPENSSL_APPLINK_SOURCE`` + The sources in the target ``OpenSSL::applink`` that is mentioned above. This + variable shall always be undefined if found openssl version is less than + 0.9.8 or if platform is not MSVC. + +Hints +^^^^^ + +The following variables may be set to control search behavior: + +``OPENSSL_ROOT_DIR`` + Set to the root directory of an OpenSSL installation. + +``OPENSSL_USE_STATIC_LIBS`` + .. versionadded:: 3.4 + + Set to ``TRUE`` to look for static libraries. + +``OPENSSL_MSVC_STATIC_RT`` + .. versionadded:: 3.5 + + Set to ``TRUE`` to choose the MT version of the lib. + +``ENV{PKG_CONFIG_PATH}`` + On UNIX-like systems, ``pkg-config`` is used to locate the system OpenSSL. + Set the ``PKG_CONFIG_PATH`` environment variable to look in alternate + locations. Useful on multi-lib systems. +#]=======================================================================] + +set(USE_IREE_AMD_AIE_FIND_OPENSSL TRUE) + +macro(_OpenSSL_test_and_find_dependencies ssl_library crypto_library) + unset(_OpenSSL_extra_static_deps) + if(UNIX AND + (("${ssl_library}" MATCHES "\\${CMAKE_STATIC_LIBRARY_SUFFIX}$") OR + ("${crypto_library}" MATCHES "\\${CMAKE_STATIC_LIBRARY_SUFFIX}$"))) + set(_OpenSSL_has_dependencies TRUE) + unset(_OpenSSL_has_dependency_zlib) + if(OPENSSL_USE_STATIC_LIBS) + set(_OpenSSL_libs "${_OPENSSL_STATIC_LIBRARIES}") + set(_OpenSSL_ldflags_other "${_OPENSSL_STATIC_LDFLAGS_OTHER}") + else() + set(_OpenSSL_libs "${_OPENSSL_LIBRARIES}") + set(_OpenSSL_ldflags_other "${_OPENSSL_LDFLAGS_OTHER}") + endif() + if(_OpenSSL_libs) + unset(_OpenSSL_has_dependency_dl) + foreach(_OPENSSL_DEP_LIB IN LISTS _OpenSSL_libs) + if (_OPENSSL_DEP_LIB STREQUAL "ssl" OR _OPENSSL_DEP_LIB STREQUAL "crypto") + # ignoring: these are the targets + elseif(_OPENSSL_DEP_LIB STREQUAL CMAKE_DL_LIBS) + set(_OpenSSL_has_dependency_dl TRUE) + elseif(_OPENSSL_DEP_LIB STREQUAL "z") + find_package(ZLIB) + set(_OpenSSL_has_dependency_zlib TRUE) + else() + list(APPEND _OpenSSL_extra_static_deps "${_OPENSSL_DEP_LIB}") + endif() + endforeach() + unset(_OPENSSL_DEP_LIB) + elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(_OpenSSL_has_dependency_dl TRUE) + endif() + if(_OpenSSL_ldflags_other) + unset(_OpenSSL_has_dependency_threads) + foreach(_OPENSSL_DEP_LDFLAG IN LISTS _OpenSSL_ldflags_other) + if (_OPENSSL_DEP_LDFLAG STREQUAL "-pthread") + set(_OpenSSL_has_dependency_threads TRUE) + find_package(Threads) + endif() + endforeach() + unset(_OPENSSL_DEP_LDFLAG) + elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(_OpenSSL_has_dependency_threads TRUE) + find_package(Threads) + endif() + unset(_OpenSSL_libs) + unset(_OpenSSL_ldflags_other) + else() + set(_OpenSSL_has_dependencies FALSE) + endif() +endmacro() + +function(_OpenSSL_add_dependencies libraries_var) + if(_OpenSSL_has_dependency_zlib) + list(APPEND ${libraries_var} ${ZLIB_LIBRARY}) + endif() + if(_OpenSSL_has_dependency_threads) + list(APPEND ${libraries_var} ${CMAKE_THREAD_LIBS_INIT}) + endif() + if(_OpenSSL_has_dependency_dl) + list(APPEND ${libraries_var} ${CMAKE_DL_LIBS}) + endif() + list(APPEND ${libraries_var} ${_OpenSSL_extra_static_deps}) + set(${libraries_var} ${${libraries_var}} PARENT_SCOPE) +endfunction() + +function(_OpenSSL_target_add_dependencies target) + if(_OpenSSL_has_dependencies) + if(_OpenSSL_has_dependency_zlib) + set_property( TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ZLIB::ZLIB ) + endif() + if(_OpenSSL_has_dependency_threads) + set_property( TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES Threads::Threads) + endif() + if(_OpenSSL_has_dependency_dl) + set_property( TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS} ) + endif() + if(_OpenSSL_extra_static_deps) + set_property( TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${_OpenSSL_extra_static_deps}) + endif() + endif() + if(WIN32 AND OPENSSL_USE_STATIC_LIBS) + if(WINCE) + set_property( TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ws2 ) + else() + set_property( TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ws2_32 ) + endif() + set_property( TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES crypt32 ) + endif() +endfunction() + +if (UNIX) + find_package(PkgConfig QUIET) + pkg_check_modules(_OPENSSL QUIET openssl) +endif () + +# Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES +if(OPENSSL_USE_STATIC_LIBS) + set(_openssl_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) + if(MSVC) + set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) + else() + set(CMAKE_FIND_LIBRARY_SUFFIXES .a ) + endif() +endif() + +if(CMAKE_SYSTEM_NAME STREQUAL "QNX" AND + CMAKE_SYSTEM_VERSION VERSION_GREATER_EQUAL "7.0" AND CMAKE_SYSTEM_VERSION VERSION_LESS "7.1" AND + OpenSSL_FIND_VERSION VERSION_GREATER_EQUAL "1.1" AND OpenSSL_FIND_VERSION VERSION_LESS "1.2") + # QNX 7.0.x provides openssl 1.0.2 and 1.1.1 in parallel: + # * openssl 1.0.2: libcrypto.so.2 and libssl.so.2, headers under usr/include/openssl + # * openssl 1.1.1: libcrypto1_1.so.2.1 and libssl1_1.so.2.1, header under usr/include/openssl1_1 + # See http://www.qnx.com/developers/articles/rel_6726_0.html + set(_OPENSSL_FIND_PATH_SUFFIX "openssl1_1") + set(_OPENSSL_NAME_POSTFIX "1_1") +else() + set(_OPENSSL_FIND_PATH_SUFFIX "include") +endif() + +if (OPENSSL_ROOT_DIR OR NOT "$ENV{OPENSSL_ROOT_DIR}" STREQUAL "") + set(_OPENSSL_ROOT_HINTS HINTS ${OPENSSL_ROOT_DIR} ENV OPENSSL_ROOT_DIR) + set(_OPENSSL_ROOT_PATHS NO_DEFAULT_PATH) +elseif (MSVC) + # http://www.slproweb.com/products/Win32OpenSSL.html + set(_OPENSSL_ROOT_HINTS + HINTS + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OpenSSL (32-bit)_is1;Inno Setup: App Path]" + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OpenSSL (64-bit)_is1;Inno Setup: App Path]" + ) + + if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8") + set(_arch "Win64") + file(TO_CMAKE_PATH "$ENV{PROGRAMFILES}" _programfiles) + else() + set(_arch "Win32") + set(_progfiles_x86 "ProgramFiles(x86)") + if(NOT "$ENV{${_progfiles_x86}}" STREQUAL "") + # under windows 64 bit machine + file(TO_CMAKE_PATH "$ENV{${_progfiles_x86}}" _programfiles) + else() + # under windows 32 bit machine + file(TO_CMAKE_PATH "$ENV{ProgramFiles}" _programfiles) + endif() + endif() + + set(_OPENSSL_ROOT_PATHS + PATHS + "${_programfiles}/OpenSSL" + "${_programfiles}/OpenSSL-${_arch}" + "C:/OpenSSL/" + "C:/OpenSSL-${_arch}/" + ) + unset(_programfiles) + unset(_arch) +endif () + +set(_OPENSSL_ROOT_HINTS_AND_PATHS + ${_OPENSSL_ROOT_HINTS} + ${_OPENSSL_ROOT_PATHS} + ) + +find_path(OPENSSL_INCLUDE_DIR + NAMES + openssl/ssl.h + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + HINTS + ${_OPENSSL_INCLUDEDIR} + ${_OPENSSL_INCLUDE_DIRS} + PATH_SUFFIXES + ${_OPENSSL_FIND_PATH_SUFFIX} +) + +if(WIN32 AND NOT CYGWIN) + if(MSVC) + # /MD and /MDd are the standard values - if someone wants to use + # others, the libnames have to change here too + # use also ssl and ssleay32 in debug as fallback for openssl < 0.9.8b + # enable OPENSSL_MSVC_STATIC_RT to get the libs build /MT (Multithreaded no-DLL) + # In Visual C++ naming convention each of these four kinds of Windows libraries has it's standard suffix: + # * MD for dynamic-release + # * MDd for dynamic-debug + # * MT for static-release + # * MTd for static-debug + + # Implementation details: + # We are using the libraries located in the VC subdir instead of the parent directory even though : + # libeay32MD.lib is identical to ../libeay32.lib, and + # ssleay32MD.lib is identical to ../ssleay32.lib + # enable OPENSSL_USE_STATIC_LIBS to use the static libs located in lib/VC/static + + if (OPENSSL_MSVC_STATIC_RT) + set(_OPENSSL_MSVC_RT_MODE "MT") + else () + set(_OPENSSL_MSVC_RT_MODE "MD") + endif () + + # Since OpenSSL 1.1, lib names are like libcrypto32MTd.lib and libssl32MTd.lib + if( "${CMAKE_SIZEOF_VOID_P}" STREQUAL "8" ) + set(_OPENSSL_MSVC_ARCH_SUFFIX "64") + else() + set(_OPENSSL_MSVC_ARCH_SUFFIX "32") + endif() + + if(OPENSSL_USE_STATIC_LIBS) + set(_OPENSSL_STATIC_SUFFIX + "_static" + ) + set(_OPENSSL_PATH_SUFFIXES_DEBUG + "lib/VC/x${_OPENSSL_MSVC_ARCH_SUFFIX}/${_OPENSSL_MSVC_RT_MODE}d" + "lib/VC/static" + "VC/static" + "lib" + ) + set(_OPENSSL_PATH_SUFFIXES_RELEASE + "lib/VC/x${_OPENSSL_MSVC_ARCH_SUFFIX}/${_OPENSSL_MSVC_RT_MODE}" + "lib/VC/static" + "VC/static" + "lib" + ) + else() + set(_OPENSSL_STATIC_SUFFIX + "" + ) + set(_OPENSSL_PATH_SUFFIXES_DEBUG + "lib/VC/x${_OPENSSL_MSVC_ARCH_SUFFIX}/${_OPENSSL_MSVC_RT_MODE}d" + "lib/VC" + "VC" + "lib" + ) + set(_OPENSSL_PATH_SUFFIXES_RELEASE + "lib/VC/x${_OPENSSL_MSVC_ARCH_SUFFIX}/${_OPENSSL_MSVC_RT_MODE}" + "lib/VC" + "VC" + "lib" + ) + endif () + message(STATUS "searching for MSVC libs in ${_OPENSSL_PATH_SUFFIXES_DEBUG}") + message(STATUS "searching for MSVC libs in ${_OPENSSL_PATH_SUFFIXES_RELEASE}") + message(FATAL_ERROR) + + find_library(LIB_EAY_DEBUG + NAMES + # When OpenSSL is built with default options, the static library name is suffixed with "_static". + # Looking the "libcrypto_static.lib" with a higher priority than "libcrypto.lib" which is the + # import library of "libcrypto.dll". + libcrypto${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d + libcrypto${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d + libcrypto${_OPENSSL_STATIC_SUFFIX}d + libeay32${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d + libeay32${_OPENSSL_STATIC_SUFFIX}d + crypto${_OPENSSL_STATIC_SUFFIX}d + # When OpenSSL is built with the "-static" option, only the static build is produced, + # and it is not suffixed with "_static". + libcrypto${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d + libcrypto${_OPENSSL_MSVC_RT_MODE}d + libcryptod + libeay32${_OPENSSL_MSVC_RT_MODE}d + libeay32d + cryptod + NAMES_PER_DIR + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + PATH_SUFFIXES + ${_OPENSSL_PATH_SUFFIXES_DEBUG} + ) + + find_library(LIB_EAY_RELEASE + NAMES + # When OpenSSL is built with default options, the static library name is suffixed with "_static". + # Looking the "libcrypto_static.lib" with a higher priority than "libcrypto.lib" which is the + # import library of "libcrypto.dll". + libcrypto${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE} + libcrypto${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE} + libcrypto${_OPENSSL_STATIC_SUFFIX} + libeay32${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE} + libeay32${_OPENSSL_STATIC_SUFFIX} + crypto${_OPENSSL_STATIC_SUFFIX} + # When OpenSSL is built with the "-static" option, only the static build is produced, + # and it is not suffixed with "_static". + libcrypto${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE} + libcrypto${_OPENSSL_MSVC_RT_MODE} + libcrypto + libeay32${_OPENSSL_MSVC_RT_MODE} + libeay32 + crypto + NAMES_PER_DIR + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + PATH_SUFFIXES + ${_OPENSSL_PATH_SUFFIXES_RELEASE} + ) + + find_library(SSL_EAY_DEBUG + NAMES + # When OpenSSL is built with default options, the static library name is suffixed with "_static". + # Looking the "libssl_static.lib" with a higher priority than "libssl.lib" which is the + # import library of "libssl.dll". + libssl${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d + libssl${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d + libssl${_OPENSSL_STATIC_SUFFIX}d + ssleay32${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d + ssleay32${_OPENSSL_STATIC_SUFFIX}d + ssl${_OPENSSL_STATIC_SUFFIX}d + # When OpenSSL is built with the "-static" option, only the static build is produced, + # and it is not suffixed with "_static". + libssl${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d + libssl${_OPENSSL_MSVC_RT_MODE}d + libssld + ssleay32${_OPENSSL_MSVC_RT_MODE}d + ssleay32d + ssld + NAMES_PER_DIR + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + PATH_SUFFIXES + ${_OPENSSL_PATH_SUFFIXES_DEBUG} + ) + + find_library(SSL_EAY_RELEASE + NAMES + # When OpenSSL is built with default options, the static library name is suffixed with "_static". + # Looking the "libssl_static.lib" with a higher priority than "libssl.lib" which is the + # import library of "libssl.dll". + libssl${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE} + libssl${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE} + libssl${_OPENSSL_STATIC_SUFFIX} + ssleay32${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE} + ssleay32${_OPENSSL_STATIC_SUFFIX} + ssl${_OPENSSL_STATIC_SUFFIX} + # When OpenSSL is built with the "-static" option, only the static build is produced, + # and it is not suffixed with "_static". + libssl${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE} + libssl${_OPENSSL_MSVC_RT_MODE} + libssl + ssleay32${_OPENSSL_MSVC_RT_MODE} + ssleay32 + ssl + NAMES_PER_DIR + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + PATH_SUFFIXES + ${_OPENSSL_PATH_SUFFIXES_RELEASE} + ) + + set(LIB_EAY_LIBRARY_DEBUG "${LIB_EAY_DEBUG}") + set(LIB_EAY_LIBRARY_RELEASE "${LIB_EAY_RELEASE}") + set(SSL_EAY_LIBRARY_DEBUG "${SSL_EAY_DEBUG}") + set(SSL_EAY_LIBRARY_RELEASE "${SSL_EAY_RELEASE}") + + include(SelectLibraryConfigurations) + select_library_configurations(LIB_EAY) + select_library_configurations(SSL_EAY) + + mark_as_advanced(LIB_EAY_LIBRARY_DEBUG LIB_EAY_LIBRARY_RELEASE + SSL_EAY_LIBRARY_DEBUG SSL_EAY_LIBRARY_RELEASE) + set(OPENSSL_SSL_LIBRARY ${SSL_EAY_LIBRARY} ) + set(OPENSSL_CRYPTO_LIBRARY ${LIB_EAY_LIBRARY} ) + elseif(MINGW) + # same player, for MinGW + set(LIB_EAY_NAMES crypto libeay32) + set(SSL_EAY_NAMES ssl ssleay32) + find_library(LIB_EAY + NAMES + ${LIB_EAY_NAMES} + NAMES_PER_DIR + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + PATH_SUFFIXES + "lib/MinGW" + "lib" + "lib64" + ) + + find_library(SSL_EAY + NAMES + ${SSL_EAY_NAMES} + NAMES_PER_DIR + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + PATH_SUFFIXES + "lib/MinGW" + "lib" + "lib64" + ) + + mark_as_advanced(SSL_EAY LIB_EAY) + set(OPENSSL_SSL_LIBRARY ${SSL_EAY} ) + set(OPENSSL_CRYPTO_LIBRARY ${LIB_EAY} ) + unset(LIB_EAY_NAMES) + unset(SSL_EAY_NAMES) + else() + # Not sure what to pick for -say- intel, let's use the toplevel ones and hope someone report issues: + find_library(LIB_EAY + NAMES + libcrypto + libeay32 + NAMES_PER_DIR + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + HINTS + ${_OPENSSL_LIBDIR} + PATH_SUFFIXES + lib + ) + + find_library(SSL_EAY + NAMES + libssl + ssleay32 + NAMES_PER_DIR + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + HINTS + ${_OPENSSL_LIBDIR} + PATH_SUFFIXES + lib + ) + + mark_as_advanced(SSL_EAY LIB_EAY) + set(OPENSSL_SSL_LIBRARY ${SSL_EAY} ) + set(OPENSSL_CRYPTO_LIBRARY ${LIB_EAY} ) + endif() +else() + + find_library(OPENSSL_SSL_LIBRARY + NAMES + ssl${_OPENSSL_NAME_POSTFIX} + ssleay32 + ssleay32MD + NAMES_PER_DIR + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + HINTS + ${_OPENSSL_LIBDIR} + ${_OPENSSL_LIBRARY_DIRS} + PATH_SUFFIXES + lib lib64 + ) + + find_library(OPENSSL_CRYPTO_LIBRARY + NAMES + crypto${_OPENSSL_NAME_POSTFIX} + NAMES_PER_DIR + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + HINTS + ${_OPENSSL_LIBDIR} + ${_OPENSSL_LIBRARY_DIRS} + PATH_SUFFIXES + lib lib64 + ) + + mark_as_advanced(OPENSSL_CRYPTO_LIBRARY OPENSSL_SSL_LIBRARY) + +endif() + +set(OPENSSL_SSL_LIBRARIES ${OPENSSL_SSL_LIBRARY}) +set(OPENSSL_CRYPTO_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY}) +set(OPENSSL_LIBRARIES ${OPENSSL_SSL_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARIES} ) +_OpenSSL_test_and_find_dependencies("${OPENSSL_SSL_LIBRARY}" "${OPENSSL_CRYPTO_LIBRARY}") +if(_OpenSSL_has_dependencies) + _OpenSSL_add_dependencies( OPENSSL_SSL_LIBRARIES ) + _OpenSSL_add_dependencies( OPENSSL_CRYPTO_LIBRARIES ) + _OpenSSL_add_dependencies( OPENSSL_LIBRARIES ) +endif() + +function(from_hex HEX DEC) + string(TOUPPER "${HEX}" HEX) + set(_res 0) + string(LENGTH "${HEX}" _strlen) + + while (_strlen GREATER 0) + math(EXPR _res "${_res} * 16") + string(SUBSTRING "${HEX}" 0 1 NIBBLE) + string(SUBSTRING "${HEX}" 1 -1 HEX) + if (NIBBLE STREQUAL "A") + math(EXPR _res "${_res} + 10") + elseif (NIBBLE STREQUAL "B") + math(EXPR _res "${_res} + 11") + elseif (NIBBLE STREQUAL "C") + math(EXPR _res "${_res} + 12") + elseif (NIBBLE STREQUAL "D") + math(EXPR _res "${_res} + 13") + elseif (NIBBLE STREQUAL "E") + math(EXPR _res "${_res} + 14") + elseif (NIBBLE STREQUAL "F") + math(EXPR _res "${_res} + 15") + else() + math(EXPR _res "${_res} + ${NIBBLE}") + endif() + + string(LENGTH "${HEX}" _strlen) + endwhile() + + set(${DEC} ${_res} PARENT_SCOPE) +endfunction() + +if(OPENSSL_INCLUDE_DIR AND EXISTS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h") + file(STRINGS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h" openssl_version_str + REGEX "^#[\t ]*define[\t ]+OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])+.*") + + if(openssl_version_str) + # The version number is encoded as 0xMNNFFPPS: major minor fix patch status + # The status gives if this is a developer or prerelease and is ignored here. + # Major, minor, and fix directly translate into the version numbers shown in + # the string. The patch field translates to the single character suffix that + # indicates the bug fix state, which 00 -> nothing, 01 -> a, 02 -> b and so + # on. + + string(REGEX REPLACE "^.*OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F]).*$" + "\\1;\\2;\\3;\\4;\\5" OPENSSL_VERSION_LIST "${openssl_version_str}") + list(GET OPENSSL_VERSION_LIST 0 OPENSSL_VERSION_MAJOR) + list(GET OPENSSL_VERSION_LIST 1 OPENSSL_VERSION_MINOR) + from_hex("${OPENSSL_VERSION_MINOR}" OPENSSL_VERSION_MINOR) + list(GET OPENSSL_VERSION_LIST 2 OPENSSL_VERSION_FIX) + from_hex("${OPENSSL_VERSION_FIX}" OPENSSL_VERSION_FIX) + list(GET OPENSSL_VERSION_LIST 3 OPENSSL_VERSION_PATCH) + + if (NOT OPENSSL_VERSION_PATCH STREQUAL "00") + from_hex("${OPENSSL_VERSION_PATCH}" _tmp) + # 96 is the ASCII code of 'a' minus 1 + math(EXPR OPENSSL_VERSION_PATCH_ASCII "${_tmp} + 96") + unset(_tmp) + # Once anyone knows how OpenSSL would call the patch versions beyond 'z' + # this should be updated to handle that, too. This has not happened yet + # so it is simply ignored here for now. + string(ASCII "${OPENSSL_VERSION_PATCH_ASCII}" OPENSSL_VERSION_PATCH_STRING) + endif () + + set(OPENSSL_VERSION "${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_MINOR}.${OPENSSL_VERSION_FIX}${OPENSSL_VERSION_PATCH_STRING}") + else () + # Since OpenSSL 3.0.0, the new version format is MAJOR.MINOR.PATCH and + # a new OPENSSL_VERSION_STR macro contains exactly that + file(STRINGS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h" OPENSSL_VERSION_STR + REGEX "^#[\t ]*define[\t ]+OPENSSL_VERSION_STR[\t ]+\"([0-9])+\\.([0-9])+\\.([0-9])+\".*") + string(REGEX REPLACE "^.*OPENSSL_VERSION_STR[\t ]+\"([0-9]+\\.[0-9]+\\.[0-9]+)\".*$" + "\\1" OPENSSL_VERSION_STR "${OPENSSL_VERSION_STR}") + + set(OPENSSL_VERSION "${OPENSSL_VERSION_STR}") + + # Setting OPENSSL_VERSION_MAJOR OPENSSL_VERSION_MINOR and OPENSSL_VERSION_FIX + string(REGEX MATCHALL "([0-9])+" OPENSSL_VERSION_NUMBER "${OPENSSL_VERSION}") + list(POP_FRONT OPENSSL_VERSION_NUMBER + OPENSSL_VERSION_MAJOR + OPENSSL_VERSION_MINOR + OPENSSL_VERSION_FIX) + + unset(OPENSSL_VERSION_NUMBER) + unset(OPENSSL_VERSION_STR) + endif () +endif () + +foreach(_comp IN LISTS OpenSSL_FIND_COMPONENTS) + if(_comp STREQUAL "Crypto") + if(EXISTS "${OPENSSL_INCLUDE_DIR}" AND + (EXISTS "${OPENSSL_CRYPTO_LIBRARY}" OR + EXISTS "${LIB_EAY_LIBRARY_DEBUG}" OR + EXISTS "${LIB_EAY_LIBRARY_RELEASE}") + ) + set(OpenSSL_${_comp}_FOUND TRUE) + else() + set(OpenSSL_${_comp}_FOUND FALSE) + endif() + elseif(_comp STREQUAL "SSL") + if(EXISTS "${OPENSSL_INCLUDE_DIR}" AND + (EXISTS "${OPENSSL_SSL_LIBRARY}" OR + EXISTS "${SSL_EAY_LIBRARY_DEBUG}" OR + EXISTS "${SSL_EAY_LIBRARY_RELEASE}") + ) + set(OpenSSL_${_comp}_FOUND TRUE) + else() + set(OpenSSL_${_comp}_FOUND FALSE) + endif() + else() + message(WARNING "${_comp} is not a valid OpenSSL component") + set(OpenSSL_${_comp}_FOUND FALSE) + endif() +endforeach() +unset(_comp) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(OpenSSL + REQUIRED_VARS + OPENSSL_CRYPTO_LIBRARY + OPENSSL_INCLUDE_DIR + VERSION_VAR + OPENSSL_VERSION + HANDLE_VERSION_RANGE + HANDLE_COMPONENTS + FAIL_MESSAGE + "Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR" +) + +mark_as_advanced(OPENSSL_INCLUDE_DIR) + +if(OPENSSL_FOUND) + if(NOT TARGET OpenSSL::Crypto AND + (EXISTS "${OPENSSL_CRYPTO_LIBRARY}" OR + EXISTS "${LIB_EAY_LIBRARY_DEBUG}" OR + EXISTS "${LIB_EAY_LIBRARY_RELEASE}") + ) + add_library(OpenSSL::Crypto UNKNOWN IMPORTED) + set_target_properties(OpenSSL::Crypto PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${OPENSSL_INCLUDE_DIR}") + if(EXISTS "${OPENSSL_CRYPTO_LIBRARY}") + set_target_properties(OpenSSL::Crypto PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${OPENSSL_CRYPTO_LIBRARY}") + endif() + if(EXISTS "${LIB_EAY_LIBRARY_RELEASE}") + set_property(TARGET OpenSSL::Crypto APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE) + set_target_properties(OpenSSL::Crypto PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C" + IMPORTED_LOCATION_RELEASE "${LIB_EAY_LIBRARY_RELEASE}") + endif() + if(EXISTS "${LIB_EAY_LIBRARY_DEBUG}") + set_property(TARGET OpenSSL::Crypto APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG) + set_target_properties(OpenSSL::Crypto PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C" + IMPORTED_LOCATION_DEBUG "${LIB_EAY_LIBRARY_DEBUG}") + endif() + _OpenSSL_target_add_dependencies(OpenSSL::Crypto) + endif() + + if(NOT TARGET OpenSSL::SSL AND + (EXISTS "${OPENSSL_SSL_LIBRARY}" OR + EXISTS "${SSL_EAY_LIBRARY_DEBUG}" OR + EXISTS "${SSL_EAY_LIBRARY_RELEASE}") + ) + add_library(OpenSSL::SSL UNKNOWN IMPORTED) + set_target_properties(OpenSSL::SSL PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${OPENSSL_INCLUDE_DIR}") + if(EXISTS "${OPENSSL_SSL_LIBRARY}") + set_target_properties(OpenSSL::SSL PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${OPENSSL_SSL_LIBRARY}") + endif() + if(EXISTS "${SSL_EAY_LIBRARY_RELEASE}") + set_property(TARGET OpenSSL::SSL APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE) + set_target_properties(OpenSSL::SSL PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C" + IMPORTED_LOCATION_RELEASE "${SSL_EAY_LIBRARY_RELEASE}") + endif() + if(EXISTS "${SSL_EAY_LIBRARY_DEBUG}") + set_property(TARGET OpenSSL::SSL APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG) + set_target_properties(OpenSSL::SSL PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C" + IMPORTED_LOCATION_DEBUG "${SSL_EAY_LIBRARY_DEBUG}") + endif() + if(TARGET OpenSSL::Crypto) + set_target_properties(OpenSSL::SSL PROPERTIES + INTERFACE_LINK_LIBRARIES OpenSSL::Crypto) + endif() + _OpenSSL_target_add_dependencies(OpenSSL::SSL) + endif() + + if("${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_MINOR}.${OPENSSL_VERSION_FIX}" VERSION_GREATER_EQUAL "0.9.8") + if(MSVC) + if(EXISTS "${OPENSSL_INCLUDE_DIR}") + set(_OPENSSL_applink_paths PATHS ${OPENSSL_INCLUDE_DIR}) + endif() + find_file(OPENSSL_APPLINK_SOURCE + NAMES + openssl/applink.c + ${_OPENSSL_applink_paths} + NO_DEFAULT_PATH) + if(OPENSSL_APPLINK_SOURCE) + set(_OPENSSL_applink_interface_srcs ${OPENSSL_APPLINK_SOURCE}) + endif() + endif() + if(NOT TARGET OpenSSL::applink) + add_library(OpenSSL::applink INTERFACE IMPORTED) + set_property(TARGET OpenSSL::applink APPEND + PROPERTY INTERFACE_SOURCES + ${_OPENSSL_applink_interface_srcs}) + endif() + endif() +endif() + +# Restore the original find library ordering +if(OPENSSL_USE_STATIC_LIBS) + set(CMAKE_FIND_LIBRARY_SUFFIXES ${_openssl_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) +endif() + +unset(_OPENSSL_FIND_PATH_SUFFIX) +unset(_OPENSSL_NAME_POSTFIX) +unset(_OpenSSL_extra_static_deps) +unset(_OpenSSL_has_dependency_dl) +unset(_OpenSSL_has_dependency_threads) +unset(_OpenSSL_has_dependency_zlib) diff --git a/runtime/src/iree-amd-aie/aie_runtime/iree_aie_runtime.cc b/runtime/src/iree-amd-aie/aie_runtime/iree_aie_runtime.cc new file mode 100644 index 000000000..ddfda39f5 --- /dev/null +++ b/runtime/src/iree-amd-aie/aie_runtime/iree_aie_runtime.cc @@ -0,0 +1,7 @@ +// Copyright 2024 The IREE Authors +// +// Licensed under the Apache License v2.0 with LLVM Exceptions. See +// https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: # Apache-2.0 WITH LLVM-exception + +#include "iree_aie_runtime.h" diff --git a/runtime/src/iree-amd-aie/aie_runtime/iree_aie_runtime.h b/runtime/src/iree-amd-aie/aie_runtime/iree_aie_runtime.h new file mode 100644 index 000000000..d0149b5b3 --- /dev/null +++ b/runtime/src/iree-amd-aie/aie_runtime/iree_aie_runtime.h @@ -0,0 +1,37 @@ +// Copyright 2024 The IREE Authors +// +// Licensed under the Apache License v2.0 with LLVM Exceptions. See +// https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: # Apache-2.0 WITH LLVM-exception + +#ifndef IREE_AIE_RUNTIME_H +#define IREE_AIE_RUNTIME_H + +#ifdef _WIN32 +#ifndef IREE_AIE_RUNTIME_EXPORT +#ifdef iree_aie_runtime_EXPORTS +// We are building this library +#define IREE_AIE_RUNTIME_EXPORT __declspec(dllexport) +#else +// We are using this library +#define IREE_AIE_RUNTIME_EXPORT __declspec(dllimport) +#endif // iree_aie_runtime_EXPORTS +#endif // IREE_AIE_RUNTIME_EXPORT +#else +// Non-windows: use visibility attributes. +#define IREE_AIE_RUNTIME_EXPORT __attribute__((visibility("default"))) +#endif // _WIN32 + +extern "C" { +#include "xaiengine.h" + +enum byte_ordering { Little_Endian, Big_Endian }; +void startCDOFileStream(const char* cdoFileName); +void endCurrentCDOFileStream(); +void FileHeader(); +void EnAXIdebug(); +void setEndianness(bool endianness); +void configureHeader(); +} + +#endif // IREE_AIE_RUNTIME_H diff --git a/runtime/src/iree-amd-aie/aie_runtime/test/CMakeLists.txt b/runtime/src/iree-amd-aie/aie_runtime/test/CMakeLists.txt new file mode 100644 index 000000000..d6a6e4c97 --- /dev/null +++ b/runtime/src/iree-amd-aie/aie_runtime/test/CMakeLists.txt @@ -0,0 +1,32 @@ +# Copyright 2024 The IREE Authors +# +# Licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# The purpose of this test is nothing more than to exercise the aie-rt and +# cdo_driver dependencies. If you're really curious the code represents a +# configuration that fetches a single float value from core_tile (0,2) via the +# mem_tile(0,1) and shim_tile(0,0). That value is produced by the program in +# the adjacent pi.elf (the value being 3.14159). + +iree_cc_binary( + NAME + aie_runtime_utest + SRCS + "utest.cxx" + DEPS + iree-amd-aie::aie_runtime::iree_aie_runtime_static +) + +iree_lit_test( + NAME + aie_runtime_utest_test + TEST_FILE + "cdo_dump.txt" + TOOLS + ::aie_runtime_utest + FileCheck + LABELS + "hostonly" +) diff --git a/runtime/src/iree-amd-aie/aie_runtime/test/cdo_dump.txt b/runtime/src/iree-amd-aie/aie_runtime/test/cdo_dump.txt new file mode 100644 index 000000000..dbb31e3ae --- /dev/null +++ b/runtime/src/iree-amd-aie/aie_runtime/test/cdo_dump.txt @@ -0,0 +1,217 @@ +// RUN: (aie_runtime_utest %S/pi.elf) | FileCheck %s + +CHECK: Generating: pi.cdo +CHECK: (BlockWrite-DMAWriteCmd): Start Address: 0x0000000000200404 Size: 9 +CHECK: Address: 0x0000000000200404 Data@ 0x{{.*}} is: 0x00000170 +CHECK: Address: 0x0000000000200408 Data@ 0x{{.*}} is: 0x00000000 +CHECK: Address: 0x000000000020040C Data@ 0x{{.*}} is: 0x00000000 +CHECK: Address: 0x0000000000200410 Data@ 0x{{.*}} is: 0x00000000 +CHECK: Address: 0x0000000000200414 Data@ 0x{{.*}} is: 0x00000000 +CHECK: Address: 0x0000000000200418 Data@ 0x{{.*}} is: 0x00000000 +CHECK: Address: 0x000000000020041C Data@ 0x{{.*}} is: 0x00000000 +CHECK: Address: 0x0000000000200420 Data@ 0x{{.*}} is: 0x00000000 +CHECK: Address: 0x0000000000200424 Data@ 0x{{.*}} is: 0x00000008 + +CHECK: (BlockWrite-DMAWriteCmd): Start Address: 0x0000000000220000 Size: 176 +CHECK: Address: 0x0000000000220000 Data@ 0x{{.*}} is: 0x38001043 +CHECK: Address: 0x0000000000220004 Data@ 0x{{.*}} is: 0x000001C3 +CHECK: Address: 0x0000000000220008 Data@ 0x{{.*}} is: 0x08000055 +CHECK: Address: 0x000000000022000C Data@ 0x{{.*}} is: 0x00550000 +CHECK: Address: 0x0000000000220010 Data@ 0x{{.*}} is: 0x00000C00 +CHECK: Address: 0x0000000000220014 Data@ 0x{{.*}} is: 0x16310799 +CHECK: Address: 0x0000000000220018 Data@ 0x{{.*}} is: 0x40400195 +CHECK: Address: 0x000000000022001C Data@ 0x{{.*}} is: 0x0001C000 +CHECK: Address: 0x0000000000220020 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x0000000000220024 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x0000000000220028 Data@ 0x{{.*}} is: 0xFC7FF855 +CHECK: Address: 0x000000000022002C Data@ 0x{{.*}} is: 0x7659FFFF +CHECK: Address: 0x0000000000220030 Data@ 0x{{.*}} is: 0x782F1F30 +CHECK: Address: 0x0000000000220034 Data@ 0x{{.*}} is: 0x04B20000 +CHECK: Address: 0x0000000000220038 Data@ 0x{{.*}} is: 0x00000062 +CHECK: Address: 0x000000000022003C Data@ 0x{{.*}} is: 0x00000000 +CHECK: Address: 0x0000000000220040 Data@ 0x{{.*}} is: 0xDC8C764D +CHECK: Address: 0x0000000000220044 Data@ 0x{{.*}} is: 0x0001DFF0 +CHECK: Address: 0x0000000000220048 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x000000000022004C Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x0000000000220050 Data@ 0x{{.*}} is: 0x14190001 +CHECK: Address: 0x0000000000220054 Data@ 0x{{.*}} is: 0x00011000 +CHECK: Address: 0x0000000000220058 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x000000000022005C Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x0000000000220060 Data@ 0x{{.*}} is: 0x14B10899 +CHECK: Address: 0x0000000000220064 Data@ 0x{{.*}} is: 0x20400195 +CHECK: Address: 0x0000000000220068 Data@ 0x{{.*}} is: 0x0001C000 +CHECK: Address: 0x000000000022006C Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x0000000000220070 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x0000000000220074 Data@ 0x{{.*}} is: 0x183E7659 +CHECK: Address: 0x0000000000220078 Data@ 0x{{.*}} is: 0x244B2003 +CHECK: Address: 0x000000000022007C Data@ 0x{{.*}} is: 0x00000000 +CHECK: Address: 0x0000000000220080 Data@ 0x{{.*}} is: 0x70000115 +CHECK: Address: 0x0000000000220084 Data@ 0x{{.*}} is: 0x00010000 +CHECK: Address: 0x0000000000220088 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x000000000022008C Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x0000000000220090 Data@ 0x{{.*}} is: 0x10000115 +CHECK: Address: 0x0000000000220094 Data@ 0x{{.*}} is: 0x06990001 +CHECK: Address: 0x0000000000220098 Data@ 0x{{.*}} is: 0x00011830 +CHECK: Address: 0x000000000022009C Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x00000000002200A0 Data@ 0x{{.*}} is: 0x880003C0 +CHECK: Address: 0x00000000002200A4 Data@ 0x{{.*}} is: 0x00000003 +CHECK: Address: 0x00000000002200A8 Data@ 0x{{.*}} is: 0x00000000 +CHECK: Address: 0x00000000002200AC Data@ 0x{{.*}} is: 0x00000000 +CHECK: Address: 0x00000000002200B0 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x00000000002200B4 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x00000000002200B8 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x00000000002200BC Data@ 0x{{.*}} is: 0x10000819 +CHECK: Address: 0x00000000002200C0 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x00000000002200C4 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x00000000002200C8 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x00000000002200CC Data@ 0x{{.*}} is: 0x00000019 +CHECK: Address: 0x00000000002200D0 Data@ 0x{{.*}} is: 0x68000095 +CHECK: Address: 0x00000000002200D4 Data@ 0x{{.*}} is: 0x00010000 +CHECK: Address: 0x00000000002200D8 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x00000000002200DC Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x00000000002200E0 Data@ 0x{{.*}} is: 0x38032019 +CHECK: Address: 0x00000000002200E4 Data@ 0x{{.*}} is: 0x0FFFC299 +CHECK: Address: 0x00000000002200E8 Data@ 0x{{.*}} is: 0x98000115 +CHECK: Address: 0x00000000002200EC Data@ 0x{{.*}} is: 0xC8430000 +CHECK: Address: 0x00000000002200F0 Data@ 0x{{.*}} is: 0x060827FF +CHECK: Address: 0x00000000002200F4 Data@ 0x{{.*}} is: 0x00010000 +CHECK: Address: 0x00000000002200F8 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x00000000002200FC Data@ 0x{{.*}} is: 0x00000019 +CHECK: Address: 0x0000000000220100 Data@ 0x{{.*}} is: 0x07FFC2D9 +CHECK: Address: 0x0000000000220104 Data@ 0x{{.*}} is: 0xA8000095 +CHECK: Address: 0x0000000000220108 Data@ 0x{{.*}} is: 0x00010000 +CHECK: Address: 0x000000000022010C Data@ 0x{{.*}} is: 0x86550001 +CHECK: Address: 0x0000000000220110 Data@ 0x{{.*}} is: 0x4048FC0B +CHECK: Address: 0x0000000000220114 Data@ 0x{{.*}} is: 0x1A0010B7 +CHECK: Address: 0x0000000000220118 Data@ 0x{{.*}} is: 0x000001C0 +CHECK: Address: 0x000000000022011C Data@ 0x{{.*}} is: 0x00000000 +CHECK: Address: 0x0000000000220120 Data@ 0x{{.*}} is: 0xC80003C0 +CHECK: Address: 0x0000000000220124 Data@ 0x{{.*}} is: 0x06282003 +CHECK: Address: 0x0000000000220128 Data@ 0x{{.*}} is: 0x0002B000 +CHECK: Address: 0x000000000022012C Data@ 0x{{.*}} is: 0xFFFC0000 +CHECK: Address: 0x0000000000220130 Data@ 0x{{.*}} is: 0x10121219 +CHECK: Address: 0x0000000000220134 Data@ 0x{{.*}} is: 0x10001819 +CHECK: Address: 0x0000000000220138 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x000000000022013C Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x0000000000220140 Data@ 0x{{.*}} is: 0x880003C0 +CHECK: Address: 0x0000000000220144 Data@ 0x{{.*}} is: 0x00000003 +CHECK: Address: 0x0000000000220148 Data@ 0x{{.*}} is: 0x00000000 +CHECK: Address: 0x000000000022014C Data@ 0x{{.*}} is: 0x00000000 +CHECK: Address: 0x0000000000220150 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x0000000000220154 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x0000000000220158 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x000000000022015C Data@ 0x{{.*}} is: 0x10101219 +CHECK: Address: 0x0000000000220160 Data@ 0x{{.*}} is: 0x10001819 +CHECK: Address: 0x0000000000220164 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x0000000000220168 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x000000000022016C Data@ 0x{{.*}} is: 0x00000019 +CHECK: Address: 0x0000000000220170 Data@ 0x{{.*}} is: 0x180B9659 +CHECK: Address: 0x0000000000220174 Data@ 0x{{.*}} is: 0x0C000055 +CHECK: Address: 0x0000000000220178 Data@ 0x{{.*}} is: 0x76590000 +CHECK: Address: 0x000000000022017C Data@ 0x{{.*}} is: 0x0055183E +CHECK: Address: 0x0000000000220180 Data@ 0x{{.*}} is: 0x00000B80 +CHECK: Address: 0x0000000000220184 Data@ 0x{{.*}} is: 0x9E0B2843 +CHECK: Address: 0x0000000000220188 Data@ 0x{{.*}} is: 0x002F8C3F +CHECK: Address: 0x000000000022018C Data@ 0x{{.*}} is: 0xF8400195 +CHECK: Address: 0x0000000000220190 Data@ 0x{{.*}} is: 0x2019C000 +CHECK: Address: 0x0000000000220194 Data@ 0x{{.*}} is: 0xEC193803 +CHECK: Address: 0x0000000000220198 Data@ 0x{{.*}} is: 0x42990FFF +CHECK: Address: 0x000000000022019C Data@ 0x{{.*}} is: 0xC0190FFE +CHECK: Address: 0x00000000002201A0 Data@ 0x{{.*}} is: 0x782F0FFE +CHECK: Address: 0x00000000002201A4 Data@ 0x{{.*}} is: 0x00380000 +CHECK: Address: 0x00000000002201A8 Data@ 0x{{.*}} is: 0x46800040 +CHECK: Address: 0x00000000002201AC Data@ 0x{{.*}} is: 0x000007FF +CHECK: Address: 0x00000000002201B0 Data@ 0x{{.*}} is: 0x070386D9 +CHECK: Address: 0x00000000002201B4 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x00000000002201B8 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x00000000002201BC Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x00000000002201C0 Data@ 0x{{.*}} is: 0x10001419 +CHECK: Address: 0x00000000002201C4 Data@ 0x{{.*}} is: 0x1D8E7659 +CHECK: Address: 0x00000000002201C8 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x00000000002201CC Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x00000000002201D0 Data@ 0x{{.*}} is: 0x15F16899 +CHECK: Address: 0x00000000002201D4 Data@ 0x{{.*}} is: 0xD8400195 +CHECK: Address: 0x00000000002201D8 Data@ 0x{{.*}} is: 0x0001C000 +CHECK: Address: 0x00000000002201DC Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x00000000002201E0 Data@ 0x{{.*}} is: 0x782F0001 +CHECK: Address: 0x00000000002201E4 Data@ 0x{{.*}} is: 0x00380000 +CHECK: Address: 0x00000000002201E8 Data@ 0x{{.*}} is: 0x00000040 +CHECK: Address: 0x00000000002201EC Data@ 0x{{.*}} is: 0x00000000 +CHECK: Address: 0x00000000002201F0 Data@ 0x{{.*}} is: 0x07FE42D9 +CHECK: Address: 0x00000000002201F4 Data@ 0x{{.*}} is: 0x07FEEE59 +CHECK: Address: 0x00000000002201F8 Data@ 0x{{.*}} is: 0x07FFEC59 +CHECK: Address: 0x00000000002201FC Data@ 0x{{.*}} is: 0x07FF7ED9 +CHECK: Address: 0x0000000000220200 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x0000000000220204 Data@ 0x{{.*}} is: 0x18190001 +CHECK: Address: 0x0000000000220208 Data@ 0x{{.*}} is: 0x00011000 +CHECK: Address: 0x000000000022020C Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x0000000000220210 Data@ 0x{{.*}} is: 0x007F0001 +CHECK: Address: 0x0000000000220214 Data@ 0x{{.*}} is: 0x00710000 +CHECK: Address: 0x0000000000220218 Data@ 0x{{.*}} is: 0xE0000000 +CHECK: Address: 0x000000000022021C Data@ 0x{{.*}} is: 0x000007FF +CHECK: Address: 0x0000000000220220 Data@ 0x{{.*}} is: 0x1A1210BB +CHECK: Address: 0x0000000000220224 Data@ 0x{{.*}} is: 0x480001C0 +CHECK: Address: 0x0000000000220228 Data@ 0x{{.*}} is: 0x10BB0100 +CHECK: Address: 0x000000000022022C Data@ 0x{{.*}} is: 0x01C04202 +CHECK: Address: 0x0000000000220230 Data@ 0x{{.*}} is: 0x0050C800 +CHECK: Address: 0x0000000000220234 Data@ 0x{{.*}} is: 0x249B293B +CHECK: Address: 0x0000000000220238 Data@ 0x{{.*}} is: 0x403E17AA +CHECK: Address: 0x000000000022023C Data@ 0x{{.*}} is: 0x36590050 +CHECK: Address: 0x0000000000220240 Data@ 0x{{.*}} is: 0xF6591C06 +CHECK: Address: 0x0000000000220244 Data@ 0x{{.*}} is: 0xC0551C84 +CHECK: Address: 0x0000000000220248 Data@ 0x{{.*}} is: 0x00000C64 +CHECK: Address: 0x000000000022024C Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x0000000000220250 Data@ 0x{{.*}} is: 0x18C1F679 +CHECK: Address: 0x0000000000220254 Data@ 0x{{.*}} is: 0x10C42099 +CHECK: Address: 0x0000000000220258 Data@ 0x{{.*}} is: 0x988B2843 +CHECK: Address: 0x000000000022025C Data@ 0x{{.*}} is: 0x000730F7 +CHECK: Address: 0x0000000000220260 Data@ 0x{{.*}} is: 0x07038ED9 +CHECK: Address: 0x0000000000220264 Data@ 0x{{.*}} is: 0x07FB86D9 +CHECK: Address: 0x0000000000220268 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x000000000022026C Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x0000000000220270 Data@ 0x{{.*}} is: 0x54190001 +CHECK: Address: 0x0000000000220274 Data@ 0x{{.*}} is: 0x00011000 +CHECK: Address: 0x0000000000220278 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x000000000022027C Data@ 0x{{.*}} is: 0x00000019 +CHECK: Address: 0x0000000000220280 Data@ 0x{{.*}} is: 0x280003C0 +CHECK: Address: 0x0000000000220284 Data@ 0x{{.*}} is: 0x0002800B +CHECK: Address: 0x0000000000220288 Data@ 0x{{.*}} is: 0x00000000 +CHECK: Address: 0x000000000022028C Data@ 0x{{.*}} is: 0x00000000 +CHECK: Address: 0x0000000000220290 Data@ 0x{{.*}} is: 0x14E78C19 +CHECK: Address: 0x0000000000220294 Data@ 0x{{.*}} is: 0x180A1659 +CHECK: Address: 0x0000000000220298 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x000000000022029C Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x00000000002202A0 Data@ 0x{{.*}} is: 0x1A791659 +CHECK: Address: 0x00000000002202A4 Data@ 0x{{.*}} is: 0x10001819 +CHECK: Address: 0x00000000002202A8 Data@ 0x{{.*}} is: 0x8C0B2843 +CHECK: Address: 0x00000000002202AC Data@ 0x{{.*}} is: 0x00232101 +CHECK: Address: 0x00000000002202B0 Data@ 0x{{.*}} is: 0x00010001 +CHECK: Address: 0x00000000002202B4 Data@ 0x{{.*}} is: 0x8EBB0001 +CHECK: Address: 0x00000000002202B8 Data@ 0x{{.*}} is: 0x00000003 +CHECK: Address: 0x00000000002202BC Data@ 0x{{.*}} is: 0x00000000 + +CHECK: (MaskWrite64): Address: 0x0000000000232000 Mask: 0x00000002 Data: 0x00000002 +CHECK: (MaskWrite64): Address: 0x0000000000232000 Mask: 0x00000002 Data: 0x00000000 +CHECK: (Write64): Address: 0x000000000021F000 Data: 0x00000001 +CHECK: (Write64): Address: 0x000000000021F010 Data: 0x00000000 +CHECK: (NOP Command): Payload Length: 2 +CHECK: (BlockWrite-DMAWriteCmd): Start Address: 0x000000000021D000 Size: 6 +CHECK: Address: 0x000000000021D000 Data@ 0x{{.*}} is: 0x00400001 +CHECK: Address: 0x000000000021D004 Data@ 0x{{.*}} is: 0x00000000 +CHECK: Address: 0x000000000021D008 Data@ 0x{{.*}} is: 0x00000000 +CHECK: Address: 0x000000000021D00C Data@ 0x{{.*}} is: 0x00000000 +CHECK: Address: 0x000000000021D010 Data@ 0x{{.*}} is: 0x00000000 +CHECK: Address: 0x000000000021D014 Data@ 0x{{.*}} is: 0x02041FE1 + +CHECK: (Write64): Address: 0x000000000021DE14 Data: 0x00000000 +CHECK: (MaskWrite64): Address: 0x000000000021DE10 Mask: 0x00000000 Data: 0x00000001 +CHECK: (Write64): Address: 0x000000000003F008 Data: 0x80000000 +CHECK: (Write64): Address: 0x000000000003F100 Data: 0x80000000 +CHECK: (Write64): Address: 0x000000000003F010 Data: 0x8000000E +CHECK: (Write64): Address: 0x000000000003F138 Data: 0x80000000 +CHECK: (Write64): Address: 0x00000000001B001C Data: 0x8000000D +CHECK: (Write64): Address: 0x00000000001B0134 Data: 0x80000000 +CHECK: (Write64): Address: 0x000000000023F014 Data: 0x80000001 +CHECK: (Write64): Address: 0x000000000023F104 Data: 0x80000000 +CHECK: (MaskWrite64): Address: 0x000000000001F004 Mask: 0x00000030 Data: 0x00000010 +CHECK: (MaskWrite64): Address: 0x0000000000232000 Mask: 0x00000001 Data: 0x00000001 diff --git a/runtime/src/iree-amd-aie/aie_runtime/test/pi.elf b/runtime/src/iree-amd-aie/aie_runtime/test/pi.elf new file mode 100644 index 0000000000000000000000000000000000000000..58cd3d10e964f8bc29b0602c50fa01a6932b7652 GIT binary patch literal 8436 zcmeI1-)|Jx702&lgI$~8jZ2743E2dT5UDb2V-c6u)YyiCf`e;*6q7c?*gMWHS?@01 z!QiMWR+J)|5E`Y0V2UVhADT8*L{UWA@{on13PrTxDFq89R@$mjMG?GEN)X%cnVGx$ z^{~S~K*t)-_jAs<=iWIxdv<4M_sX@aLZOh-+cZ^KpcWXf%vWj}jx8#pD%B$OfC}Lc zjDO|j70%uOmVE|x@yWhf{&`yt31puR7W21SYBP1^+N;#_RYfgo6a2ep6>Z_7bkt_} ze|QgnAN)Th|FgdFCj7U^KS^tm&_VbozE~U-m4(xmp>rd1K~_R_hE?ky5w}sHZ1R7m zQsWg(a}I>s+f`0#=>BcIx%+lL-!~F{bnz~wPL%h1S-MB|UB32-j*?^jY!xo@c;#b6)K*|GBcrq8aKq zE(~=$Ute1ruCFW3d(ZXNhNr~Je0>M2>)a|!6*j7|YOHEe_0g~ITdYv0n<^(OuD_D6 z8Sl7LQ=hw2BlT`o?P_dQz5?srQ&ush2B>!5$o@yPZ9IPcA>_GOthXMI$+2DPxKq)0 z75kNZ#ij4%y5O@O zH(s8%F&D#iBWoDFak_3iayHz#=+#62iB_mf`^zdW?fIP6T)#nAPwIjCEvg=q+PYi) zzJJc{n^Wbz`XSXfXLPQt4mH{rdTfC+M@XI8U$`c^y8Bg6w_4ENFk}twOvLQ?vaW8U z-%P!*qOGZJwn^2pZ5C z}5a7XeU)mFx zOx}nALjscp4w1KG>0~7x-doZ?VrSbD|K+vQt5uMrBXCG(pr>@+sbEgOBlm0_IB*==pb7FyW_dQp5q89gk2NRVO#MvxZpV^pgnSwyGzNA8(k$g zf}$g&A15uhRyt-O>0W3_Bx5&`eKYATq`yu2InrC9n@E^EwYL1(tLC2)jPVi=-z=Unc!A z=}BlT&B^l_j{1DBLh771NZ%xVi}Y>Ml1#6&92(b(lfMdD=bTA;7U|ifBc!9ydY!Fg zUq8|ftJ47ASk2H6jiK1}*3>7SF%LF<~ICHpzjACNvz z`Y)s}K(KhVeoXd5qz{umLi#A_w@Ay6CHfpskbal+Nz&5OYVo^_UPlD{2=U`!{039-H-MKA zF9a_qmfp68So+%rV(D=PvGloZ#M0|_5KE66BbGk*DzWssgTxu|&xobx{f2lC_&wsi z;4{S1^ZraMeeWW%^uE6lOP{++EWPf(#7@7%Czh`7G5BkUkAvqDp8&TIzYBhb_#`+^ z{5$YV#D4%EAX>%;t#;B#L}yKiKSng#L}~q#1r71 z#L~N8B9{LB8nN`}L&Vafe?fc;{0_17>faMfUp`ALz4=38>9-Ta(sTboEPeMHvGm^0 ziKYL}_(HK>(sv&umfky$So-f1#L|PCiKP#>5lgRJO)UL#J+bu6=ZK|mCWxh9+QiZ` zcN0tBe1%wg=K*5rpT~%$hrUfb6MT|bdg*Cm>8Iz3rCtpVB^P89qf`5Pty6Sn@A0&RpYP?Kz1vgbdJv5kUg5Q%v36En|30d z61y5m4_ijmXl}HUgUZBI3A-_^j4f-Qav>|aDe8hTkh0Z~g`YdJi2(^SR;*cRtmy4r zZFH~eTDjKPw6b^onsv_@MsqaU6kQUH8b%_OOr)%sVKfOcHtB*i97i%aGK5*pgw-sEf$cjIIPVg!VJm5wSONRDwedAVW!fl z(V_H?Y*ZNoxarTjF|NdmI&3Q=R<-z^$PFS(pM&Q;;9>2NntBj*YmRqB;Q%C=N|^k6T=9O zAy^jR*dR|3Jzj#N-Xwmx2X5Z!>Sb^{cFk`>j}gBOeS!FW=ue10gw~tnm(QxjNT&0B z23|*82Aw9J?*=+4Wc-uhn=tt3CaKJWQebW_%@ms)K$-f=^KJoV{{z1$q z-__;TST^CKKL4+LeA36KeJr0PIn1Z?edOc6`{J+q_>M5Gr$%xSFLZJj*ZUP8_j+?r zVpuKe^Bu709*+mXQOptXSUxLyh~EHb!15hS#>;0%1p6_M-RsKzS;6-J7ZLZ`kW>|( zgF#o}f!YsffcRy@BgQFlKSJCuu>$`lkCNHEY#vq#gV^SH!C@S~gk8@q?-Y5)-r)J= zpy&Ovr}0J9**3$GqX~3eGrW8r^32`;tX&ecW0z;{qGg+y@7@jR{9?nGBK0)(=P6E} z(aXC1ahqV1XY@EYn>?$RINpR!> + +#include "iree-amd-aie/aie_runtime/iree_aie_runtime.h" + +#define NPI_ADDR 0x0 +#define NPU_NUM_COLS 6 +#define NPU_NUM_MEM_TILE_ROWS 1 +#define NPU_NUM_ROWS 6 +#define XAIE_BASE_ADDR 0x40000000 +#define XAIE_COL_SHIFT 25 +#define XAIE_MEM_TILE_ROW_START 1 +#define XAIE_NUM_SHIM_TILE_ROWS 1 +#define XAIE_PARTITION_BASE_ADDR 0x0 +#define XAIE_ROW_SHIFT 20 +#define XAIE_SHIM_ROW 0 + +int main(int argc, char** argv) { + std::string elfPath(argv[1]); + + uint8_t col = 0; + XAie_LocType tile00 = {.Row = 0, .Col = col}; + XAie_LocType tile01 = {.Row = 1, .Col = col}; + XAie_LocType tile02 = {.Row = 2, .Col = col}; + XAie_Lock lock01 = {.LockId = 0, .LockVal = 1}; + XAie_Lock lock10 = {.LockId = 1, .LockVal = 0}; + + XAie_PartitionProp partitionProp; + + XAie_Config config = { + .AieGen = XAIE_DEV_GEN_AIEML, + .BaseAddr = XAIE_BASE_ADDR, + .ColShift = XAIE_COL_SHIFT, + .RowShift = XAIE_ROW_SHIFT, + .NumRows = NPU_NUM_ROWS, + .NumCols = NPU_NUM_COLS, + .ShimRowNum = XAIE_SHIM_ROW, + .MemTileRowStart = XAIE_MEM_TILE_ROW_START, + .MemTileNumRows = NPU_NUM_MEM_TILE_ROWS, + .AieTileRowStart = XAIE_MEM_TILE_ROW_START + NPU_NUM_MEM_TILE_ROWS, + .AieTileNumRows = + NPU_NUM_ROWS - NPU_NUM_MEM_TILE_ROWS - XAIE_NUM_SHIM_TILE_ROWS, + .PartProp = partitionProp, + .Backend = XAIE_IO_BACKEND_CDO}; + + uint8_t partitionStartCol = 1; + uint8_t partitionNumCols = 1; + + XAie_DevInst devInst = {}; + XAie_SetupPartitionConfig(&devInst, XAIE_PARTITION_BASE_ADDR, + partitionStartCol, partitionNumCols); + XAie_CfgInitialize(&devInst, &config); + XAie_UpdateNpiAddr(&devInst, NPI_ADDR); + + EnAXIdebug(); + setEndianness(Little_Endian); + startCDOFileStream("pi.cdo"); + FileHeader(); + + XAie_LoadElf(&devInst, tile02, elfPath.c_str(), /*LoadSym*/ false); + + XAie_CoreReset(&devInst, tile02); + XAie_CoreUnreset(&devInst, tile02); + XAie_LockSetValue(&devInst, tile02, lock01); + XAie_LockSetValue(&devInst, tile02, lock10); + + XAie_DmaDesc dmaTileBd; + XAie_DmaDescInit(&devInst, &dmaTileBd, tile02); + lock10 = XAie_Lock{.LockId = 1, .LockVal = -1}; + dmaTileBd.DmaMod->SetLock(&dmaTileBd, lock10, lock01, /*AcqEn*/ 1, + /*RelEn*/ 0); + // address 1024 is the beginning of the core's stack + XAie_DmaSetAddrLen(&dmaTileBd, /*Addr*/ 1024, /*Len*/ 4); + XAie_DmaEnableBd(&dmaTileBd); + uint8_t bdNum = 0, chNum = 0; + XAie_DmaWriteBd(&devInst, &dmaTileBd, tile02, bdNum); + XAie_DmaChannelSetStartQueue(&devInst, tile02, chNum, + XAie_DmaDirection::DMA_MM2S, bdNum, + /*RepeatCount*/ 1, /*EnTokenIssue*/ 0); + XAie_DmaChannelEnable(&devInst, tile02, chNum, XAie_DmaDirection::DMA_MM2S); + + // Slave == source, Master == destination + // Note, these are internal connections in the switch + // (so src port -> dest port within the switch itself) + XAie_StrmConnCctEnable(&devInst, tile00, /*Slave*/ StrmSwPortType::CTRL, + /*SlvPortNum*/ 0, /*Master*/ StrmSwPortType::SOUTH, + /*MstrPortNum*/ 0); + XAie_StrmConnCctEnable(&devInst, tile00, /*Slave*/ StrmSwPortType::NORTH, + /*SlvPortNum*/ 0, + /*Master*/ StrmSwPortType::SOUTH, /*MstrPortNum*/ 2); + XAie_StrmConnCctEnable(&devInst, tile01, /*Slave*/ StrmSwPortType::NORTH, + /*SlvPortNum*/ 0, + /*Master*/ StrmSwPortType::SOUTH, /*MstrPortNum*/ 0); + XAie_StrmConnCctEnable(&devInst, tile02, /*Slave*/ StrmSwPortType::DMA, + /*SlvPortNum*/ 0, + /*Master*/ StrmSwPortType::SOUTH, /*MstrPortNum*/ 0); + XAie_EnableAieToShimDmaStrmPort(&devInst, tile00, /*PortNum*/ 2); + XAie_CoreEnable(&devInst, tile02); + + configureHeader(); + endCurrentCDOFileStream(); +} diff --git a/third_party/aie-rt b/third_party/aie-rt new file mode 160000 index 000000000..f3fcaaeba --- /dev/null +++ b/third_party/aie-rt @@ -0,0 +1 @@ +Subproject commit f3fcaaeba5c23965d0fc643e564b37b81c327744 diff --git a/third_party/bootgen b/third_party/bootgen new file mode 160000 index 000000000..92e09bf37 --- /dev/null +++ b/third_party/bootgen @@ -0,0 +1 @@ +Subproject commit 92e09bf37ea17d7b1f0e102a2548f27fb768651c