diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 34cf397b9..58534199a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,17 +21,16 @@ on: branches: [ main ] env: - build_dir: "build" + build-dir: "build" config: "Release" artifact: "native" nt: "4" jobs: - windows: - runs-on: windows-2019 + runs-on: windows-2022 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 with: submodules: true fetch-depth: 0 @@ -43,44 +42,22 @@ jobs: arch: amd64 - name: Configure CMake - run: cmake . -G Ninja -B ${{ env.build_dir }} -DCMAKE_BUILD_TYPE=${{ env.config }} + run: | + cmake . -G Ninja -B ${{ env.build-dir }} -DCMAKE_BUILD_TYPE=${{ env.config }} -DSPLA_BUILD_OPENCL=OFF - name: Build library sources - run: cmake --build ${{ env.build_dir }} + run: cmake --build ${{ env.build-dir }} --verbose -j ${{ env.nt }} - name: Upload binary uses: actions/upload-artifact@v4 with: name: windows-${{env.artifact}} - path: ${{env.build_dir}}/spla_x64.dll - - - ubuntu: - runs-on: ubuntu-24.04 - steps: - - uses: actions/checkout@v4 - with: - submodules: true - fetch-depth: 0 - - - uses: seanmiddleditch/gha-setup-ninja@master - - - name: Configure CMake - run: cmake . -G Ninja -B ${{ env.build_dir }} -DCMAKE_BUILD_TYPE=${{ env.config }} - - - name: Build library sources - run: cmake --build ${{ env.build_dir }} - - - name: Upload binary - uses: actions/upload-artifact@v4 - with: - name: linux-${{env.artifact}} - path: ${{env.build_dir}}/libspla_x64.so + path: ${{env.build-dir}}/spla_x64.dll macos: runs-on: macos-14 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 with: submodules: true fetch-depth: 0 @@ -88,23 +65,28 @@ jobs: - uses: seanmiddleditch/gha-setup-ninja@master - name: Configure CMake x64 - run: cmake . -G Ninja -B ${{ env.build_dir }} -DCMAKE_BUILD_TYPE=${{ env.config }} -DCMAKE_OSX_ARCHITECTURES=x86_64 + run: cmake . -G Ninja -B ${{ env.build-dir }} -DCMAKE_BUILD_TYPE=${{ env.config }} -DCMAKE_OSX_ARCHITECTURES=x86_64 - name: Build library sources x64 - run: cmake --build ${{ env.build_dir }} + run: cmake --build ${{ env.build-dir }} - name: Configure CMake arm64 - run: cmake . -G Ninja -B ${{ env.build_dir }} -DCMAKE_BUILD_TYPE=${{ env.config }} -DCMAKE_OSX_ARCHITECTURES=arm64 + run: | + cmake . -G Ninja \ + -B ${{ env.build-dir }} \ + -DCMAKE_BUILD_TYPE=${{ env.config }} \ + -DCMAKE_OSX_ARCHITECTURES=arm64 \ + -DSPLA_BUILD_OPENCL=OFF env: BOOST_ROOT: ${{ steps.install-boost.outputs.BOOST_ROOT }} - name: Build library sources arm64 - run: cmake --build ${{ env.build_dir }} + run: cmake --build ${{ env.build-dir }} --verbose -j ${{ env.nt }} - name: Upload binary uses: actions/upload-artifact@v4 with: name: macos-${{env.artifact}} path: | - ${{env.build_dir}}/libspla_x64.dylib - ${{env.build_dir}}/libspla_arm64.dylib + ${{env.build-dir}}/libspla_x64.dylib + ${{env.build-dir}}/libspla_arm64.dylib diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml index 61f697d55..76e2c460d 100644 --- a/.github/workflows/clang-format.yml +++ b/.github/workflows/clang-format.yml @@ -26,9 +26,10 @@ jobs: - 'tests' - 'examples' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 + - name: Run clang-format style check - uses: jidicula/clang-format-action@v4.10.1 + uses: jidicula/clang-format-action@v4.15.0 with: - clang-format-version: '15' + clang-format-version: '20' check-path: ${{ matrix.path }} diff --git a/.github/workflows/deploy-test.yml b/.github/workflows/deploy-test.yml index e22cd7855..ae0c00869 100644 --- a/.github/workflows/deploy-test.yml +++ b/.github/workflows/deploy-test.yml @@ -2,7 +2,7 @@ name: Python Package (Test) on: workflow_run: - workflows: [ "Build" ] + workflows: [ Build ] branches: [ "pre-release" ] types: - completed @@ -14,10 +14,8 @@ jobs: if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v6 with: python-version: '3.8' @@ -27,7 +25,7 @@ jobs: pip install setuptools wheel twine - name: Download artifact - uses: dawidd6/action-download-artifact@v2 + uses: dawidd6/action-download-artifact@v5 with: workflow: build.yml workflow_conclusion: success diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 026492987..a689e31d0 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -14,12 +14,12 @@ jobs: if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v6 with: - python-version: '3.8' + python-version: '3.12.5' - name: Install dependencies run: | @@ -27,7 +27,7 @@ jobs: pip install setuptools wheel twine - name: Download artifact - uses: dawidd6/action-download-artifact@v2 + uses: dawidd6/action-download-artifact@v5 with: workflow: build.yml workflow_conclusion: success diff --git a/.github/workflows/docs-cpp.yml b/.github/workflows/docs-cpp.yml index bd557537f..f89432a91 100644 --- a/.github/workflows/docs-cpp.yml +++ b/.github/workflows/docs-cpp.yml @@ -17,13 +17,13 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 - name: Generate documentation - uses: mattnotmitt/doxygen-action@v1.3.1 + uses: mattnotmitt/doxygen-action@v1.12.0 - name: Publish to Github Pages - uses: peaceiris/actions-gh-pages@v3 + uses: peaceiris/actions-gh-pages@v4 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./html/ diff --git a/.github/workflows/docs-python.yml b/.github/workflows/docs-python.yml index 5a288db1e..26782bd6d 100644 --- a/.github/workflows/docs-python.yml +++ b/.github/workflows/docs-python.yml @@ -14,12 +14,12 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [ 3.8 ] + python-version: [ 3.12.5 ] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v6 with: python-version: ${{ matrix.python-version }} @@ -32,8 +32,8 @@ jobs: SPLA_DOCS: true - name: Publish to Github Pages - uses: peaceiris/actions-gh-pages@v3 + uses: peaceiris/actions-gh-pages@v4 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./pydocs/ - destination_dir: docs-python \ No newline at end of file + destination_dir: docs-python diff --git a/.github/workflows/self-hosted.yml b/.github/workflows/self-hosted.yml new file mode 100644 index 000000000..84f0e967e --- /dev/null +++ b/.github/workflows/self-hosted.yml @@ -0,0 +1,102 @@ +name: Self-Hosted + +on: + push: + branches: + - main + - release + - pre-release + paths: + - '.github/**' + - 'deps/**' + - 'include/**' + - 'src/**' + - 'tests/**' + - 'examples/**' + - 'python/**' + - '.gitignore' + - '.gitmodules' + - 'CMakeLists.txt' + pull_request: + branches: [ main, pocl-support ] + +env: + build-dir: "build" + +jobs: + build: + name: Build ${{ matrix.os }} + runs-on: self-hosted + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-24.04 + env: + config: "Release" + nt: "4" + + steps: + - uses: actions/checkout@v5 + with: + submodules: true + fetch-depth: 0 + + - name: Configure CMake + run: | + cmake . -G Ninja \ + -B ${{ env.build-dir }} \ + -DCMAKE_BUILD_TYPE=${{ env.config }} \ + -DSPLA_BUILD_TESTS=ON + + - name: Build library sources + run: | + cmake --build ${{ env.build-dir }} \ + --target all \ + --verbose \ + -j ${{ env.nt }} + + test: + name: Test GPU ${{ matrix.gpu }} + needs: build + runs-on: self-hosted + strategy: + fail-fast: false + matrix: + include: + - gpu: Intel-Core-i7-4790 + platform: 0 + device: 0 + + env: + test-file: ${{ matrix.gpu }}_tests.log + + steps: + - name: Run tests + run: | + python3 ./run_tests.py --build-dir=${{ env.build-dir }} \ + --platform=${{ matrix.platform }} \ + --device=${{ matrix.device }} \ + | tee ${{ env.test-file }} + + - name: Upload tests resutls + uses: actions/upload-artifact@v4 + with: + name: ${{ env.test-file }} + path: ${{ env.test-file }} + + - name: Check for tests results + run: | + ! grep -qi "FAILED" ${{ env.test-file }} + + clean: + name: Cleanup workspace + needs: test + if: always() + runs-on: self-hosted + + steps: + - name: Cleanup workspace + run: | + rm -rf ${{ github.workspace }}/* + rm -rf ${{ github.workspace }}/.* diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml new file mode 100644 index 000000000..6828c3d40 --- /dev/null +++ b/.github/workflows/ubuntu.yml @@ -0,0 +1,109 @@ +name: Ubuntu + +on: + push: + branches: + - main + - release + - pre-release + paths: + - '.github/**' + - 'deps/**' + - 'include/**' + - 'src/**' + - 'tests/**' + - 'examples/**' + - 'python/**' + - '.gitignore' + - '.gitmodules' + - 'CMakeLists.txt' + pull_request: + branches: [ main ] + +env: + build-dir: "build" + config: "Release" + artifact: "spla-ubuntu-build.tar.xz" + nt: "4" + +jobs: + build: + name: Build ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-24.04 + steps: + - uses: actions/checkout@v5 + with: + submodules: true + fetch-depth: 0 + + - uses: seanmiddleditch/gha-setup-ninja@master + + - name: Configure CMake + run: | + cmake . -G Ninja \ + -B ${{ env.build-dir }} \ + -DCMAKE_BUILD_TYPE=${{ env.config }} \ + -DSPLA_BUILD_TESTS=ON \ + -DSPLA_BUILD_OPENCL=OFF + + - name: Build library sources + run: | + cmake --build ${{ env.build-dir }} --verbose -j ${{ env.nt }} + + - name: Prepare upload binary + run: | + tar cfz ${{ env.artifact }} ${{ env.build-dir }} + + - name: Upload binary + uses: actions/upload-artifact@v4 + with: + name: ${{env.artifact}} + path: ${{env.artifact}} + + test: + name: Test CPU ${{ matrix.cpu }} + needs: build + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-24.04 + cpu: AMD-EPYC-7763 + + env: + test-file: cpu_tests.log + + steps: + - uses: actions/checkout@v5 + with: + submodules: true + fetch-depth: 0 + + - uses: actions/download-artifact@v5 + with: + name: ${{ env.artifact }} + + - name: Unarchive artifact + run: | + tar xzf ${{ env.artifact }} + rm ${{ env.artifact }} + + - name: Run tests + run: | + python3 ./run_tests.py --build-dir=${{ env.build-dir }} | tee ${{ env.test-file }} + + - name: Upload tests resutls + uses: actions/upload-artifact@v4 + with: + name: ${{ env.test-file }} + path: ${{ env.test-file }} + + - name: Check for tests results + run: | + ! grep -qi "FAILED" ${{ env.test-file }} diff --git a/run_tests.py b/run_tests.py index ad738fdea..0e8befbc2 100644 --- a/run_tests.py +++ b/run_tests.py @@ -29,6 +29,7 @@ import argparse import subprocess import re +import os def test_names(test_src_path): @@ -41,18 +42,30 @@ def test_names(test_src_path): def main(): parser = argparse.ArgumentParser() parser.add_argument("--build-dir", default="build") + parser.add_argument("--platform", default="0") + parser.add_argument("--device", default="0") args = parser.parse_args() + spla_opencl_platform = "SPLA_OPENCL_PLATFORM" + spla_opencl_device = "SPLA_OPENCL_DEVICE" + + os.environ[spla_opencl_platform] = args.platform + os.environ[spla_opencl_device] = args.device + tests_dir = shared.ROOT / args.build_dir / "tests" print(f"Searching for unit-tests in `{tests_dir}` folder") failed_tests = [] + skipped_tests = [] all_tests = test_names(shared.ROOT / "tests") for test_name in all_tests: full_test_name = str(tests_dir / test_name) - print(f"Exec unit-test: `{full_test_name}`") try: subprocess.check_call(full_test_name) + print(f"Exec unit-test: `{full_test_name}`") + except FileNotFoundError: + skipped_tests.append(test_name) + print(f"Skipped: `{full_test_name}`") except subprocess.CalledProcessError as err: failed_tests.append(test_name) print(f"Failed: `{err.output}`") @@ -60,10 +73,14 @@ def main(): all_tests_string = '\n\t'.join(all_tests) print(f"All executed tests: \n\t{all_tests_string}") + if skipped_tests: + skipped_tests_string = '\n\t'.join(skipped_tests) + print(f"Skipped tests: \n\t{skipped_tests_string}") + if failed_tests: failed_tests_string = '\n\t'.join(failed_tests) raise Exception(f"Some tests have not been passed: \n\t{failed_tests_string}") if __name__ == "__main__": - main() + main() \ No newline at end of file diff --git a/src/opencl/cl_accelerator.cpp b/src/opencl/cl_accelerator.cpp index 6c3d588b3..d91291f55 100644 --- a/src/opencl/cl_accelerator.cpp +++ b/src/opencl/cl_accelerator.cpp @@ -42,10 +42,15 @@ namespace spla { Status CLAccelerator::init() { m_description = "no platform or device"; - if (set_platform(0) != Status::Ok) + const char* spla_opencl_platform = std::getenv(SPLA_OPENCL_PLATFORM); + const char* spla_opencl_device = std::getenv(SPLA_OPENCL_DEVICE); + int platform_index = (spla_opencl_platform ? std::atoi(spla_opencl_platform) : 0); + int device_index = (spla_opencl_device ? std::atoi(spla_opencl_device) : 0); + + if (set_platform(platform_index) != Status::Ok) return Status::PlatformNotFound; - if (set_device(0) != Status::Ok) + if (set_device(device_index) != Status::Ok) return Status::DeviceNotFound; if (set_queues_count(1) != Status::Ok) @@ -111,9 +116,14 @@ namespace spla { m_is_intel = false; m_is_img = false; - auto dev_type = m_device.getInfo(); + auto dev_type = m_device.getInfo(); + auto m_platform_name = m_platform.getInfo(); - if (m_vendor_id == 0x10006 && + if ((m_vendor_id == 65542 || + m_vendor_name.find("pocl") != std::string::npos || + m_vendor_name.find("POCL") != std::string::npos || + m_vendor_name.find("PoCL") != std::string::npos || + m_platform_name.find("Portable Computing Language") != std::string::npos) && dev_type == CL_DEVICE_TYPE_CPU) { m_vendor_code = VENDOR_CODE_POCL_CPU; m_default_wgs = 64; diff --git a/src/opencl/cl_accelerator.hpp b/src/opencl/cl_accelerator.hpp index d9741d1f9..d809398c3 100644 --- a/src/opencl/cl_accelerator.hpp +++ b/src/opencl/cl_accelerator.hpp @@ -52,6 +52,9 @@ #define VENDOR_CODE_IMG "img" #define VENDOR_CODE_POCL_CPU "pocl_cpu" +#define SPLA_OPENCL_PLATFORM "SPLA_OPENCL_PLATFORM" +#define SPLA_OPENCL_DEVICE "SPLA_OPENCL_DEVICE" + namespace spla { /** @@ -99,6 +102,7 @@ namespace spla { [[nodiscard]] bool is_amd() const { return m_is_amd; } [[nodiscard]] bool is_intel() const { return m_is_intel; } [[nodiscard]] bool is_img() const { return m_is_img; } + [[nodiscard]] bool is_pocl() const { return m_is_pocl; } private: cl::Platform m_platform; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d642b2fe0..e20657a89 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -15,7 +15,9 @@ spla_test_target(test_mxmT) spla_test_target(test_mxv) spla_test_target(test_vxm) spla_test_target(test_op) -spla_test_target(test_opencl) -spla_test_target(test_opencl_merge) +if (SPLA_BUILD_OPENCL) + spla_test_target(test_opencl) + spla_test_target(test_opencl_merge) +endif () spla_test_target(test_schedule) -spla_test_target(test_vector) +spla_test_target(test_vector) \ No newline at end of file diff --git a/tests/test_array.cpp b/tests/test_array.cpp index 51278a5dc..31f6c131a 100644 --- a/tests/test_array.cpp +++ b/tests/test_array.cpp @@ -99,4 +99,4 @@ TEST(array, read) { } } -SPLA_GTEST_MAIN \ No newline at end of file +SPLA_GTEST_MAIN diff --git a/tests/test_kron.cpp b/tests/test_kron.cpp index 22040d795..e0839b605 100644 --- a/tests/test_kron.cpp +++ b/tests/test_kron.cpp @@ -92,4 +92,4 @@ TEST(kron, naive) { } } -SPLA_GTEST_MAIN_WITH_FINALIZE_PLATFORM(1) +SPLA_GTEST_MAIN diff --git a/tests/test_library.cpp b/tests/test_library.cpp index 7eba89e93..114f8db1b 100644 --- a/tests/test_library.cpp +++ b/tests/test_library.cpp @@ -66,4 +66,4 @@ TEST(library, default_accelerator_info) { std::cout << "Info: " << acc_info << std::endl; } -SPLA_GTEST_MAIN \ No newline at end of file +SPLA_GTEST_MAIN diff --git a/tests/test_matrix.cpp b/tests/test_matrix.cpp index 2246b38e9..14ecc4e17 100644 --- a/tests/test_matrix.cpp +++ b/tests/test_matrix.cpp @@ -271,4 +271,4 @@ TEST(matrix, emult) { } } -SPLA_GTEST_MAIN_WITH_FINALIZE \ No newline at end of file +SPLA_GTEST_MAIN_WITH_FINALIZE diff --git a/tests/test_mxm.cpp b/tests/test_mxm.cpp index 879415cd4..b727975ab 100644 --- a/tests/test_mxm.cpp +++ b/tests/test_mxm.cpp @@ -129,4 +129,4 @@ TEST(mxm, perf_zero) { } } -SPLA_GTEST_MAIN_WITH_FINALIZE_PLATFORM(1) +SPLA_GTEST_MAIN diff --git a/tests/test_mxmT.cpp b/tests/test_mxmT.cpp index 64c05b6dc..2fa385494 100644 --- a/tests/test_mxmT.cpp +++ b/tests/test_mxmT.cpp @@ -140,4 +140,4 @@ TEST(mxmT_masked, perf_zero) { } -SPLA_GTEST_MAIN_WITH_FINALIZE_PLATFORM(1) \ No newline at end of file +SPLA_GTEST_MAIN diff --git a/tests/test_mxv.cpp b/tests/test_mxv.cpp index 9c1c6de29..611c4c404 100644 --- a/tests/test_mxv.cpp +++ b/tests/test_mxv.cpp @@ -129,4 +129,4 @@ TEST(mxv_masked, perf) { std::cout << std::endl; } -SPLA_GTEST_MAIN_WITH_FINALIZE_PLATFORM(1) \ No newline at end of file +SPLA_GTEST_MAIN diff --git a/tests/test_op.cpp b/tests/test_op.cpp index c439c29a5..a1d915891 100644 --- a/tests/test_op.cpp +++ b/tests/test_op.cpp @@ -61,4 +61,4 @@ TEST(op_binary, custom) { display_op_info(custom_plus); } -SPLA_GTEST_MAIN_WITH_FINALIZE \ No newline at end of file +SPLA_GTEST_MAIN_WITH_FINALIZE diff --git a/tests/test_opencl.cpp b/tests/test_opencl.cpp index 7b8d6a384..14d0799a5 100644 --- a/tests/test_opencl.cpp +++ b/tests/test_opencl.cpp @@ -31,6 +31,8 @@ #define CL_HPP_MINIMUM_OPENCL_VERSION 120 #define CL_HPP_TARGET_OPENCL_VERSION 120 #define CL_HPP_ENABLE_EXCEPTIONS +#define SPLA_OPENCL_PLATFORM "SPLA_OPENCL_PLATFORM" +#define SPLA_OPENCL_DEVICE "SPLA_OPENCL_DEVICE" #include #include @@ -44,14 +46,21 @@ TEST(opencl, basic) { if (platforms.empty()) { GTEST_SKIP() << "No platforms found"; } - cl::Platform platform = platforms.front(); + + const char* spla_opencl_platform = std::getenv(SPLA_OPENCL_PLATFORM); + int platform_index = (spla_opencl_platform ? std::atoi(spla_opencl_platform) : 0); + + cl::Platform platform = platforms[platform_index]; std::vector devices; platform.getDevices(CL_DEVICE_TYPE_ALL, &devices); if (devices.empty()) { GTEST_SKIP() << "No devices found"; } - cl::Device device = devices.front(); + + const char* spla_opencl_device = std::getenv(SPLA_OPENCL_DEVICE); + int device_index = (spla_opencl_device ? std::atoi(spla_opencl_device) : 0); + cl::Device device = devices[device_index]; cl::Context context(device); cl::CommandQueue queue(context); @@ -97,14 +106,21 @@ TEST(opencl, bitonic_sort_local) { if (platforms.empty()) { GTEST_SKIP() << "No platforms found"; } - cl::Platform platform = platforms.front(); + + const char* spla_opencl_platform = std::getenv(SPLA_OPENCL_PLATFORM); + int platform_index = (spla_opencl_platform ? std::atoi(spla_opencl_platform) : 0); + + cl::Platform platform = platforms[platform_index]; std::vector devices; platform.getDevices(CL_DEVICE_TYPE_ALL, &devices); if (devices.empty()) { GTEST_SKIP() << "No devices found"; } - cl::Device device = devices.front(); + + const char* spla_opencl_device = std::getenv(SPLA_OPENCL_DEVICE); + int device_index = (spla_opencl_device ? std::atoi(spla_opencl_device) : 0); + cl::Device device = devices[device_index]; cl::Context context(device); cl::CommandQueue queue(context); @@ -153,14 +169,21 @@ TEST(opencl, bitonic_sort_global) { if (platforms.empty()) { GTEST_SKIP() << "No platforms found"; } - cl::Platform platform = platforms.front(); + + const char* spla_opencl_platform = std::getenv(SPLA_OPENCL_PLATFORM); + int platform_index = (spla_opencl_platform ? std::atoi(spla_opencl_platform) : 0); + + cl::Platform platform = platforms[platform_index]; std::vector devices; platform.getDevices(CL_DEVICE_TYPE_ALL, &devices); if (devices.empty()) { GTEST_SKIP() << "No devices found"; } - cl::Device device = devices.front(); + + const char* spla_opencl_device = std::getenv(SPLA_OPENCL_DEVICE); + int device_index = (spla_opencl_device ? std::atoi(spla_opencl_device) : 0); + cl::Device device = devices[device_index]; cl::Context context(device); cl::CommandQueue queue(context); @@ -210,14 +233,21 @@ TEST(opencl, custom_value) { if (platforms.empty()) { GTEST_SKIP() << "No platforms found"; } - cl::Platform platform = platforms.front(); + + const char* spla_opencl_platform = std::getenv(SPLA_OPENCL_PLATFORM); + int platform_index = (spla_opencl_platform ? std::atoi(spla_opencl_platform) : 0); + + cl::Platform platform = platforms[platform_index]; std::vector devices; platform.getDevices(CL_DEVICE_TYPE_ALL, &devices); if (devices.empty()) { GTEST_SKIP() << "No devices found"; } - cl::Device device = devices.front(); + + const char* spla_opencl_device = std::getenv(SPLA_OPENCL_DEVICE); + int device_index = (spla_opencl_device ? std::atoi(spla_opencl_device) : 0); + cl::Device device = devices[device_index]; cl::Context context(device); cl::CommandQueue queue(context); @@ -264,14 +294,21 @@ TEST(opencl, reduce_by_key_small) { if (platforms.empty()) { GTEST_SKIP() << "No platforms found"; } - cl::Platform platform = platforms.front(); + + const char* spla_opencl_platform = std::getenv(SPLA_OPENCL_PLATFORM); + int platform_index = (spla_opencl_platform ? std::atoi(spla_opencl_platform) : 0); + + cl::Platform platform = platforms[platform_index]; std::vector devices; platform.getDevices(CL_DEVICE_TYPE_ALL, &devices); if (devices.empty()) { GTEST_SKIP() << "No devices found"; } - cl::Device device = devices.front(); + + const char* spla_opencl_device = std::getenv(SPLA_OPENCL_DEVICE); + int device_index = (spla_opencl_device ? std::atoi(spla_opencl_device) : 0); + cl::Device device = devices[device_index]; cl::Context context(device); cl::CommandQueue queue(context, CL_QUEUE_PROFILING_ENABLE); diff --git a/tests/test_opencl_merge.cpp b/tests/test_opencl_merge.cpp index 9761de9aa..40e8d96f2 100644 --- a/tests/test_opencl_merge.cpp +++ b/tests/test_opencl_merge.cpp @@ -30,6 +30,8 @@ #define CL_HPP_MINIMUM_OPENCL_VERSION 120 #define CL_HPP_TARGET_OPENCL_VERSION 120 #define CL_HPP_ENABLE_EXCEPTIONS +#define SPLA_OPENCL_PLATFORM "SPLA_OPENCL_PLATFORM" +#define SPLA_OPENCL_DEVICE "SPLA_OPENCL_DEVICE" #include #include @@ -415,7 +417,11 @@ TEST(opencl_merge, merge_path_v1) { if (platforms.empty()) { GTEST_SKIP() << "No platforms found"; } - cl::Platform platform = platforms.back(); + + const char* spla_opencl_platform = std::getenv(SPLA_OPENCL_PLATFORM); + int platform_index = (spla_opencl_platform ? std::atoi(spla_opencl_platform) : 0); + + cl::Platform platform = platforms[platform_index]; std::cout << "Platforms: " << std::endl; for (auto& it : platforms) { @@ -429,7 +435,10 @@ TEST(opencl_merge, merge_path_v1) { if (devices.empty()) { GTEST_SKIP() << "No devices found"; } - cl::Device device = devices[0]; + + const char* spla_opencl_device = std::getenv(SPLA_OPENCL_DEVICE); + int device_index = (spla_opencl_device ? std::atoi(spla_opencl_device) : 0); + cl::Device device = devices[device_index]; std::cout << "Devices: " << std::endl; for (auto& it : devices) { @@ -511,7 +520,11 @@ TEST(opencl_merge, merge_path_v2) { if (platforms.empty()) { GTEST_SKIP() << "No platforms found"; } - cl::Platform platform = platforms.back(); + + const char* spla_opencl_platform = std::getenv(SPLA_OPENCL_PLATFORM); + int platform_index = (spla_opencl_platform ? std::atoi(spla_opencl_platform) : 0); + + cl::Platform platform = platforms[platform_index]; std::cout << "Platforms: " << std::endl; for (auto& it : platforms) { @@ -525,7 +538,10 @@ TEST(opencl_merge, merge_path_v2) { if (devices.empty()) { GTEST_SKIP() << "No devices found"; } - cl::Device device = devices[0]; + + const char* spla_opencl_device = std::getenv(SPLA_OPENCL_DEVICE); + int device_index = (spla_opencl_device ? std::atoi(spla_opencl_device) : 0); + cl::Device device = devices[device_index]; std::cout << "Devices: " << std::endl; for (auto& it : devices) { diff --git a/tests/test_schedule.cpp b/tests/test_schedule.cpp index 15d9b7f63..cb978910f 100644 --- a/tests/test_schedule.cpp +++ b/tests/test_schedule.cpp @@ -37,4 +37,4 @@ TEST(schedule, task_callback) { schedule->submit(); } -SPLA_GTEST_MAIN_WITH_FINALIZE \ No newline at end of file +SPLA_GTEST_MAIN_WITH_FINALIZE diff --git a/tests/test_vector.cpp b/tests/test_vector.cpp index 22763c5a2..4bd310b43 100644 --- a/tests/test_vector.cpp +++ b/tests/test_vector.cpp @@ -497,4 +497,4 @@ TEST(vector, map) { } } -SPLA_GTEST_MAIN_WITH_FINALIZE_PLATFORM(1) +SPLA_GTEST_MAIN diff --git a/tests/test_vxm.cpp b/tests/test_vxm.cpp index 14394b55c..615aa8c30 100644 --- a/tests/test_vxm.cpp +++ b/tests/test_vxm.cpp @@ -186,4 +186,4 @@ TEST(vxm_masked, perf_and_or) { std::cout << std::endl; } -SPLA_GTEST_MAIN_WITH_FINALIZE_PLATFORM(1) \ No newline at end of file +SPLA_GTEST_MAIN