diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml index a7c24c55..c74b52d4 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -140,23 +140,6 @@ jobs: cd build ninja -v -k0 - - name: cache aocl - id: cache-aocl - uses: actions/cache@v4 - with: - path: c:\aocl - key: aocl-${{ hashFiles('.github/workflows/build-windows.yml', 'scripts/install_aocl.ps1') }} - - - name: install aocl - if: ${{ !steps.cache-aocl.outputs.cache-hit }} - run: pwsh .\scripts\install_aocl.ps1 -installdir C:\aocl - - - name: add aocl to path - run: echo c:\aocl\hld\bin | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - - - name: query aocl version - run: aoc -version - - name: test runtime run: | cd build diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index 0f381417..5c77b39b 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -36,7 +36,6 @@ on: - 'container/opensuse-leap-15-dev/**' - 'container/ubuntu-20.04-dev/**' - 'container/ubuntu-22.04-dev/**' - - 'scripts/install_aocl.sh' pull_request: paths: @@ -47,7 +46,6 @@ on: - 'container/opensuse-leap-15-dev/**' - 'container/ubuntu-20.04-dev/**' - 'container/ubuntu-22.04-dev/**' - - 'scripts/install_aocl.sh' workflow_dispatch: diff --git a/README.md b/README.md index 8346e454..abf1fdf6 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,10 @@ ### Linux -- Red Hat Enterprise Linux (RHEL)\* or Rocky Linux\* 8 +- Red Hat Enterprise Linux (RHEL)\* or Rocky Linux\* 8 or 9 - SUSE Linux Enterprise Server (SLES)\* or openSUSE Leap\* 15 -- Ubuntu\* 18.04, 20.04, or 22.04 LTS -- GCC 7.4.0 and higher +- Ubuntu\* 20.04, or 22.04 LTS +- GCC 7.5.0 and higher - [CMake](https://cmake.org/) 3.10 and higher - [Ninja](https://ninja-build.org/) 1.8.2 and higher - [Git](https://git-scm.com/) @@ -17,7 +17,7 @@ ### Windows - Windows\* 10 (64 bit) -- Windows Server\* 2012, 2016, or 2019 +- Windows Server\* 2019 or 2022 - Microsoft Visual C++ (MSVC)\* 2017 and higher - [CMake](https://cmake.org/) 3.10 and higher - [Ninja](https://ninja-build.org/) 1.8.2 and higher @@ -113,45 +113,6 @@ ctest -V ### Notes -- To run unit tests, you need the `aoc` executable from the IntelⓇ FPGA SDK - for OpenCL™. - - To set the path to `aoc`, change to the IntelⓇ FPGA SDK for OpenCL™ - installation directory and source the initialization script. - - - On Linux: - - ``` - source init_opencl.sh - ``` - - - On Windows: - - ``` - call init_opencl.bat - ``` - -- On Linux, `aoc` requires the `libtinfo.so.5` library, which you can install - using one of the following OS-specific commands: - - - Red Hat Enterprise Linux (RHEL)\* or Rocky Linux\* 8: - - ``` - sudo yum install ncurses-compat-libs-6.1 - ``` - - - SUSE Linux Enterprise Server (SLES)\* or openSUSE Leap\* 15: - - ``` - sudo zypper install libncurses5 - ``` - - - Ubuntu\* 18.04 or 20.04 LTS: - - ``` - sudo apt install libtinfo5 - ``` - - On Windows, you need to set the paths to the libelf and (optionally) zlib libraries. ``` @@ -186,7 +147,19 @@ Perform these steps if you have the IntelⓇ FPGA SDK for OpenCL™ or IntelⓇ FPGA RTE for OpenCL™ installed on your system: 1. In the IntelⓇ FPGA SDK for OpenCL™ installation directory, source - the initialization script (see [Running Unit Tests](#running-unit-tests)). + the initialization script. + + - On Linux: + + ``` + source init_opencl.sh + ``` + + - On Windows: + + ``` + call init_opencl.bat + ``` 2. Update the `/etc/OpenCL/vendors/Altera.icd` file with either the filename `libalteracl.so` if `LD_LIBRARY_PATH` contains the full path of the runtime diff --git a/container/opensuse-leap-15-dev/Dockerfile b/container/opensuse-leap-15-dev/Dockerfile index efe9b8ca..81ff7b42 100644 --- a/container/opensuse-leap-15-dev/Dockerfile +++ b/container/opensuse-leap-15-dev/Dockerfile @@ -36,16 +36,9 @@ RUN zypper -n update \ which \ zlib-devel \ && zypper -n clean \ - && ./install_aocl.sh /opt/aocl \ && useradd --system ${uid:+--uid "$uid"} --user-group --shell /sbin/nologin --create-home --home-dir /home/build build \ && echo 'build ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/build \ && rm -rf "$PWD" USER build WORKDIR /home/build - -ENV PATH="/opt/aocl/hld/bin:$PATH" -# Workaround for libnsl.so.1 not installed by default on the latest OpenSUSE image -RUN mkdir -p /tmp/aoc && ln -snf /usr/lib64/libnsl.so.2.0.0 /tmp/aoc/libnsl.so.1 -ENV LD_LIBRARY_PATH="/tmp/aoc:$LD_LIBRARY_PATH" -RUN aoc -version diff --git a/container/rockylinux-8-dev/Dockerfile b/container/rockylinux-8-dev/Dockerfile index a667d331..39a38928 100644 --- a/container/rockylinux-8-dev/Dockerfile +++ b/container/rockylinux-8-dev/Dockerfile @@ -41,13 +41,9 @@ RUN \ which \ zlib-devel \ && yum -y clean all \ - && ./install_aocl.sh /opt/aocl \ && useradd --system ${uid:+--uid "$uid"} --user-group --shell /sbin/nologin --create-home --home-dir /home/build build \ && echo 'build ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/build \ && rm -rf "$PWD" USER build WORKDIR /home/build - -ENV PATH="/opt/aocl/hld/bin:$PATH" -RUN aoc -version diff --git a/container/rockylinux-9-dev/Dockerfile b/container/rockylinux-9-dev/Dockerfile index 6b75483f..79d71cde 100644 --- a/container/rockylinux-9-dev/Dockerfile +++ b/container/rockylinux-9-dev/Dockerfile @@ -44,13 +44,9 @@ RUN \ which \ zlib-devel \ && yum -y clean all \ - && ./install_aocl.sh /opt/aocl \ && useradd --system ${uid:+--uid "$uid"} --user-group --shell /sbin/nologin --create-home --home-dir /home/build build \ && echo 'build ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/build \ && rm -rf "$PWD" USER build WORKDIR /home/build - -ENV PATH="/opt/aocl/hld/bin:$PATH" -RUN aoc -version diff --git a/container/ubuntu-20.04-dev/Dockerfile b/container/ubuntu-20.04-dev/Dockerfile index 66a69979..6ffb46ee 100644 --- a/container/ubuntu-20.04-dev/Dockerfile +++ b/container/ubuntu-20.04-dev/Dockerfile @@ -32,13 +32,9 @@ RUN apt-get -y update \ sudo \ zlib1g-dev \ && apt-get -y clean \ - && ./install_aocl.sh /opt/aocl \ && useradd --system ${uid:+--uid "$uid"} --user-group --shell /sbin/nologin --create-home --home-dir /home/build build \ && echo 'build ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/build \ && rm -rf "$PWD" USER build WORKDIR /home/build - -ENV PATH="/opt/aocl/hld/bin:$PATH" -RUN aoc -version diff --git a/container/ubuntu-22.04-dev/Dockerfile b/container/ubuntu-22.04-dev/Dockerfile index 2fe1f6f4..ef853ddf 100644 --- a/container/ubuntu-22.04-dev/Dockerfile +++ b/container/ubuntu-22.04-dev/Dockerfile @@ -40,7 +40,6 @@ RUN apt-get -y update \ sudo \ zlib1g-dev \ && apt-get -y clean \ - && ./install_aocl.sh /opt/aocl \ && useradd --system ${uid:+--uid "$uid"} --user-group --shell /sbin/nologin --create-home --home-dir /home/build build \ && echo 'build ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/build \ && rm -rf "$PWD" @@ -48,6 +47,5 @@ RUN apt-get -y update \ USER build WORKDIR /home/build -ENV PATH="/opt/aocl/hld/bin:/usr/lib/llvm-13/bin:$PATH" -RUN aoc -version +ENV PATH="/usr/lib/llvm-13/bin:$PATH" RUN clang-format --version diff --git a/scripts/install_aocl.ps1 b/scripts/install_aocl.ps1 deleted file mode 100755 index b87f21af..00000000 --- a/scripts/install_aocl.ps1 +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright (C) 2021 Intel Corporation -# SPDX-License-Identifier: BSD-3-Clause - -# Install Intel FPGA SDK for OpenCL Pro Edition -# https://fpgasoftware.intel.com/ - -Param( - [Parameter(Mandatory)]$installdir, - $major="21", - $minor="3", - $patch="0", - $build="170", - $version="$major.$minor.$patch.$build", - $installer="AOCLProSetup-$version-windows.exe", - $installer_url="https://download.altera.com/akdlm/software/acdsinst/$major.$minor/$build/ib_installers/$installer", - $sha256="d7177d248e81ce2f2f228b4c99650a1baecb3de01d6b1842f2fe3d713a24b870" -) - -$ErrorActionPreference = "Stop" - -Invoke-WebRequest $installer_url -OutFile $installer - -$download_sha256 = (Get-FileHash $installer -Algorithm SHA256).Hash -if ($download_sha256 -ne $sha256) { - throw "SHA256 $download_sha256 of downloaded file does not match expected SHA256 $sha256" -} - -Start-Process -Wait -FilePath $installer -ArgumentList --mode,unattended,--installdir,$installdir,--accept_eula,1 diff --git a/scripts/install_aocl.sh b/scripts/install_aocl.sh deleted file mode 100755 index d765fccf..00000000 --- a/scripts/install_aocl.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -# Copyright (C) 2021 Intel Corporation -# SPDX-License-Identifier: BSD-3-Clause - -# Install Intel FPGA SDK for OpenCL Pro Edition -# https://fpgasoftware.intel.com/ - -set -eu -o pipefail - -installdir="$1" -major=21 -minor=3 -patch=0 -build=170 -version="$major.$minor.$patch.$build" -installer="AOCLProSetup-$version-linux.run" -installer_url="https://download.altera.com/akdlm/software/acdsinst/$major.$minor/$build/ib_installers/$installer" - -curl -L -o "$installer" "$installer_url" -chmod +x "$installer" -./"$installer" --mode unattended --installdir "$installdir" --accept_eula 1 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f29f61f4..4b2e7d99 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -52,7 +52,10 @@ target_link_libraries(acl_test PRIVATE ) add_test(NAME acl_test COMMAND acl_test -v) set_property(TEST acl_test PROPERTY ENVIRONMENT - "AOCL_BOARD_PACKAGE_ROOT=${CMAKE_CURRENT_SOURCE_DIR}/board/a10_ref" + "\ +AOCL_BOARD_PACKAGE_ROOT=${CMAKE_CURRENT_SOURCE_DIR}/board/a10_ref;\ +ACL_TEST_EXAMPLE_BINARY=${CMAKE_CURRENT_SOURCE_DIR}/example_binary\ +" ) add_subdirectory(fake_bsp) diff --git a/test/acl_kernel_test.cpp b/test/acl_kernel_test.cpp index c7f05e8b..c1334095 100644 --- a/test/acl_kernel_test.cpp +++ b/test/acl_kernel_test.cpp @@ -1443,6 +1443,12 @@ TEST(acl_kernel, enqueue_ndrange) { MT_TEST(acl_kernel, test_local_work_group_size_debug_msg) { ACL_LOCKED(acl_print_debug_msg("test local wg size debug msg\n")); + if (acl_getenv(ENV_ACL_CONTEXT_CALLBACK_DEBUG)) { + // Skip this test if ACL_CONTEXT_CALLBACK_DEBUG is set as it will + // disrupt printed messages. + return; + } + // Create buffer for debug msg std::stringstream msg_buf; std::streambuf *cout_ptr = std::cout.rdbuf(msg_buf.rdbuf()); diff --git a/test/acl_program_test.cpp b/test/acl_program_test.cpp index 782eb986..10cba4b5 100644 --- a/test/acl_program_test.cpp +++ b/test/acl_program_test.cpp @@ -844,7 +844,7 @@ MT_TEST_GROUP(from_source) { void load(int compiler_mode = CL_CONTEXT_COMPILER_MODE_OFFLINE_CREATE_EXE_LIBRARY_INTELFPGA, - const char *compile_command = 0, bool print_notify = true) { + std::string compile_command = "", bool print_notify = true) { unload(); CHECK_EQUAL(CL_SUCCESS, clGetPlatformIDs(1, &m_platform, 0)); CHECK(acl_platform_is_valid(m_platform)); @@ -853,14 +853,31 @@ MT_TEST_GROUP(from_source) { &m_device[0], &m_num_devices)); CHECK(m_num_devices > 0); + // Check if there is precompiled binaries, if envvar set, use that instead + const char *envvar_example_binary = "ACL_TEST_EXAMPLE_BINARY"; + const char *example_binary_root = acl_getenv(envvar_example_binary); + if (example_binary_root) { + // Precompiled binaries exist, emulate the compile by copying the + // precompiled binaries to the current directory. +#ifdef _WIN32 + std::string bin_file = + std::string(example_binary_root) + "/windows/foo.aocr"; +#else + std::string bin_file = + std::string(example_binary_root) + "/linux/foo.aocr"; +#endif + compile_command = "cp " + bin_file + " ./kernels.aocr && echo "; + } + cl_int status = CL_INVALID_DEVICE; cl_context_properties props[] = { CL_CONTEXT_PROGRAM_EXE_LIBRARY_ROOT_INTELFPGA, (cl_context_properties)m_basedir.c_str(), CL_CONTEXT_COMPILER_MODE_INTELFPGA, compiler_mode, - (compile_command ? CL_CONTEXT_COMPILE_COMMAND_INTELFPGA : 0), - (cl_context_properties)compile_command, + (compile_command != "" ? CL_CONTEXT_COMPILE_COMMAND_INTELFPGA : 0), + (cl_context_properties)(compile_command != "" ? compile_command.c_str() + : 0), 0, 0}; m_context = @@ -949,7 +966,8 @@ MT_TEST(from_source, make_prog_dir_and_build_command) { // Default arguments, just turning off printing of errors for invalid calls to // be tested below - load(CL_CONTEXT_COMPILER_MODE_OFFLINE_CREATE_EXE_LIBRARY_INTELFPGA, 0, false); + load(CL_CONTEXT_COMPILER_MODE_OFFLINE_CREATE_EXE_LIBRARY_INTELFPGA, "", + false); load_program(); // Before build. No executable. @@ -1082,11 +1100,9 @@ MT_TEST(from_source, online_mode) { ACL_LOCKED(CHECK(acl_realpath_existing(check_str) != "")); check_str = m_hashdir + std::string("/build.cmd"); ACL_LOCKED(CHECK(acl_realpath_existing(check_str) != "")); - // Since we invoked compiler with -rtl, we only get an .aoco and .aocr + // If we have invoked compiler with -rtl, we should get an .aocr check_str = m_hashdir + std::string("/kernels.aocr"); ACL_LOCKED(CHECK(acl_realpath_existing(check_str) != "")); - check_str = m_hashdir + std::string("/kernels/kernels.v"); - ACL_LOCKED(CHECK(acl_realpath_existing(check_str) != "")); // Check the build log. size_t size_ret; diff --git a/test/acl_test.cpp b/test/acl_test.cpp index cfa4bb22..66b6de50 100644 --- a/test/acl_test.cpp +++ b/test/acl_test.cpp @@ -218,91 +218,140 @@ const unsigned char *acl_test_get_example_binary(size_t *binary_len) { } static void l_load_example_binary(void) { - const char *envvar_offline_device = "CL_CONTEXT_OFFLINE_DEVICE_INTELFPGA"; - const char *envvar_program_lib = - "CL_CONTEXT_PROGRAM_EXE_LIBRARY_ROOT_INTELFPGA"; - const char *offline_old_value = acl_getenv(envvar_offline_device); - const char *program_lib_old_value = acl_getenv(envvar_program_lib); - int system_ret = -1; - enum { MAX_DEVICES = 100 }; - cl_platform_id platform; - cl_device_id device[MAX_DEVICES]; - cl_context context; - cl_program program; - cl_int status; - - acl_test_setenv(envvar_offline_device, ACLTEST_DEFAULT_BOARD); - acl_test_setenv(envvar_program_lib, ".acltest_builtin_prog"); - system_ret = system("rm -rf .acltest_builtin_prog"); - assert(system_ret != -1); - - ACL_LOCKED(acl_test_setup_generic_system()); - // Since this runs before the CppUTest runner is set up, we can't use // the CHECK* macros. // Just use asserts. - assert(CL_SUCCESS == clGetPlatformIDs(1, &platform, 0)); - assert(CL_SUCCESS == clGetDeviceIDs(platform, CL_DEVICE_TYPE_ACCELERATOR, - MAX_DEVICES, device, 0)); + const char *envvar_example_binary = "ACL_TEST_EXAMPLE_BINARY"; + const char *example_binary_root = acl_getenv(envvar_example_binary); + if (example_binary_root) { + // Precompiled binaries exist, just read its content + ACL_LOCKED(acl_test_setup_generic_system()); +#ifdef _WIN32 + std::string bin_file = + std::string(example_binary_root) + "/windows/example.aocr"; +#else + std::string bin_file = + std::string(example_binary_root) + "/linux/example.aocr"; +#endif + FILE *infile = fopen(bin_file.c_str(), "rb"); + assert(infile && "Cannot open example binary example.aocr, make sure " + "ACL_TEST_EXAMPLE_BINARY is set to the correct path"); + + // Get binary length + assert(fseek(infile, 0, SEEK_END) == 0); + long int position = ftell(infile); + assert(position != -1L); + acl_test_example_binary_len = (size_t)position; + // Return to beginning of file + assert(fseek(infile, 0, SEEK_SET) == 0); + + // Read binary + acl_test_example_binary = + (unsigned char *)acl_malloc(acl_test_example_binary_len); + assert(acl_test_example_binary); + assert(fread(acl_test_example_binary, sizeof(char), + acl_test_example_binary_len, + infile) == acl_test_example_binary_len); + assert(fclose(infile) == 0); + } else { + // Precompiled binaries don't exist, do an actual compile with the + // aoc compiler and store the binary as test example binary. + const char *envvar_offline_device = "CL_CONTEXT_OFFLINE_DEVICE_INTELFPGA"; + const char *envvar_program_lib = + "CL_CONTEXT_PROGRAM_EXE_LIBRARY_ROOT_INTELFPGA"; + const char *offline_old_value = acl_getenv(envvar_offline_device); + const char *program_lib_old_value = acl_getenv(envvar_program_lib); + int system_ret = -1; + enum { MAX_DEVICES = 100 }; + cl_platform_id platform; + cl_device_id device[MAX_DEVICES]; + cl_context context; + cl_program program; + cl_int status; + + acl_test_setenv(envvar_offline_device, ACLTEST_DEFAULT_BOARD); + acl_test_setenv(envvar_program_lib, ".acltest_builtin_prog"); + system_ret = system("rm -rf .acltest_builtin_prog"); + assert(system_ret != -1); - cl_context_properties props[] = { - CL_CONTEXT_COMPILER_MODE_INTELFPGA, - CL_CONTEXT_COMPILER_MODE_OFFLINE_CREATE_EXE_LIBRARY_INTELFPGA, 0}; - context = clCreateContext(props, 1, device, acl_test_notify_print, 0, 0); - assert(context); - - const char *src = - "kernel void vecaccum(global int*A, global int*B) {\n" - " size_t gid = get_global_id(0);\n" - " A[gid] += B[gid];\n" - "};\n" - // This one has two constant arguments. - "kernel void vecsum(global int*A, constant int*B, constant int*C) {\n" - " size_t gid = get_global_id(0);\n" - " A[gid] = B[gid] + C[gid];\n" - "};\n" - - // This has a printf. - "kernel void printit(global int*A) {\n" - " printf(\"Hello world! %d\\n\", A[0]);\n" - "};\n"; - - program = clCreateProgramWithSource(context, 1, &src, 0, 0); - assert(program); - - status = clBuildProgram(program, 1, device, "-cl-kernel-arg-info", 0, 0); - if (status != CL_SUCCESS) { - printf("Compilation failed. Kernel source is:\n-----\n%s\n----\n", src); + ACL_LOCKED(acl_test_setup_generic_system()); + + assert(CL_SUCCESS == clGetPlatformIDs(1, &platform, 0)); + assert(CL_SUCCESS == clGetDeviceIDs(platform, CL_DEVICE_TYPE_ACCELERATOR, + MAX_DEVICES, device, 0)); + + cl_context_properties props[] = { + CL_CONTEXT_COMPILER_MODE_INTELFPGA, + CL_CONTEXT_COMPILER_MODE_OFFLINE_CREATE_EXE_LIBRARY_INTELFPGA, 0}; + context = clCreateContext(props, 1, device, acl_test_notify_print, 0, 0); + assert(context); + + const char *src = + "kernel void vecaccum(global int*A, global int*B) {\n" + " size_t gid = get_global_id(0);\n" + " A[gid] += B[gid];\n" + "};\n" + // This one has two constant arguments. + "kernel void vecsum(global int*A, constant int*B, constant int*C) {\n" + " size_t gid = get_global_id(0);\n" + " A[gid] = B[gid] + C[gid];\n" + "};\n" + + // This has a printf. + "kernel void printit(global int*A) {\n" + " printf(\"Hello world! %d\\n\", A[0]);\n" + "};\n"; + + program = clCreateProgramWithSource(context, 1, &src, 0, 0); + assert(program); + + status = clBuildProgram(program, 1, device, "-cl-kernel-arg-info", 0, 0); + if (status != CL_SUCCESS) { + printf("Compilation failed. Kernel source is:\n-----\n%s\n----\n", src); + size_t log_size = 0; + clGetProgramBuildInfo(program, device[0], CL_PROGRAM_BUILD_LOG, 0, 0, + &log_size); + char *log = (char *)acl_malloc(log_size); + clGetProgramBuildInfo(program, device[0], CL_PROGRAM_BUILD_LOG, log_size, + log, 0); + if (log) + printf("Build log is:\n-----\n%s\n----\n", log); + exit(1); + } + + // The build log should not be empty size_t log_size = 0; + size_t empty_log_size = 1; clGetProgramBuildInfo(program, device[0], CL_PROGRAM_BUILD_LOG, 0, 0, &log_size); - char *log = (char *)acl_malloc(log_size); - clGetProgramBuildInfo(program, device[0], CL_PROGRAM_BUILD_LOG, log_size, - log, 0); - if (log) - printf("Build log is:\n-----\n%s\n----\n", log); - exit(1); + assert(log_size > empty_log_size); + + acl_test_example_binary_len = 0; + assert(CL_SUCCESS == clGetProgramInfo(program, CL_PROGRAM_BINARY_SIZES, + sizeof(size_t), + &acl_test_example_binary_len, 0)); + acl_test_example_binary = + (unsigned char *)acl_malloc(acl_test_example_binary_len); + assert(acl_test_example_binary); + assert(CL_SUCCESS == clGetProgramInfo(program, CL_PROGRAM_BINARIES, + sizeof(acl_test_example_binary), + &acl_test_example_binary, 0)); + + // Don't leak + clReleaseProgram(program); + clReleaseContext(context); + + acl_test_unsetenv(envvar_offline_device); + if (offline_old_value) { + acl_test_setenv(envvar_offline_device, offline_old_value); + } + acl_test_unsetenv(envvar_program_lib); + if (program_lib_old_value) { + acl_test_setenv(envvar_program_lib, program_lib_old_value); + } } - // The build log should not be empty - size_t log_size = 0; - size_t empty_log_size = 1; - clGetProgramBuildInfo(program, device[0], CL_PROGRAM_BUILD_LOG, 0, 0, - &log_size); - assert(log_size > empty_log_size); - - acl_test_example_binary_len = 0; - assert(CL_SUCCESS == clGetProgramInfo(program, CL_PROGRAM_BINARY_SIZES, - sizeof(size_t), - &acl_test_example_binary_len, 0)); - acl_test_example_binary = - (unsigned char *)acl_malloc(acl_test_example_binary_len); - assert(acl_test_example_binary); - assert(CL_SUCCESS == clGetProgramInfo(program, CL_PROGRAM_BINARIES, - sizeof(acl_test_example_binary), - &acl_test_example_binary, 0)); - // Save the derived sysdef for later tests. { acl_pkg_file_t pkg; @@ -334,19 +383,6 @@ static void l_load_example_binary(void) { acl_pkg_close_file(pkg); } - // Don't leak - clReleaseProgram(program); - clReleaseContext(context); - - acl_test_unsetenv(envvar_offline_device); - if (offline_old_value) { - acl_test_setenv(envvar_offline_device, offline_old_value); - } - acl_test_unsetenv(envvar_program_lib); - if (program_lib_old_value) { - acl_test_setenv(envvar_program_lib, program_lib_old_value); - } - ACL_LOCKED(acl_test_teardown_generic_system()); } diff --git a/test/example_binary/README.md b/test/example_binary/README.md new file mode 100644 index 00000000..219fc44f --- /dev/null +++ b/test/example_binary/README.md @@ -0,0 +1,38 @@ +# Precompiled Binaries for Runtime Unit Tests + +This directory contains precompiled binaries that the runtime unit tests could use. + +When the environment variable `ACL_TEST_EXAMPLE_BINARY` is set, precompiled binaries +will be used for the unit tests, instead of compiling with aoc in-time. The environment +variable is set to this directory by default by the unit test CMake configuration. + +## Unit Tests Using AOC compiler + +During setup, the runtime loads an example binary that may be obtained and used by +any runtime unit tests. The loading is done in the function `l_load_example_binary` +of acl_test.cpp, and the loaded binary can be obtained by calling the function +`acl_test_get_example_binary`. + +Other than this, the program `from_source` test group contains two tests that either +requires the aoc compiler, or the precompiled binaries to be present: + +- `make_prog_dir_and_build_command` +- `online_mode` + +## Overriding the Binaries to be Used + +To use precompiled binaries contained in another directory, set `ACL_TEST_EXAMPLE_BINARY` +to the root of that directory, and make sure there is a `linux` subdirectory for linux +precompiled binaries and a `windows` subdirectory for windows precompile binaries. + +## Updating the Binaries + +In case binaries have to be updated, make sure the aoc compiler is available, and +run the compile scripts contained in each of the corresponding OS subdirectories: + +``` +# On Linux +sh linux/compile_aocr.sh +# On Windows +windows\compile_aocr.sh +``` diff --git a/test/example_binary/linux/compile_aocr.sh b/test/example_binary/linux/compile_aocr.sh new file mode 100755 index 00000000..44f59ec0 --- /dev/null +++ b/test/example_binary/linux/compile_aocr.sh @@ -0,0 +1,38 @@ +#!/bin/bash +# Copyright (C) 2021 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause + +set -eux -o pipefail + +if ! command -v aoc &> /dev/null +then + echo "Error: aoc could not be found on PATH" + exit 1 +fi + +scripthome=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +AOCL_BOARD_PACKAGE_ROOT=$(readlink -f "$scripthome/../../board/a10_ref") +export AOCL_BOARD_PACKAGE_ROOT + +# First compile example.cl +kernel='example' +board='a10_ref_small' +compile_arg='-cl-kernel-arg-info' +compute_hash='f3effd06c681436a828f7e11c6c1b037807ddba0' +src=$(readlink -f "$scripthome/../src/$kernel.cl") +dest="$scripthome/$kernel.aocr" + +aoc -rtl -tidy -board="$board" -hash="$compute_hash" "$src" "$compile_arg" -o "$dest" + +# Then compile foo.cl +kernel='foo' +board='a10_ref_small' +compile_arg='' +compute_hash='7128ac1c937694f5b54a12229f19e4ca3a494c16' +src=$(readlink -f "$scripthome/../src/$kernel.cl") +dest="$scripthome/$kernel.aocr" + +aoc -rtl -tidy -board="$board" -hash="$compute_hash" "$src" "$compile_arg" -o "$dest" + +# Clean up +rm -rf "$scripthome"/*.temp "$scripthome"/*.bc diff --git a/test/example_binary/linux/example.aocr b/test/example_binary/linux/example.aocr new file mode 100644 index 00000000..c3a4c95c Binary files /dev/null and b/test/example_binary/linux/example.aocr differ diff --git a/test/example_binary/linux/foo.aocr b/test/example_binary/linux/foo.aocr new file mode 100644 index 00000000..f959e589 Binary files /dev/null and b/test/example_binary/linux/foo.aocr differ diff --git a/test/example_binary/src/example.cl b/test/example_binary/src/example.cl new file mode 100644 index 00000000..ef5968ac --- /dev/null +++ b/test/example_binary/src/example.cl @@ -0,0 +1,11 @@ +kernel void vecaccum(global int*A, global int*B) { + size_t gid = get_global_id(0); + A[gid] += B[gid]; +}; +kernel void vecsum(global int*A, constant int*B, constant int*C) { + size_t gid = get_global_id(0); + A[gid] = B[gid] + C[gid]; +}; +kernel void printit(global int*A) { + printf("Hello world! %d\n", A[0]); +}; diff --git a/test/example_binary/src/foo.cl b/test/example_binary/src/foo.cl new file mode 100644 index 00000000..a3c455aa --- /dev/null +++ b/test/example_binary/src/foo.cl @@ -0,0 +1 @@ +kernel void foo(){} diff --git a/test/example_binary/windows/compile_aocr.cmd b/test/example_binary/windows/compile_aocr.cmd new file mode 100644 index 00000000..cc117afc --- /dev/null +++ b/test/example_binary/windows/compile_aocr.cmd @@ -0,0 +1,45 @@ +REM Copyright (C) 2021 Intel Corporation +REM SPDX-License-Identifier: BSD-3-Clause + +WHERE /q aoc +IF ERRORLEVEL 1 ( + ECHO Error: aoc could not be found on PATH + EXIT /B +) + +SET scripthome=%~dp0 +SET OLD_BOARD_PACKAGE_ROOT=%AOCL_BOARD_PACKAGE_ROOT% +SET AOCL_BOARD_PACKAGE_ROOT=%scripthome%/../../board/a10_ref + +REM First compile example.cl +SET kernel=example +SET board=a10_ref_small +SET compile_arg=-cl-kernel-arg-info +SET compute_hash=f3effd06c681436a828f7e11c6c1b037807ddba0 +SET src=%scripthome%\..\src\%kernel%.cl +SET dest=%scripthome%\%kernel%.aocr + +aoc -rtl -tidy -board=%board% -hash=%compute_hash% %src% %compile_arg% -o %dest% + +REM Then compile foo.cl +SET kernel=foo +SET board=a10_ref_small +SET compile_arg= +SET compute_hash=7128ac1c937694f5b54a12229f19e4ca3a494c16 +SET src=%scripthome%/../src/%kernel%.cl +SET dest=%scripthome%/%kernel%.aocr + +aoc -rtl -tidy -board=%board% -hash=%compute_hash% %src% %compile_arg% -o %dest% + +REM Clean up +DEL /f %scripthome%\*.temp %scripthome%\*.bc + +REM Unset variables +SET AOCL_BOARD_PACKAGE_ROOT=%OLD_BOARD_PACKAGE_ROOT% +SET scripthome= +SET kernel= +SET board= +SET compile_arg= +SET compute_hash= +SET src= +SET dest= diff --git a/test/example_binary/windows/example.aocr b/test/example_binary/windows/example.aocr new file mode 100755 index 00000000..de543597 Binary files /dev/null and b/test/example_binary/windows/example.aocr differ diff --git a/test/example_binary/windows/foo.aocr b/test/example_binary/windows/foo.aocr new file mode 100755 index 00000000..6eb1a7eb Binary files /dev/null and b/test/example_binary/windows/foo.aocr differ