Skip to content

Commit

Permalink
[Programming Guide] lit tests for code samples in programming guide (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
denolf authored Apr 25, 2024
1 parent 05a31ec commit a26185e
Show file tree
Hide file tree
Showing 13 changed files with 614 additions and 23 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ endif()

# Last because each of these has its own CMakeLists.txt which reloads/re-finds LLVM, thus resettings globals.
add_subdirectory(programming_examples)
add_subdirectory(programming_guide)
add_subdirectory(test)
add_subdirectory(mlir_tutorials)
add_subdirectory(cmake/modules)
Expand Down
145 changes: 145 additions & 0 deletions programming_guide/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#
# This file is 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
#
# Copyright (C) 2022, Advanced Micro Devices, Inc.

cmake_minimum_required(VERSION 3.10)

if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()

if(POLICY CMP0068)
cmake_policy(SET CMP0068 NEW)
set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
endif()

if(POLICY CMP0075)
cmake_policy(SET CMP0075 NEW)
endif()

if(POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif()

if(POLICY CMP0144)
cmake_policy(SET CMP0144 NEW)
endif()

project(ref-designs LANGUAGES CXX C)

# find package AIE if running tests from AIE installation
if(NOT AIE_BINARY_DIR)
find_package(AIE REQUIRED CONFIG)
set(LibXAIE_${AIE_RUNTIME_TEST_TARGET}_DIR CACHE STRING "") #pick up libxaiengine from installation folder if no other location specified
endif()

# default to x86_64 system architecture for runtime target
set(AIE_RUNTIME_TARGETS "x86_64" CACHE STRING "Architectures to compile the runtime libraries for.")
list(GET AIE_RUNTIME_TARGETS 0 firstRuntimeTarget)
set(AIE_RUNTIME_TEST_TARGET ${firstRuntimeTarget} CACHE STRING "Runtime architecture to test with.")

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED YES)

option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
option(LLVM_BUILD_TOOLS "Build the LLVM tools. If OFF, just generate build targets." ON)

if(Vitis_FOUND)
set(DEFAULT_ENABLE_CHESS_TESTS ON)
else()
set(DEFAULT_ENABLE_CHESS_TESTS OFF)
endif()
option(ENABLE_CHESS_TESTS "Enable backend tests using xchesscc" ${DEFAULT_ENABLE_CHESS_TESTS})

if(${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL aarch64)
set(DEFAULT_ENABLE_BOARD_TESTS ON)
endif()
option(ENABLE_BOARD_TESTS "Enable board tests" ${DEFAULT_ENABLE_BOARD_TESTS})

find_package(MLIR REQUIRED CONFIG)

message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")

set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin)
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib)
set(MLIR_BINARY_DIR ${CMAKE_BINARY_DIR})

find_package(Vitis 2023.2 COMPONENTS AIE AIE2)
find_package(Python3 COMPONENTS Interpreter)
find_package(XRT)
find_package(OpenCV)
find_package(hsa-runtime64)

# Look for LibXAIE
if (DEFINED LibXAIE_${AIE_RUNTIME_TEST_TARGET}_DIR)
message("Ref designs using xaiengine from LibXAIE_${AIE_RUNTIME_TEST_TARGET}_DIR=${LibXAIE_${AIE_RUNTIME_TEST_TARGET}_DIR}")
set(LibXAIE_ROOT ${LibXAIE_${target}_DIR})
find_package(LibXAIE)
else()
if(DEFINED VITIS_ROOT)
message(STATUS "Ref designs have Vitis available, no libxaie location specified so pick up from build area")
set(LibXAIE_FOUND TRUE)
endif()
endif()

# Define the default arguments to use with 'lit', and an option for the user to
# override.
set(LIT_ARGS_DEFAULT "-sv")
if (MSVC_IDE OR XCODE)
set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
endif()
set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")

list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")

include(TableGen)
include(AddLLVM)
include(AddMLIR)
include(HandleLLVMOptions)

include_directories(${LLVM_INCLUDE_DIRS})
include_directories(${MLIR_INCLUDE_DIRS})
include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(${PROJECT_BINARY_DIR}/include)
add_definitions(${LLVM_DEFINITIONS})

if(ENABLE_CHESS_TESTS)
set(CONFIG_ENABLE_CHESS_TESTS 1)
else()
set(CONFIG_ENABLE_CHESS_TESTS 0)
endif()
if(ENABLE_BOARD_TESTS)
set(CONFIG_ENABLE_BOARD_TESTS 1)
else()
set(CONFIG_ENABLE_BOARD_TESTS 0)
endif()
if(LibXAIE_FOUND)
set(CONFIG_HAS_LIBXAIE 1)
else()
set(CONFIG_HAS_LIBXAIE 0)
endif()
configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
MAIN_CONFIG
${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
)

set(TEST_DEPENDS
FileCheck count not
AIEPythonModules
aie-opt
aie-translate
)

add_lit_testsuite(check-programming-guide "Running the programming guide code samples"
${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${TEST_DEPENDS}
ARGS "-sv --timeout 600"
)
set_target_properties(check-reference-designs PROPERTIES FOLDER "Programming Guide")
Loading

0 comments on commit a26185e

Please sign in to comment.