diff --git a/CMakeLists.txt b/CMakeLists.txt index 736d516fa1f6..119bf8325c8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -638,18 +638,6 @@ if(BUILD_FOR_HEXAGON AND DEFINED USE_HEXAGON_GTEST AND EXISTS ${USE_HEXAGON_GTES include_directories("${USE_HEXAGON_GTEST}/include") endif() -if(USE_OPENCL AND DEFINED USE_OPENCL_GTEST AND EXISTS ${USE_OPENCL_GTEST}) - include(FetchContent) - FetchContent_Declare(googletest SOURCE_DIR "${USE_OPENCL_GTEST}") - set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - FetchContent_MakeAvailable(googletest) - target_link_libraries(tvm_runtime PUBLIC gtest) - target_link_libraries(tvm PUBLIC gtest) - include_directories("${USE_OPENCL_GTEST}/include") - include_directories("${USE_OPENCL_GTEST}/googletest/include") - message(STATUS "Found OpenCL gtest at ${USE_OPENCL_GTEST}") -endif() - # Set flags for clang include(cmake/modules/ClangFlags.cmake) set(CRC16_INCLUDE_PATH "3rdparty/libcrc/include") @@ -715,9 +703,6 @@ install(TARGETS tvm_runtime EXPORT ${PROJECT_NAME}Targets DESTINATION lib${LIB_S if(BUILD_FOR_HEXAGON AND DEFINED USE_HEXAGON_GTEST AND EXISTS ${USE_HEXAGON_GTEST}) install(TARGETS gtest EXPORT ${PROJECT_NAME}Targets DESTINATION lib${LIB_SUFFIX}) endif() -if(USE_OPENCL AND DEFINED USE_OPENCL_GTEST AND EXISTS ${USE_OPENCL_GTEST}) - install(TARGETS gtest EXPORT ${PROJECT_NAME}Targets DESTINATION lib${LIB_SUFFIX}) -endif() if (INSTALL_DEV) install( diff --git a/ci/jenkins/docker-images.ini b/ci/jenkins/docker-images.ini index 119a43218642..40e1b8a1313f 100644 --- a/ci/jenkins/docker-images.ini +++ b/ci/jenkins/docker-images.ini @@ -20,7 +20,7 @@ ci_arm: tlcpack/ci-arm:20221013-060115-61c9742ea ci_cortexm: tlcpack/ci-cortexm:20221013-060115-61c9742ea ci_cpu: tlcpack/ci-cpu:20221013-060115-61c9742ea -ci_gpu: tlcpack/ci-gpu:20221019-060125-0b4836739 +ci_gpu: tlcpack/ci-gpu:20221128-070141-ae4fd7df7 ci_hexagon: tlcpack/ci-hexagon:20221013-060115-61c9742ea ci_i386: tlcpack/ci-i386:20221013-060115-61c9742ea ci_lint: tlcpack/ci-lint:20221013-060115-61c9742ea diff --git a/ci/jenkins/generated/gpu_jenkinsfile.groovy b/ci/jenkins/generated/gpu_jenkinsfile.groovy index 48a6619cbab1..3c9dbbc1477c 100644 --- a/ci/jenkins/generated/gpu_jenkinsfile.groovy +++ b/ci/jenkins/generated/gpu_jenkinsfile.groovy @@ -574,6 +574,14 @@ def shard_run_unittest_GPU_1_of_3() { make_standalone_crt(ci_gpu, 'build') make_cpp_tests(ci_gpu, 'build') cpp_unittest(ci_gpu) + sh ( + script: "${docker_run} ${ci_gpu} python3 ./tests/scripts/task_build.py --sccache-bucket tvm-sccache-prod --cmake-target opencl-cpptest --build-dir build", + label: 'Make OpenCL cpp unit tests', + ) + sh ( + script: "${docker_run} ${ci_gpu} ./tests/scripts/task_opencl_cpp_unittest.sh", + label: 'Run OpenCL cpp unit tests', + ) micro_cpp_unittest(ci_gpu) sh ( script: "${docker_run} ${ci_gpu} ./tests/scripts/task_python_unittest_gpuonly.sh", diff --git a/ci/jenkins/templates/gpu_jenkinsfile.groovy.j2 b/ci/jenkins/templates/gpu_jenkinsfile.groovy.j2 index 2a9e7236d26d..40698131a783 100644 --- a/ci/jenkins/templates/gpu_jenkinsfile.groovy.j2 +++ b/ci/jenkins/templates/gpu_jenkinsfile.groovy.j2 @@ -63,6 +63,14 @@ make_standalone_crt(ci_gpu, 'build') make_cpp_tests(ci_gpu, 'build') cpp_unittest(ci_gpu) + sh ( + script: "${docker_run} ${ci_gpu} python3 ./tests/scripts/task_build.py --sccache-bucket tvm-sccache-prod --cmake-target opencl-cpptest --build-dir build", + label: 'Make OpenCL cpp unit tests', + ) + sh ( + script: "${docker_run} ${ci_gpu} ./tests/scripts/task_opencl_cpp_unittest.sh", + label: 'Run OpenCL cpp unit tests', + ) micro_cpp_unittest(ci_gpu) {% else %} {{ m.download_artifacts(tag='gpu') }} diff --git a/cmake/modules/OpenCL.cmake b/cmake/modules/OpenCL.cmake index e738df7c564c..1e1041efe386 100644 --- a/cmake/modules/OpenCL.cmake +++ b/cmake/modules/OpenCL.cmake @@ -59,9 +59,19 @@ if(USE_OPENCL) endif() if(DEFINED USE_OPENCL_GTEST AND EXISTS ${USE_OPENCL_GTEST}) - file_glob_append(RUNTIME_OPENCL_SRCS + include(FetchContent) + FetchContent_Declare(googletest SOURCE_DIR "${USE_OPENCL_GTEST}") + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + FetchContent_MakeAvailable(googletest) + install(TARGETS gtest EXPORT ${PROJECT_NAME}Targets DESTINATION lib${LIB_SUFFIX}) + + message(STATUS "Found OpenCL gtest at ${USE_OPENCL_GTEST}") + + tvm_file_glob(GLOB_RECURSE OPENCL_TEST_SRCS "${CMAKE_SOURCE_DIR}/tests/cpp-runtime/opencl/*.cc" ) + add_executable(opencl-cpptest ${OPENCL_TEST_SRCS}) + target_link_libraries(opencl-cpptest PRIVATE gtest_main tvm_runtime) endif() list(APPEND RUNTIME_SRCS ${RUNTIME_OPENCL_SRCS}) else() diff --git a/tests/cpp-runtime/opencl/run_gtests.cc b/tests/cpp-runtime/opencl/run_gtests.cc deleted file mode 100644 index ffe86a7f52c0..000000000000 --- a/tests/cpp-runtime/opencl/run_gtests.cc +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#include -#include -#include - -#include -#include - -#include "../src/support/utils.h" - -namespace tvm { -namespace runtime { -namespace cl { - -TVM_REGISTER_GLOBAL("opencl.run_gtests").set_body([](TVMArgs args, TVMRetValue* rv) { - // gtest args are passed into this packed func as a singular string - // split gtest args using delimiter and build argument vector - std::vector parsed_args = tvm::support::Split(args[0], ' '); - std::vector argv; - - // add executable name - argv.push_back(const_cast("opencl_run_gtests")); - - // add parsed arguments - for (size_t i = 0; i < parsed_args.size(); ++i) { - argv.push_back(const_cast(parsed_args[i].data())); - } - - // end of parsed arguments - argv.push_back(nullptr); - - // set argument count - int argc = argv.size() - 1; - - // initialize gtest with arguments and run - ::testing::InitGoogleTest(&argc, argv.data()); - *rv = RUN_ALL_TESTS(); -}); - -} // namespace cl -} // namespace runtime -} // namespace tvm diff --git a/tests/python/contrib/test_opencl/test_run_gtests.py b/tests/python/contrib/test_opencl/test_run_gtests.py deleted file mode 100644 index ee59086b25f1..000000000000 --- a/tests/python/contrib/test_opencl/test_run_gtests.py +++ /dev/null @@ -1,56 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -import os -import pytest -import numpy as np - -import tvm -from tvm import rpc - - -# use pytest -sv to observe gtest output -# use --gtest_args to pass arguments to gtest -# for example to run all "foo" tests twice and observe gtest output run -# pytest -sv --gtests_args="--gtest_filter=*foo* --gtest_repeat=2" -@tvm.testing.requires_opencl -@pytest.mark.skipif(tvm.testing.utils.IS_IN_CI, reason="failed due to nvidia libOpencl in the CI") -def test_run_gtests(gtest_args): - if ( - "TVM_TRACKER_HOST" in os.environ - and "TVM_TRACKER_PORT" in os.environ - and "TVM_TRACKER_KEY" in os.environ - ): - rpc_tracker_host = os.environ["TVM_TRACKER_HOST"] - rpc_tracker_port = os.environ["TVM_TRACKER_PORT"] - rpc_tracker_port = int(rpc_tracker_port) - rpc_key = os.environ["TVM_TRACKER_KEY"] - tracker = rpc.connect_tracker(rpc_tracker_host, rpc_tracker_port) - rpc_connection = tracker.request(rpc_key, priority=0, session_timeout=600) - else: - rpc_connection = rpc.LocalSession() - - try: - func = rpc_connection.get_function("opencl.run_gtests") - except: - print( - "This test requires TVM Runtime to be built with a OpenCL gtest version using OpenCL API cmake flag -DUSE_OPENCL_GTEST=/path/to/opencl/googletest/gtest" - ) - raise - - gtest_error_code = func(gtest_args) - np.testing.assert_equal(gtest_error_code, 0) diff --git a/tests/scripts/ci.py b/tests/scripts/ci.py index 6799f68d43b7..b11ee538dc68 100755 --- a/tests/scripts/ci.py +++ b/tests/scripts/ci.py @@ -593,6 +593,7 @@ def add_subparser( "run unit tests", [ "./tests/scripts/task_java_unittest.sh", + "./tests/scripts/task_opencl_cpp_unittest.sh", "./tests/scripts/task_python_unittest_gpuonly.sh", "./tests/scripts/task_python_integration_gpuonly.sh", ], diff --git a/tests/scripts/task_config_build_gpu.sh b/tests/scripts/task_config_build_gpu.sh index ca5f3e935c08..90c91fb990be 100755 --- a/tests/scripts/task_config_build_gpu.sh +++ b/tests/scripts/task_config_build_gpu.sh @@ -29,6 +29,7 @@ echo set\(USE_CUDA ON\) >> config.cmake echo set\(USE_VULKAN ON\) >> config.cmake echo set\(USE_OPENGL ON\) >> config.cmake echo set\(USE_OPENCL ON\) >> config.cmake +echo set\(USE_OPENCL_GTEST \"/googletest\"\) >> config.cmake echo set\(USE_MICRO ON\) >> config.cmake echo set\(USE_MICRO_STANDALONE_RUNTIME ON\) >> config.cmake echo set\(USE_LLVM \"/usr/bin/llvm-config-9 --link-static\"\) >> config.cmake diff --git a/tests/scripts/task_opencl_cpp_unittest.sh b/tests/scripts/task_opencl_cpp_unittest.sh new file mode 100755 index 000000000000..7ea6ea470db7 --- /dev/null +++ b/tests/scripts/task_opencl_cpp_unittest.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +set -euxo pipefail + +if [ $# -gt 0 ]; then + BUILD_DIR="$1" +elif [ -n "${TVM_BUILD_PATH:-}" ]; then + # TVM_BUILD_PATH may contain multiple space-separated paths. If + # so, use the first one. + BUILD_DIR=$(IFS=" "; set -- $TVM_BUILD_PATH; echo $1) +else + BUILD_DIR=build +fi + + +# to avoid CI thread throttling. +export TVM_BIND_THREADS=0 +export OMP_NUM_THREADS=1 + +pushd "${BUILD_DIR}" +# run cpp test executable +./opencl-cpptest +popd