diff --git a/sycl/unittests/pi/CMakeLists.txt b/sycl/unittests/pi/CMakeLists.txt index 0c78c9a634010..861fc41069c7e 100644 --- a/sycl/unittests/pi/CMakeLists.txt +++ b/sycl/unittests/pi/CMakeLists.txt @@ -1,9 +1,7 @@ set(CMAKE_CXX_EXTENSIONS OFF) add_sycl_unittest(PiTests OBJECT - EnqueueMemTest.cpp PiMock.cpp - PlatformTest.cpp PiUtility.cpp pi_arguments_handler.cpp piInteropRetain.cpp @@ -13,11 +11,3 @@ add_dependencies(PiTests sycl) target_include_directories(PiTests PRIVATE SYSTEM ${sycl_inc_dir}) target_include_directories(PiTests PRIVATE ${sycl_src_dir}/../tools/xpti_helpers) -if("cuda" IN_LIST SYCL_ENABLE_PLUGINS) - add_subdirectory(cuda) -endif() - -if("hip" IN_LIST SYCL_ENABLE_PLUGINS) - add_subdirectory(hip) -endif() - diff --git a/sycl/unittests/pi/EnqueueMemTest.cpp b/sycl/unittests/pi/EnqueueMemTest.cpp deleted file mode 100644 index d6439654f7bbb..0000000000000 --- a/sycl/unittests/pi/EnqueueMemTest.cpp +++ /dev/null @@ -1,152 +0,0 @@ -//==---- EnqueueMemTest.cpp --- PI unit tests ------------------------------==// -// -// Part of the LLVM Project, 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 "TestGetPlugin.hpp" -#include -#include -#include - -using namespace sycl; - -namespace { -class EnqueueMemTest : public testing::TestWithParam { -protected: - constexpr static size_t _numElementsX = 8; - constexpr static size_t _numElementsY = 4; - - pi_device _device = nullptr; - pi_context _context = nullptr; - pi_queue _queue = nullptr; - pi_mem _mem = nullptr; - - EnqueueMemTest() = default; - - ~EnqueueMemTest() = default; - - void SetUp() override { - - const detail::PluginPtr &plugin = GetParam(); - - pi_platform platform = nullptr; - ASSERT_EQ((plugin->call_nocheck( - 1, &platform, nullptr)), - PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - platform, PI_DEVICE_TYPE_DEFAULT, 1, &_device, nullptr)), - PI_SUCCESS); - - pi_result result = PI_ERROR_INVALID_VALUE; - result = plugin->call_nocheck( - nullptr, 1u, &_device, nullptr, nullptr, &_context); - ASSERT_EQ(result, PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - _context, _device, 0, &_queue)), - PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - _context, PI_MEM_FLAGS_ACCESS_RW, - _numElementsX * _numElementsY * sizeof(pi_int32), nullptr, - &_mem, nullptr)), - PI_SUCCESS); - } - - void TearDown() override { - - const detail::PluginPtr &plugin = GetParam(); - - ASSERT_EQ((plugin->call_nocheck(_mem)), - PI_SUCCESS); - ASSERT_EQ((plugin->call_nocheck(_queue)), - PI_SUCCESS); - ASSERT_EQ( - (plugin->call_nocheck(_context)), - PI_SUCCESS); - } - - template void TestBufferFill(const T &pattern) { - - const detail::PluginPtr &plugin = GetParam(); - - T inValues[_numElementsX] = {}; - - for (size_t i = 0; i < _numElementsX; ++i) { - ASSERT_NE(pattern, inValues[i]); - } - - pi_event event; - ASSERT_EQ((plugin->call_nocheck( - _queue, _mem, PI_TRUE, 0, _numElementsX * sizeof(T), inValues, - 0, nullptr, &event)), - PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - _queue, _mem, &pattern, sizeof(T), 0, sizeof(inValues), 0, - nullptr, &event)), - PI_SUCCESS); - ASSERT_EQ( - (plugin->call_nocheck(1, &event)), - PI_SUCCESS); - - T outValues[_numElementsX] = {}; - ASSERT_EQ((plugin->call_nocheck( - _queue, _mem, PI_TRUE, 0, _numElementsX * sizeof(T), - outValues, 0, nullptr, &event)), - PI_SUCCESS); - - for (size_t i = 0; i < _numElementsX; ++i) { - ASSERT_EQ(pattern, outValues[i]); - } - } -}; - -INSTANTIATE_TEST_SUITE_P( - EnqueueMemTestImpl, EnqueueMemTest, - testing::ValuesIn(pi::initializeAndRemoveInvalid()), - [](const testing::TestParamInfo &info) { - return pi::GetBackendString(info.param); - }); - -template struct vec4 { - T x, y, z, w; - - bool operator==(const vec4 &rhs) const { - return x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w; - } - - bool operator!=(const vec4 &rhs) const { return !(*this == rhs); } -}; - -template struct vec2 { - T x, y; - - bool operator==(const vec2 &rhs) const { return x == rhs.x && y == rhs.y; } - - bool operator!=(const vec2 &rhs) const { return !(*this == rhs); } -}; - -TEST_P(EnqueueMemTest, piEnqueueMemBufferFill) { - - TestBufferFill(float{1}); - TestBufferFill(vec2{1, 2}); - TestBufferFill(vec4{1, 2, 3, 4}); - - TestBufferFill(uint8_t{1}); - TestBufferFill(vec2{1, 2}); - TestBufferFill(vec4{1, 2, 3, 4}); - - TestBufferFill(uint16_t{1}); - TestBufferFill(vec2{1, 2}); - TestBufferFill(vec4{1, 2, 3, 4}); - - TestBufferFill(uint32_t{1}); - TestBufferFill(vec2{1, 2}); - TestBufferFill(vec4{1, 2, 3, 4}); -} -} // namespace diff --git a/sycl/unittests/pi/PlatformTest.cpp b/sycl/unittests/pi/PlatformTest.cpp deleted file mode 100644 index 61834dbb14fff..0000000000000 --- a/sycl/unittests/pi/PlatformTest.cpp +++ /dev/null @@ -1,113 +0,0 @@ -//==---- PlatformTest.cpp --- PI unit tests --------------------------------==// -// -// Part of the LLVM Project, 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 "TestGetPlugin.hpp" -#include -#include -#include -#include -#include - -namespace { - -using namespace sycl; - -class PlatformTest : public testing::TestWithParam { -protected: - std::vector _platforms; - PlatformTest() : _platforms{} {}; - - ~PlatformTest() override = default; - - void SetUp() override { - - const detail::PluginPtr &plugin = GetParam(); - - ASSERT_NO_FATAL_FAILURE(Test::SetUp()); - - const static char *platform_count_key = "PiPlatformCount"; - - pi_uint32 platform_count = 0u; - - // Initialize the logged number of platforms before the following assertion. - RecordProperty(platform_count_key, platform_count); - - // TODO: Change the test to check this for all plugins present. - // Currently, it is only checking for the first plugin attached. - ASSERT_EQ((plugin->call_nocheck( - 0, nullptr, &platform_count)), - PI_SUCCESS); - - // Overwrite previous log value with queried number of platforms. - RecordProperty(platform_count_key, platform_count); - - if (platform_count == 0u) { - std::cout << "WARNING: piPlatformsGet does not find any PI platforms.\n"; - - // Do not call into OpenCL below as a platform count of 0 might fail with - // OpenCL implementations if the platforms pointer is not `nullptr`. - return; - } - - _platforms.resize(platform_count, nullptr); - - ASSERT_EQ((plugin->call_nocheck( - _platforms.size(), _platforms.data(), nullptr)), - PI_SUCCESS); - } -}; - -INSTANTIATE_TEST_SUITE_P( - PlatformTestImpl, PlatformTest, - testing::ValuesIn(pi::initializeAndRemoveInvalid()), - [](const testing::TestParamInfo &info) { - return pi::GetBackendString(info.param); - }); - -TEST_P(PlatformTest, piPlatformsGet) { - // The PlatformTest::SetUp method is called to prepare for this test case - // implicitly tests the calls to `piPlatformsGet`. -} - -TEST_P(PlatformTest, piPlatformGetInfo) { - - const detail::PluginPtr &plugin = GetParam(); - - auto get_info_test = [&](pi_platform platform, _pi_platform_info info) { - size_t reported_string_length = 0; - EXPECT_EQ((plugin->call_nocheck( - platform, info, 0u, nullptr, &reported_string_length)), - PI_SUCCESS); - - // Create a larger result string to catch overwrites. - std::vector param_value(reported_string_length * 2u, '\0'); - EXPECT_EQ( - (plugin->call_nocheck( - platform, info, param_value.size(), param_value.data(), nullptr)), - PI_SUCCESS) - << "piPlatformGetInfo for " << detail::pi::platformInfoToString(info) - << " failed.\n"; - - const auto returned_string_length = strlen(param_value.data()) + 1; - - EXPECT_EQ(returned_string_length, reported_string_length) - << "Returned string length " << returned_string_length - << " does not equal reported string length " << reported_string_length - << ".\n"; - }; - - for (const auto &platform : _platforms) { - get_info_test(platform, PI_PLATFORM_INFO_NAME); - get_info_test(platform, PI_PLATFORM_INFO_VENDOR); - get_info_test(platform, PI_PLATFORM_INFO_PROFILE); - get_info_test(platform, PI_PLATFORM_INFO_VERSION); - get_info_test(platform, PI_PLATFORM_INFO_EXTENSIONS); - get_info_test(platform, PI_EXT_PLATFORM_INFO_BACKEND); - } -} -} // namespace diff --git a/sycl/unittests/pi/cuda/CMakeLists.txt b/sycl/unittests/pi/cuda/CMakeLists.txt deleted file mode 100644 index 7808340cc4302..0000000000000 --- a/sycl/unittests/pi/cuda/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -add_sycl_unittest(PiCudaTests OBJECT - test_base_objects.cpp - test_commands.cpp - test_contexts.cpp - test_device.cpp - test_interop_get_native.cpp - test_kernels.cpp - test_mem_obj.cpp - test_primary_context.cpp - test_sampler_properties.cpp -) - -add_dependencies(PiCudaTests sycl) - -target_compile_definitions(PiCudaTests - PRIVATE - GTEST_HAS_COMBINE=1) - -target_include_directories(PiCudaTests - PRIVATE - "../" - "${sycl_inc_dir}/sycl/detail/" - "${sycl_inc_dir}" - "${sycl_plugin_dir}/cuda/" - "${sycl_plugin_dir}/unified_runtime/" -) - -target_link_libraries(PiCudaTests - PRIVATE - cudadrv - UnifiedRuntime-Headers -) diff --git a/sycl/unittests/pi/cuda/CudaUtils.hpp b/sycl/unittests/pi/cuda/CudaUtils.hpp deleted file mode 100644 index f7cb8b40492d3..0000000000000 --- a/sycl/unittests/pi/cuda/CudaUtils.hpp +++ /dev/null @@ -1,20 +0,0 @@ -// Part of the LLVM Project, 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 - -#pragma once - -#include - -namespace pi { - -// utility function to clear the CUDA context stack -inline void clearCudaContext() { - CUcontext ctxt = nullptr; - do { - cuCtxSetCurrent(nullptr); - cuCtxGetCurrent(&ctxt); - } while (ctxt != nullptr); -} - -} // namespace pi diff --git a/sycl/unittests/pi/cuda/test_base_objects.cpp b/sycl/unittests/pi/cuda/test_base_objects.cpp deleted file mode 100644 index d0799a08cfff3..0000000000000 --- a/sycl/unittests/pi/cuda/test_base_objects.cpp +++ /dev/null @@ -1,139 +0,0 @@ -//==---- test_base_objects.cpp --- PI unit tests ---------------------------==// -// -// Part of the LLVM Project, 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 "gtest/gtest.h" - -#include - -#include "TestGetPlugin.hpp" -#include -#include -#include -#include -#include - -#include - -const unsigned int LATEST_KNOWN_CUDA_DRIVER_API_VERSION = 3020u; - -using namespace sycl; - -class CudaBaseObjectsTest : public ::testing::Test { -protected: - std::optional &plugin = - pi::initializeAndGet(backend::ext_oneapi_cuda); - - void SetUp() override { - // skip the tests if the CUDA backend is not available - if (!plugin.has_value()) { - GTEST_SKIP(); - } - } - - CudaBaseObjectsTest() = default; - - ~CudaBaseObjectsTest() = default; -}; - -TEST_F(CudaBaseObjectsTest, piContextCreate) { - pi_uint32 numPlatforms = 0; - pi_platform platform = nullptr; - pi_device device; - ASSERT_EQ(plugin->hasBackend(backend::ext_oneapi_cuda), PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - 0, nullptr, &numPlatforms)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - numPlatforms, &platform, nullptr)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_GE(numPlatforms, 1u); - ASSERT_NE(platform, nullptr); - - ASSERT_EQ((plugin->call_nocheck( - platform, PI_DEVICE_TYPE_GPU, 1, &device, nullptr)), - PI_SUCCESS) - << "piDevicesGet failed.\n"; - - pi_context ctxt = nullptr; - ASSERT_EQ((plugin->call_nocheck( - nullptr, 1, &device, nullptr, nullptr, &ctxt)), - PI_SUCCESS) - << "piContextCreate failed.\n"; - - EXPECT_NE(ctxt, nullptr); - EXPECT_EQ(ctxt->get_device(), device); - - // Retrieve the cuCtxt to check information is correct - CUcontext cudaContext = ctxt->get(); - unsigned int version = 0; - cuCtxGetApiVersion(cudaContext, &version); - EXPECT_EQ(version, LATEST_KNOWN_CUDA_DRIVER_API_VERSION); - - ASSERT_EQ((plugin->call_nocheck(ctxt)), - PI_SUCCESS); -} - -TEST_F(CudaBaseObjectsTest, piContextCreateChildThread) { - pi_uint32 numPlatforms = 0; - pi_platform platform; - pi_device device; - - ASSERT_EQ((plugin->call_nocheck( - 0, nullptr, &numPlatforms)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - numPlatforms, &platform, nullptr)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - platform, PI_DEVICE_TYPE_GPU, 1, &device, nullptr)), - PI_SUCCESS); - - pi_context ctxt; - ASSERT_EQ((plugin->call_nocheck( - nullptr, 1, &device, nullptr, nullptr, &ctxt)), - PI_SUCCESS); - EXPECT_NE(ctxt, nullptr); - - // Retrieve the cuCtxt to check information is correct - auto checkValue = [=]() { - CUcontext cudaContext = ctxt->get(); - unsigned int version = 0; - auto cuErr = cuCtxGetApiVersion(cudaContext, &version); - EXPECT_EQ(cuErr, CUDA_SUCCESS); - EXPECT_EQ(version, LATEST_KNOWN_CUDA_DRIVER_API_VERSION); - - // The current context is different from the current thread - CUcontext current; - cuErr = cuCtxGetCurrent(¤t); - EXPECT_EQ(cuErr, CUDA_SUCCESS); - EXPECT_NE(cudaContext, current); - - // Set the context from PI API as the current one - cuErr = cuCtxPushCurrent(cudaContext); - EXPECT_EQ(cuErr, CUDA_SUCCESS); - - cuErr = cuCtxGetCurrent(¤t); - EXPECT_EQ(cuErr, CUDA_SUCCESS); - EXPECT_EQ(cudaContext, current); - }; - auto callContextFromOtherThread = std::thread(checkValue); - - callContextFromOtherThread.join(); - - ASSERT_EQ((plugin->call_nocheck(ctxt)), - PI_SUCCESS); -} diff --git a/sycl/unittests/pi/cuda/test_commands.cpp b/sycl/unittests/pi/cuda/test_commands.cpp deleted file mode 100644 index 6c794fe51c899..0000000000000 --- a/sycl/unittests/pi/cuda/test_commands.cpp +++ /dev/null @@ -1,145 +0,0 @@ -//==---- test_commands.cpp --- PI unit tests -------------------------------==// -// -// Part of the LLVM Project, 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 "gtest/gtest.h" - -#include - -#include "CudaUtils.hpp" -#include "TestGetPlugin.hpp" -#include -#include -#include -#include - -using namespace sycl; - -struct CudaCommandsTest : public ::testing::Test { - -protected: - std::optional &plugin = - pi::initializeAndGet(backend::ext_oneapi_cuda); - - pi_platform platform_; - pi_device device_; - pi_context context_; - pi_queue queue_; - - void SetUp() override { - // skip the tests if the CUDA backend is not available - if (!plugin.has_value()) { - GTEST_SKIP(); - } - - pi::clearCudaContext(); - pi_uint32 numPlatforms = 0; - ASSERT_EQ(plugin->hasBackend(backend::ext_oneapi_cuda), PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - 0, nullptr, &numPlatforms)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - numPlatforms, &platform_, nullptr)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - platform_, PI_DEVICE_TYPE_GPU, 1, &device_, nullptr)), - PI_SUCCESS); - ASSERT_EQ((plugin->call_nocheck( - nullptr, 1, &device_, nullptr, nullptr, &context_)), - PI_SUCCESS); - ASSERT_NE(context_, nullptr); - - ASSERT_EQ((plugin->call_nocheck( - context_, device_, 0, &queue_)), - PI_SUCCESS); - ASSERT_NE(queue_, nullptr); - auto tmpCtxt = queue_->get_context(); - ASSERT_EQ(tmpCtxt, context_); - } - - void TearDown() override { - if (plugin.has_value()) { - plugin->call(queue_); - plugin->call(context_); - } - } - - CudaCommandsTest() = default; - - ~CudaCommandsTest() = default; -}; - -TEST_F(CudaCommandsTest, PIEnqueueReadBufferBlocking) { - constexpr const size_t memSize = 10u; - constexpr const size_t bytes = memSize * sizeof(int); - const int data[memSize] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - int output[memSize] = {}; - - pi_mem memObj; - ASSERT_EQ( - (plugin->call_nocheck( - context_, PI_MEM_FLAGS_ACCESS_RW, bytes, nullptr, &memObj, nullptr)), - PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - queue_, memObj, true, 0, bytes, data, 0, nullptr, nullptr)), - PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - queue_, memObj, true, 0, bytes, output, 0, nullptr, nullptr)), - PI_SUCCESS); - - bool isSame = - std::equal(std::begin(output), std::end(output), std::begin(data)); - EXPECT_TRUE(isSame); - if (!isSame) { - std::for_each(std::begin(output), std::end(output), - [](int &elem) { std::cout << elem << ","; }); - std::cout << std::endl; - } -} - -TEST_F(CudaCommandsTest, PIEnqueueReadBufferNonBlocking) { - constexpr const size_t memSize = 10u; - constexpr const size_t bytes = memSize * sizeof(int); - const int data[memSize] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - int output[memSize] = {}; - - pi_mem memObj; - ASSERT_EQ( - (plugin->call_nocheck( - context_, PI_MEM_FLAGS_ACCESS_RW, bytes, nullptr, &memObj, nullptr)), - PI_SUCCESS); - - pi_event cpIn, cpOut; - ASSERT_EQ((plugin->call_nocheck( - queue_, memObj, false, 0, bytes, data, 0, nullptr, &cpIn)), - PI_SUCCESS); - ASSERT_NE(cpIn, nullptr); - - ASSERT_EQ((plugin->call_nocheck( - queue_, memObj, false, 0, bytes, output, 0, nullptr, &cpOut)), - PI_SUCCESS); - ASSERT_NE(cpOut, nullptr); - - ASSERT_EQ((plugin->call_nocheck(1, &cpOut)), - PI_SUCCESS); - - bool isSame = - std::equal(std::begin(output), std::end(output), std::begin(data)); - EXPECT_TRUE(isSame); - if (!isSame) { - std::for_each(std::begin(output), std::end(output), - [](int &elem) { std::cout << elem << ","; }); - std::cout << std::endl; - } -} diff --git a/sycl/unittests/pi/cuda/test_contexts.cpp b/sycl/unittests/pi/cuda/test_contexts.cpp deleted file mode 100644 index 7113537ebf147..0000000000000 --- a/sycl/unittests/pi/cuda/test_contexts.cpp +++ /dev/null @@ -1,250 +0,0 @@ -//==---- test_contexts.cpp --- PI unit tests -------------------------------==// -// -// Part of the LLVM Project, 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 "gtest/gtest.h" - -#include -#include -#include - -#include - -#include "CudaUtils.hpp" -#include "TestGetPlugin.hpp" -#include -#include -#include -#include - -using namespace sycl; - -struct CudaContextsTest : public ::testing::Test { - -protected: - std::optional &plugin = - pi::initializeAndGet(backend::ext_oneapi_cuda); - - pi_platform platform_; - pi_device device_; - - void SetUp() override { - // skip the tests if the CUDA backend is not available - if (!plugin.has_value()) { - GTEST_SKIP(); - } - - pi_uint32 numPlatforms = 0; - ASSERT_EQ(plugin->hasBackend(backend::ext_oneapi_cuda), PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - 0, nullptr, &numPlatforms)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - numPlatforms, &platform_, nullptr)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - platform_, PI_DEVICE_TYPE_GPU, 1, &device_, nullptr)), - PI_SUCCESS); - } - - void TearDown() override {} - - CudaContextsTest() = default; - - ~CudaContextsTest() = default; -}; - -TEST_F(CudaContextsTest, ContextLifetime) { - // start with no active context - pi::clearCudaContext(); - - // create a context - pi_context context; - ASSERT_EQ((plugin->call_nocheck( - nullptr, 1, &device_, nullptr, nullptr, &context)), - PI_SUCCESS); - ASSERT_NE(context, nullptr); - - // create a queue from the context, this should use the ScopedContext - pi_queue queue; - ASSERT_EQ((plugin->call_nocheck( - context, device_, 0, &queue)), - PI_SUCCESS); - ASSERT_NE(queue, nullptr); - - // ensure the queue has the correct context - ASSERT_EQ(context, queue->get_context()); - - // check that the context is now the active CUDA context - CUcontext cudaCtxt = nullptr; - cuCtxGetCurrent(&cudaCtxt); - ASSERT_EQ(cudaCtxt, context->get()); - - plugin->call(queue); - plugin->call(context); - - // check that the context was cleaned up properly by the destructor - cuCtxGetCurrent(&cudaCtxt); - ASSERT_EQ(cudaCtxt, nullptr); -} - -TEST_F(CudaContextsTest, ContextLifetimeExisting) { - // start by setting up a CUDA context on the thread - CUcontext original; - cuCtxCreate(&original, CU_CTX_MAP_HOST, device_->get()); - - // ensure the CUDA context is active - CUcontext current = nullptr; - cuCtxGetCurrent(¤t); - ASSERT_EQ(original, current); - - // create a PI context - pi_context context; - ASSERT_EQ((plugin->call_nocheck( - nullptr, 1, &device_, nullptr, nullptr, &context)), - PI_SUCCESS); - ASSERT_NE(context, nullptr); - - // create a queue from the context, this should use the ScopedContext - pi_queue queue; - ASSERT_EQ((plugin->call_nocheck( - context, device_, 0, &queue)), - PI_SUCCESS); - ASSERT_NE(queue, nullptr); - - // ensure the queue has the correct context - ASSERT_EQ(context, queue->get_context()); - - // check that the context is now the active CUDA context - cuCtxGetCurrent(¤t); - ASSERT_EQ(current, context->get()); - - plugin->call(queue); - plugin->call(context); - - // check that the context was cleaned up, the old context will be restored - // automatically by cuCtxDestroy in piContextRelease, as it was pushed on the - // stack bu cuCtxCreate - cuCtxGetCurrent(¤t); - ASSERT_EQ(current, original); - - // release original context - cuCtxDestroy(original); -} - -// In some cases (for host_task), the SYCL runtime may call PI API functions -// from threads of the thread pool, this can cause issues because with the CUDA -// plugin these functions will set an active CUDA context on these threads, but -// never clean it up, as it will only get cleaned up in the main thread. -// -// So the following test aims to reproduce the scenario where there is a -// dangling deleted context in a separate thread and seeing if the PI calls are -// still able to work correctly in that thread. -TEST_F(CudaContextsTest, ContextThread) { - // start with no active context - pi::clearCudaContext(); - - // create two PI contexts - pi_context context1; - ASSERT_EQ((plugin->call_nocheck( - nullptr, 1, &device_, nullptr, nullptr, &context1)), - PI_SUCCESS); - ASSERT_NE(context1, nullptr); - - pi_context context2; - ASSERT_EQ((plugin->call_nocheck( - nullptr, 1, &device_, nullptr, nullptr, &context2)), - PI_SUCCESS); - ASSERT_NE(context2, nullptr); - - // setup synchronization variables between the main thread and the testing - // thread - std::mutex m; - std::condition_variable cv; - bool released = false; - bool thread_done = false; - - // create a testing thread that will create a queue with the first context, - // release the queue, then wait for the main thread to release the first - // context, and then create and release another queue with the second context - // this time - auto test_thread = std::thread([&] { - CUcontext current = nullptr; - - // create a queue with the first context - pi_queue queue; - ASSERT_EQ((plugin->call_nocheck( - context1, device_, 0, &queue)), - PI_SUCCESS); - ASSERT_NE(queue, nullptr); - - // ensure the queue has the correct context - ASSERT_EQ(context1, queue->get_context()); - - // check that the first context is now the active CUDA context - cuCtxGetCurrent(¤t); - ASSERT_EQ(current, context1->get()); - - plugin->call(queue); - - // mark the first set of processing as done and notify the main thread - std::unique_lock lock(m); - thread_done = true; - lock.unlock(); - cv.notify_one(); - - // wait for the main thread to release the first context - lock.lock(); - cv.wait(lock, [&] { return released; }); - - // check that the first context is still active, this is because deleting a - // context only cleans up the current thread - cuCtxGetCurrent(¤t); - ASSERT_EQ(current, context1->get()); - - // create a queue with the second context - ASSERT_EQ((plugin->call_nocheck( - context2, device_, 0, &queue)), - PI_SUCCESS); - ASSERT_NE(queue, nullptr); - - // ensure the queue has the correct context - ASSERT_EQ(context2, queue->get_context()); - - // check that the second context is now the active CUDA context - cuCtxGetCurrent(¤t); - ASSERT_EQ(current, context2->get()); - - plugin->call(queue); - }); - - // wait for the thread to be done with the first queue to release the first - // context - std::unique_lock lock(m); - cv.wait(lock, [&] { return thread_done; }); - plugin->call(context1); - - // notify the other thread that the context was released - released = true; - lock.unlock(); - cv.notify_one(); - - // wait for the thread to finish - test_thread.join(); - - plugin->call(context2); - - // check that there is no context set on the main thread - CUcontext current = nullptr; - cuCtxGetCurrent(¤t); - ASSERT_EQ(current, nullptr); -} diff --git a/sycl/unittests/pi/cuda/test_device.cpp b/sycl/unittests/pi/cuda/test_device.cpp deleted file mode 100644 index 9ddb62ca1a512..0000000000000 --- a/sycl/unittests/pi/cuda/test_device.cpp +++ /dev/null @@ -1,111 +0,0 @@ -//==---- test_device.cpp --- PI unit tests ---------------------------------==// -// -// Part of the LLVM Project, 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 "gtest/gtest.h" - -#include - -#include "TestGetPlugin.hpp" -#include -#include -#include -#include - -using namespace sycl; - -struct CudaDeviceTests : public ::testing::Test { - -protected: - std::optional &plugin = - pi::initializeAndGet(backend::ext_oneapi_cuda); - - pi_platform platform_; - pi_device device_; - pi_context context_; - - void SetUp() override { - // skip the tests if the CUDA backend is not available - if (!plugin.has_value()) { - GTEST_SKIP(); - } - - pi_uint32 numPlatforms = 0; - ASSERT_EQ(plugin->hasBackend(backend::ext_oneapi_cuda), PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - 0, nullptr, &numPlatforms)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - numPlatforms, &platform_, nullptr)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - platform_, PI_DEVICE_TYPE_GPU, 1, &device_, nullptr)), - PI_SUCCESS); - ASSERT_EQ((plugin->call_nocheck( - nullptr, 1, &device_, nullptr, nullptr, &context_)), - PI_SUCCESS); - EXPECT_NE(context_, nullptr); - } - - void TearDown() override { - if (plugin.has_value()) { - plugin->call(device_); - plugin->call(context_); - } - } - - CudaDeviceTests() = default; - ~CudaDeviceTests() = default; -}; - -TEST_F(CudaDeviceTests, PIDeviceGetInfoSimple) { - - size_t return_size = 0; - pi_device_type device_type; - ASSERT_EQ((plugin->call_nocheck( - device_, PI_DEVICE_INFO_TYPE, sizeof(pi_device_type), - &device_type, &return_size)), - PI_SUCCESS); - EXPECT_EQ(return_size, sizeof(pi_device_type)); - EXPECT_EQ( - device_type, - PI_DEVICE_TYPE_GPU); // backend pre-defined value, device must be a GPU - - pi_device parent_device = nullptr; - ASSERT_EQ((plugin->call_nocheck( - device_, PI_DEVICE_INFO_PARENT_DEVICE, sizeof(pi_device), - &parent_device, &return_size)), - PI_SUCCESS); - EXPECT_EQ(return_size, sizeof(pi_device)); - EXPECT_EQ(parent_device, - nullptr); // backend pre-set value, device cannot have a parent - - pi_platform platform = nullptr; - ASSERT_EQ((plugin->call_nocheck( - device_, PI_DEVICE_INFO_PLATFORM, sizeof(pi_platform), - &platform, &return_size)), - PI_SUCCESS); - EXPECT_EQ(return_size, sizeof(pi_platform)); - EXPECT_EQ(platform, platform_); // test fixture device was created from the - // test fixture platform - - cl_device_partition_property device_partition_property = -1; - ASSERT_EQ((plugin->call_nocheck( - device_, PI_DEVICE_INFO_PARTITION_TYPE, - sizeof(cl_device_partition_property), - &device_partition_property, &return_size)), - PI_SUCCESS); - EXPECT_EQ(device_partition_property, - 0); // PI CUDA backend will not support device partitioning, this - // function should just return 0. - EXPECT_EQ(return_size, sizeof(cl_device_partition_property)); -} diff --git a/sycl/unittests/pi/cuda/test_interop_get_native.cpp b/sycl/unittests/pi/cuda/test_interop_get_native.cpp deleted file mode 100644 index 903d44043cda6..0000000000000 --- a/sycl/unittests/pi/cuda/test_interop_get_native.cpp +++ /dev/null @@ -1,137 +0,0 @@ -//==------- test_interop_get_native.cpp - SYCL CUDA get_native tests -------==// -// -// Part of the LLVM Project, 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 "gtest/gtest.h" - -#include - -#include "TestGetPlatforms.hpp" -#include - -#include - -using namespace sycl; - -struct CudaInteropGetNativeTests : public ::testing::TestWithParam { - -protected: - std::unique_ptr syclQueue_; - device syclDevice_; - - void SetUp() override { - syclDevice_ = GetParam().get_devices()[0]; - syclQueue_ = std::unique_ptr{new queue{syclDevice_}}; - } - - void TearDown() override { syclQueue_.reset(); } -}; - -TEST_P(CudaInteropGetNativeTests, getNativeDevice) { - CUdevice cudaDevice = get_native(syclDevice_); - char cudaDeviceName[2] = {0, 0}; - CUresult result = cuDeviceGetName(cudaDeviceName, 2, cudaDevice); - ASSERT_EQ(result, CUDA_SUCCESS); - ASSERT_NE(cudaDeviceName[0], 0); -} - -TEST_P(CudaInteropGetNativeTests, getNativeContext) { - CUcontext cudaContext = - get_native(syclQueue_->get_context()); - ASSERT_NE(cudaContext, nullptr); -} - -TEST_P(CudaInteropGetNativeTests, getNativeQueue) { - CUstream cudaStream = get_native(*syclQueue_); - ASSERT_NE(cudaStream, nullptr); - - CUcontext streamContext = nullptr; - CUresult result = cuStreamGetCtx(cudaStream, &streamContext); - ASSERT_EQ(result, CUDA_SUCCESS); - - CUcontext cudaContext = - get_native(syclQueue_->get_context()); - ASSERT_EQ(streamContext, cudaContext); -} - -TEST_P(CudaInteropGetNativeTests, interopTaskGetMem) { - buffer syclBuffer(range<1>{1}); - syclQueue_->submit([&](handler &cgh) { - auto syclAccessor = syclBuffer.get_access(cgh); - cgh.host_task([=](interop_handle ih) { - CUdeviceptr cudaPtr = - ih.get_native_mem(syclAccessor); - CUdeviceptr cudaPtrBase; - size_t cudaPtrSize = 0; - CUcontext cudaContext = - get_native(syclQueue_->get_context()); - ASSERT_EQ(CUDA_SUCCESS, cuCtxPushCurrent(cudaContext)); - ASSERT_EQ(CUDA_SUCCESS, - cuMemGetAddressRange(&cudaPtrBase, &cudaPtrSize, cudaPtr)); - ASSERT_EQ(CUDA_SUCCESS, cuCtxPopCurrent(nullptr)); - ASSERT_EQ(sizeof(int), cudaPtrSize); - }); - }); -} - -TEST_P(CudaInteropGetNativeTests, interopTaskGetQueue) { - CUstream cudaStream = get_native(*syclQueue_); - syclQueue_->submit([&](handler &cgh) { - cgh.host_task([=](interop_handle ih) { - CUstream cudaInteropStream = - ih.get_native_queue(); - ASSERT_EQ(cudaInteropStream, cudaStream); - }); - }); -} - -TEST_P(CudaInteropGetNativeTests, hostTaskGetNativeMem) { - buffer syclBuffer(range<1>{1}); - syclQueue_->submit([&](handler &cgh) { - auto syclAccessor = syclBuffer.get_access(cgh); - cgh.host_task([=](interop_handle ih) { - CUdeviceptr cudaPtr = - ih.get_native_mem(syclAccessor); - CUdeviceptr cudaPtrBase; - size_t cudaPtrSize = 0; - CUcontext cudaContext = - get_native(syclQueue_->get_context()); - ASSERT_EQ(CUDA_SUCCESS, cuCtxPushCurrent(cudaContext)); - ASSERT_EQ(CUDA_SUCCESS, - cuMemGetAddressRange(&cudaPtrBase, &cudaPtrSize, cudaPtr)); - ASSERT_EQ(CUDA_SUCCESS, cuCtxPopCurrent(nullptr)); - ASSERT_EQ(sizeof(int), cudaPtrSize); - }); - }); -} - -TEST_P(CudaInteropGetNativeTests, hostTaskGetNativeQueue) { - CUstream cudaStream = get_native(*syclQueue_); - syclQueue_->submit([&](handler &cgh) { - cgh.host_task([=](interop_handle ih) { - CUstream cudaInteropStream = - ih.get_native_queue(); - ASSERT_EQ(cudaInteropStream, cudaStream); - }); - }); -} - -TEST_P(CudaInteropGetNativeTests, hostTaskGetNativeContext) { - CUcontext cudaContext = - get_native(syclQueue_->get_context()); - syclQueue_->submit([&](handler &cgh) { - cgh.host_task([=](interop_handle ih) { - CUcontext cudaInteropContext = - ih.get_native_context(); - ASSERT_EQ(cudaInteropContext, cudaContext); - }); - }); -} - -INSTANTIATE_TEST_SUITE_P( - OnCudaPlatform, CudaInteropGetNativeTests, - ::testing::ValuesIn(pi::getPlatformsWithName("CUDA BACKEND"))); diff --git a/sycl/unittests/pi/cuda/test_kernels.cpp b/sycl/unittests/pi/cuda/test_kernels.cpp deleted file mode 100644 index 736e266b6566e..0000000000000 --- a/sycl/unittests/pi/cuda/test_kernels.cpp +++ /dev/null @@ -1,466 +0,0 @@ -//==---- test_kernels.cpp --- PI unit tests --------------------------------==// -// -// Part of the LLVM Project, 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 "gtest/gtest.h" - -#include - -#include "TestGetPlugin.hpp" -#include -#include -#include -#include - -// PI CUDA kernels carry an additional argument for the implicit global offset. -#define NUM_IMPLICIT_ARGS 1 - -using namespace sycl; - -struct CudaKernelsTest : public ::testing::Test { - -protected: - std::optional &plugin = - pi::initializeAndGet(backend::ext_oneapi_cuda); - pi_platform platform_; - pi_device device_; - pi_context context_; - pi_queue queue_; - - void SetUp() override { - // skip the tests if the CUDA backend is not available - if (!plugin.has_value()) { - GTEST_SKIP(); - } - - pi_uint32 numPlatforms = 0; - ASSERT_EQ(plugin->hasBackend(backend::ext_oneapi_cuda), PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - 0, nullptr, &numPlatforms)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - numPlatforms, &platform_, nullptr)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - platform_, PI_DEVICE_TYPE_GPU, 1, &device_, nullptr)), - PI_SUCCESS); - ASSERT_EQ((plugin->call_nocheck( - nullptr, 1, &device_, nullptr, nullptr, &context_)), - PI_SUCCESS); - ASSERT_NE(context_, nullptr); - - ASSERT_EQ((plugin->call_nocheck( - context_, device_, 0, &queue_)), - PI_SUCCESS); - ASSERT_NE(queue_, nullptr); - ASSERT_EQ(queue_->get_context(), context_); - } - - void TearDown() override { - if (plugin.has_value()) { - plugin->call(device_); - plugin->call(queue_); - plugin->call(context_); - } - } - - CudaKernelsTest() = default; - - ~CudaKernelsTest() = default; -}; - -const char *ptxSource = "\n\ -.version 3.2\n\ -.target sm_20\n\ -.address_size 64\n\ -.visible .entry _Z8myKernelPi(\n\ - .param .u64 _Z8myKernelPi_param_0\n\ -)\n\ -{\n\ - .reg .s32 %r<5>;\n\ - .reg .s64 %rd<5>;\n\ - ld.param.u64 %rd1, [_Z8myKernelPi_param_0];\n\ - cvta.to.global.u64 %rd2, %rd1;\n\ - .loc 1 3 1\n\ - mov.u32 %r1, %ntid.x;\n\ - mov.u32 %r2, %ctaid.x;\n\ - mov.u32 %r3, %tid.x;\n\ - mad.lo.s32 %r4, %r1, %r2, %r3;\n\ - mul.wide.s32 %rd3, %r4, 4;\n\ - add.s64 %rd4, %rd2, %rd3;\n\ - .loc 1 4 1\n\ - st.global.u32 [%rd4], %r4;\n\ - .loc 1 5 2\n\ - ret;\n\ - ret;\ -\n\ -}\ -\n\ -"; - -const char *twoParams = "\n\ -.version 3.2\n\ -.target sm_20\n\ -.address_size 64\n\ -.visible .entry twoParamKernel(\n\ - .param .u64 twoParamKernel_param_0,\n\ - .param .u64 twoParamKernel_param_1\n\ -)\n\ -{\n\ - ret;\ - \n\ -}\n\ -"; - -const char *threeParamsTwoLocal = "\n\ -.version 3.2\n\ -.target sm_20\n\ -.address_size 64\n\ -.visible .entry twoParamKernelLocal(\n\ - .param .u64 twoParamKernel_param_0,\n\ - .param .u32 twoParamKernel_param_1,\n\ - .param .u32 twoParamKernel_param_2\n\ -)\n\ -{\n\ - ret;\ - \n\ -}\n\ -"; - -TEST_F(CudaKernelsTest, PICreateProgramAndKernel) { - - pi_program prog; - pi_int32 binary_status = PI_SUCCESS; - ASSERT_EQ( - (plugin->call_nocheck( - context_, 1, &device_, nullptr, (const unsigned char **)&ptxSource, 0, - nullptr, &binary_status, &prog)), - PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - prog, 1, &device_, "", nullptr, nullptr)), - PI_SUCCESS); - - pi_kernel kern; - ASSERT_EQ((plugin->call_nocheck( - prog, "_Z8myKernelPi", &kern)), - PI_SUCCESS); - ASSERT_NE(kern, nullptr); -} - -TEST_F(CudaKernelsTest, PICreateProgramAndKernelWithMetadata) { - - std::vector reqdWorkGroupSizeMD; - reqdWorkGroupSizeMD.reserve(5); - // 64-bit representing bit size - reqdWorkGroupSizeMD.push_back(96); - reqdWorkGroupSizeMD.push_back(0); - // reqd_work_group_size x - reqdWorkGroupSizeMD.push_back(8); - // reqd_work_group_size y - reqdWorkGroupSizeMD.push_back(16); - // reqd_work_group_size z - reqdWorkGroupSizeMD.push_back(32); - - const char *reqdWorkGroupSizeMDConstName = - "_Z8myKernelPi@reqd_work_group_size"; - std::vector reqdWorkGroupSizeMDName( - reqdWorkGroupSizeMDConstName, - reqdWorkGroupSizeMDConstName + strlen(reqdWorkGroupSizeMDConstName) + 1); - _pi_device_binary_property_struct reqdWorkGroupSizeMDProp = { - reqdWorkGroupSizeMDName.data(), reqdWorkGroupSizeMD.data(), - pi_property_type::PI_PROPERTY_TYPE_BYTE_ARRAY, - sizeof(std::uint64_t) + sizeof(std::uint32_t) * 3}; - pi_device_binary_property reqdWorkGroupSizeMDPropPointer = - &reqdWorkGroupSizeMDProp; - - pi_program prog; - pi_int32 binary_status = PI_SUCCESS; - ASSERT_EQ( - (plugin->call_nocheck( - context_, 1, &device_, nullptr, (const unsigned char **)&ptxSource, 1, - &reqdWorkGroupSizeMDPropPointer, &binary_status, &prog)), - PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - prog, 1, &device_, "", nullptr, nullptr)), - PI_SUCCESS); - - pi_kernel kern; - ASSERT_EQ((plugin->call_nocheck( - prog, "_Z8myKernelPi", &kern)), - PI_SUCCESS); - ASSERT_NE(kern, nullptr); - - size_t compileWGSize[3] = {0}; - ASSERT_EQ((plugin->call_nocheck( - kern, device_, PI_KERNEL_GROUP_INFO_COMPILE_WORK_GROUP_SIZE, - sizeof(size_t) * 3, compileWGSize, nullptr)), - PI_SUCCESS); - for (int i = 0; i < 3; ++i) { - ASSERT_EQ(compileWGSize[i], reqdWorkGroupSizeMD[i + 2]); - } -} - -TEST_F(CudaKernelsTest, PIKernelArgumentSimple) { - - pi_program prog; - /// NOTE: `binary_status` currently unsused in the CUDA backend but in case we - /// use it at some point in the future, pass it anyway and check the result. - /// Same goes for all the other tests in this file. - pi_int32 binary_status = PI_SUCCESS; - ASSERT_EQ( - (plugin->call_nocheck( - context_, 1, &device_, nullptr, (const unsigned char **)&ptxSource, 0, - nullptr, &binary_status, &prog)), - PI_SUCCESS); - ASSERT_EQ(binary_status, PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - prog, 1, &device_, "", nullptr, nullptr)), - PI_SUCCESS); - - pi_kernel kern; - ASSERT_EQ((plugin->call_nocheck( - prog, "_Z8myKernelPi", &kern)), - PI_SUCCESS); - - int number = 10; - ASSERT_EQ((plugin->call_nocheck( - kern, 0, sizeof(int), &number)), - PI_SUCCESS); - const auto &kernArgs = kern->get_arg_indices(); - ASSERT_EQ(kernArgs.size(), (size_t)1 + NUM_IMPLICIT_ARGS); - int storedValue = *(static_cast(kernArgs[0])); - ASSERT_EQ(storedValue, number); -} - -TEST_F(CudaKernelsTest, PIKernelArgumentSetTwice) { - - pi_program prog; - pi_int32 binary_status = PI_SUCCESS; - ASSERT_EQ( - (plugin->call_nocheck( - context_, 1, &device_, nullptr, (const unsigned char **)&ptxSource, 0, - nullptr, &binary_status, &prog)), - PI_SUCCESS); - ASSERT_EQ(binary_status, PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - prog, 1, &device_, "", nullptr, nullptr)), - PI_SUCCESS); - - pi_kernel kern; - ASSERT_EQ((plugin->call_nocheck( - prog, "_Z8myKernelPi", &kern)), - PI_SUCCESS); - - int number = 10; - ASSERT_EQ((plugin->call_nocheck( - kern, 0, sizeof(int), &number)), - PI_SUCCESS); - const auto &kernArgs = kern->get_arg_indices(); - ASSERT_GT(kernArgs.size(), (size_t)0 + NUM_IMPLICIT_ARGS); - int storedValue = *(static_cast(kernArgs[0])); - ASSERT_EQ(storedValue, number); - - int otherNumber = 934; - ASSERT_EQ((plugin->call_nocheck( - kern, 0, sizeof(int), &otherNumber)), - PI_SUCCESS); - const auto &kernArgs2 = kern->get_arg_indices(); - ASSERT_EQ(kernArgs2.size(), (size_t)1 + NUM_IMPLICIT_ARGS); - storedValue = *(static_cast(kernArgs2[0])); - ASSERT_EQ(storedValue, otherNumber); -} - -TEST_F(CudaKernelsTest, PIKernelSetMemObj) { - - pi_program prog; - pi_int32 binary_status = PI_SUCCESS; - ASSERT_EQ( - (plugin->call_nocheck( - context_, 1, &device_, nullptr, (const unsigned char **)&ptxSource, 0, - nullptr, &binary_status, &prog)), - PI_SUCCESS); - ASSERT_EQ(binary_status, PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - prog, 1, &device_, "", nullptr, nullptr)), - PI_SUCCESS); - - pi_kernel kern; - ASSERT_EQ((plugin->call_nocheck( - prog, "_Z8myKernelPi", &kern)), - PI_SUCCESS); - - size_t memSize = 1024u; - pi_mem memObj; - ASSERT_EQ((plugin->call_nocheck( - context_, PI_MEM_FLAGS_ACCESS_RW, memSize, nullptr, &memObj, - nullptr)), - PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - kern, 0, sizeof(pi_mem), &memObj)), - PI_SUCCESS); - const auto &kernArgs = kern->get_arg_indices(); - ASSERT_EQ(kernArgs.size(), (size_t)1 + NUM_IMPLICIT_ARGS); - pi_mem storedValue = *(static_cast(kernArgs[0])); - ASSERT_EQ(storedValue, memObj); -} - -TEST_F(CudaKernelsTest, PIkerneldispatch) { - - pi_program prog; - pi_int32 binary_status = PI_SUCCESS; - ASSERT_EQ( - (plugin->call_nocheck( - context_, 1, &device_, nullptr, (const unsigned char **)&ptxSource, 0, - nullptr, &binary_status, &prog)), - PI_SUCCESS); - ASSERT_EQ(binary_status, PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - prog, 1, &device_, "", nullptr, nullptr)), - PI_SUCCESS); - - pi_kernel kern; - ASSERT_EQ((plugin->call_nocheck( - prog, "_Z8myKernelPi", &kern)), - PI_SUCCESS); - - size_t memSize = 1024u; - pi_mem memObj; - ASSERT_EQ((plugin->call_nocheck( - context_, PI_MEM_FLAGS_ACCESS_RW, memSize, nullptr, &memObj, - nullptr)), - PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - kern, 0, nullptr, &memObj)), - PI_SUCCESS); - - size_t workDim = 1; - size_t globalWorkOffset[] = {0}; - size_t globalWorkSize[] = {1}; - size_t localWorkSize[] = {1}; - ASSERT_EQ((plugin->call_nocheck( - queue_, kern, workDim, globalWorkOffset, globalWorkSize, - localWorkSize, 0, nullptr, nullptr)), - PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck(memObj)), - PI_SUCCESS); -} - -TEST_F(CudaKernelsTest, PIkerneldispatchTwo) { - - pi_program prog; - pi_int32 binary_status = PI_SUCCESS; - ASSERT_EQ( - (plugin->call_nocheck( - context_, 1, &device_, nullptr, (const unsigned char **)&twoParams, 0, - nullptr, &binary_status, &prog)), - PI_SUCCESS); - ASSERT_EQ(binary_status, PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - prog, 1, &device_, "", nullptr, nullptr)), - PI_SUCCESS); - - pi_kernel kern; - ASSERT_EQ((plugin->call_nocheck( - prog, "twoParamKernel", &kern)), - PI_SUCCESS); - - size_t memSize = 1024u; - pi_mem memObj; - ASSERT_EQ((plugin->call_nocheck( - context_, PI_MEM_FLAGS_ACCESS_RW, memSize, nullptr, &memObj, - nullptr)), - PI_SUCCESS); - - pi_mem memObj2; - ASSERT_EQ((plugin->call_nocheck( - context_, PI_MEM_FLAGS_ACCESS_RW, memSize, nullptr, &memObj2, - nullptr)), - PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - kern, 0, nullptr, &memObj)), - PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - kern, 1, nullptr, &memObj2)), - PI_SUCCESS); - - size_t workDim = 1; - size_t globalWorkOffset[] = {0}; - size_t globalWorkSize[] = {1}; - size_t localWorkSize[] = {1}; - ASSERT_EQ((plugin->call_nocheck( - queue_, kern, workDim, globalWorkOffset, globalWorkSize, - localWorkSize, 0, nullptr, nullptr)), - PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck(memObj)), - PI_SUCCESS); - ASSERT_EQ((plugin->call_nocheck(memObj2)), - PI_SUCCESS); -} - -TEST_F(CudaKernelsTest, PIKernelArgumentSetTwiceOneLocal) { - - pi_program prog; - pi_int32 binary_status = PI_SUCCESS; - ASSERT_EQ((plugin->call_nocheck( - context_, 1, &device_, nullptr, - (const unsigned char **)&threeParamsTwoLocal, 0, nullptr, - &binary_status, &prog)), - PI_SUCCESS); - ASSERT_EQ(binary_status, PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - prog, 1, &device_, "", nullptr, nullptr)), - PI_SUCCESS); - - pi_kernel kern; - ASSERT_EQ((plugin->call_nocheck( - prog, "twoParamKernelLocal", &kern)), - PI_SUCCESS); - - int number = 10; - ASSERT_EQ((plugin->call_nocheck( - kern, 0, sizeof(int), &number)), - PI_SUCCESS); - const auto &kernArgs = kern->get_arg_indices(); - ASSERT_GT(kernArgs.size(), (size_t)0 + NUM_IMPLICIT_ARGS); - int storedValue = *(static_cast(kernArgs[0])); - ASSERT_EQ(storedValue, number); - - ASSERT_EQ((plugin->call_nocheck( - kern, 1, sizeof(int), nullptr)), - PI_SUCCESS); - const auto &kernArgs2 = kern->get_arg_indices(); - ASSERT_EQ(kernArgs2.size(), (size_t)2 + NUM_IMPLICIT_ARGS); - storedValue = *(static_cast(kernArgs2[1])); - ASSERT_EQ(storedValue, 0); - - ASSERT_EQ((plugin->call_nocheck( - kern, 2, sizeof(int), nullptr)), - PI_SUCCESS); - const auto &kernArgs3 = kern->get_arg_indices(); - ASSERT_EQ(kernArgs3.size(), (size_t)3 + NUM_IMPLICIT_ARGS); - storedValue = *(static_cast(kernArgs3[2])); - ASSERT_EQ(storedValue, static_cast(sizeof(int))); -} diff --git a/sycl/unittests/pi/cuda/test_mem_obj.cpp b/sycl/unittests/pi/cuda/test_mem_obj.cpp deleted file mode 100644 index b0693ff30830c..0000000000000 --- a/sycl/unittests/pi/cuda/test_mem_obj.cpp +++ /dev/null @@ -1,207 +0,0 @@ -//==---- test_mem_obj.cpp --- PI unit tests --------------------------------==// -// -// Part of the LLVM Project, 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 "gtest/gtest.h" - -#include - -#include "CudaUtils.hpp" -#include "TestGetPlugin.hpp" -#include -#include -#include -#include -#include - -using namespace sycl; - -struct CudaTestMemObj : public ::testing::Test { - -protected: - std::optional &plugin = - pi::initializeAndGet(backend::ext_oneapi_cuda); - - pi_platform platform_; - pi_device device_; - pi_context context_; - - void SetUp() override { - // skip the tests if the CUDA backend is not available - if (!plugin.has_value()) { - GTEST_SKIP(); - } - - pi::clearCudaContext(); - pi_uint32 numPlatforms = 0; - ASSERT_EQ(plugin->hasBackend(backend::ext_oneapi_cuda), PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - 0, nullptr, &numPlatforms)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - numPlatforms, &platform_, nullptr)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - platform_, PI_DEVICE_TYPE_GPU, 1, &device_, nullptr)), - PI_SUCCESS); - ASSERT_EQ((plugin->call_nocheck( - nullptr, 1, &device_, nullptr, nullptr, &context_)), - PI_SUCCESS); - EXPECT_NE(context_, nullptr); - } - - void TearDown() override { - if (plugin.has_value()) { - plugin->call(device_); - plugin->call(context_); - } - } - - CudaTestMemObj() = default; - - ~CudaTestMemObj() = default; -}; - -TEST_F(CudaTestMemObj, piMemBufferCreateSimple) { - const size_t memSize = 1024u; - pi_mem memObj; - ASSERT_EQ((plugin->call_nocheck( - context_, PI_MEM_FLAGS_ACCESS_RW, memSize, nullptr, &memObj, - nullptr)), - PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck(memObj)), - PI_SUCCESS); -} - -TEST_F(CudaTestMemObj, piMemBufferAllocHost) { - const size_t memSize = 1024u; - pi_mem memObj; - ASSERT_EQ((plugin->call_nocheck( - context_, PI_MEM_FLAGS_ACCESS_RW | PI_MEM_FLAGS_HOST_PTR_ALLOC, - memSize, nullptr, &memObj, nullptr)), - PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck(memObj)), - PI_SUCCESS); -} - -TEST_F(CudaTestMemObj, piMemBufferCreateNoActiveContext) { - const size_t memSize = 1024u; - // Context has been destroyed - - CUcontext current = nullptr; - - // pop CUDA contexts until there is not a cuda context bound to the thread - do { - CUcontext oldContext = nullptr; - auto cuErr = cuCtxPopCurrent(&oldContext); - EXPECT_EQ(cuErr, CUDA_SUCCESS); - - // There should not be any active CUDA context - cuErr = cuCtxGetCurrent(¤t); - ASSERT_EQ(cuErr, CUDA_SUCCESS); - } while (current != nullptr); - - // The context object is passed, even if its not active it should be used - // to allocate the memory object - pi_mem memObj; - ASSERT_EQ((plugin->call_nocheck( - context_, PI_MEM_FLAGS_ACCESS_RW, memSize, nullptr, &memObj, - nullptr)), - PI_SUCCESS); - ASSERT_NE(memObj, nullptr); - - ASSERT_EQ((plugin->call_nocheck(memObj)), - PI_SUCCESS); -} - -TEST_F(CudaTestMemObj, piMemBufferPinnedMappedRead) { - const size_t memSize = sizeof(int); - const int value = 20; - - pi_queue queue; - ASSERT_EQ((plugin->call_nocheck( - context_, device_, 0, &queue)), - PI_SUCCESS); - ASSERT_NE(queue, nullptr); - ASSERT_EQ(queue->get_context(), context_); - - pi_mem memObj; - ASSERT_EQ((plugin->call_nocheck( - context_, PI_MEM_FLAGS_ACCESS_RW | PI_MEM_FLAGS_HOST_PTR_ALLOC, - memSize, nullptr, &memObj, nullptr)), - PI_SUCCESS); - - ASSERT_EQ( - (plugin->call_nocheck( - queue, memObj, true, 0, sizeof(int), &value, 0, nullptr, nullptr)), - PI_SUCCESS); - - int *host_ptr = nullptr; - ASSERT_EQ((plugin->call_nocheck( - queue, memObj, true, PI_MAP_READ, 0, sizeof(int), 0, nullptr, - nullptr, (void **)&host_ptr)), - PI_SUCCESS); - - ASSERT_EQ(*host_ptr, value); - - ASSERT_EQ((plugin->call_nocheck( - queue, memObj, host_ptr, 0, nullptr, nullptr)), - PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck(memObj)), - PI_SUCCESS); - plugin->call(queue); -} - -TEST_F(CudaTestMemObj, piMemBufferPinnedMappedWrite) { - const size_t memSize = sizeof(int); - const int value = 30; - - pi_queue queue; - ASSERT_EQ((plugin->call_nocheck( - context_, device_, 0, &queue)), - PI_SUCCESS); - ASSERT_NE(queue, nullptr); - ASSERT_EQ(queue->get_context(), context_); - - pi_mem memObj; - ASSERT_EQ((plugin->call_nocheck( - context_, PI_MEM_FLAGS_ACCESS_RW | PI_MEM_FLAGS_HOST_PTR_ALLOC, - memSize, nullptr, &memObj, nullptr)), - PI_SUCCESS); - - int *host_ptr = nullptr; - ASSERT_EQ((plugin->call_nocheck( - queue, memObj, true, PI_MAP_WRITE, 0, sizeof(int), 0, nullptr, - nullptr, (void **)&host_ptr)), - PI_SUCCESS); - - *host_ptr = value; - - ASSERT_EQ((plugin->call_nocheck( - queue, memObj, host_ptr, 0, nullptr, nullptr)), - PI_SUCCESS); - - int read_value = 0; - ASSERT_EQ((plugin->call_nocheck( - queue, memObj, true, 0, sizeof(int), &read_value, 0, nullptr, - nullptr)), - PI_SUCCESS); - - ASSERT_EQ(read_value, value); - - ASSERT_EQ((plugin->call_nocheck(memObj)), - PI_SUCCESS); - plugin->call(queue); -} diff --git a/sycl/unittests/pi/cuda/test_primary_context.cpp b/sycl/unittests/pi/cuda/test_primary_context.cpp deleted file mode 100644 index f9ce627d126ad..0000000000000 --- a/sycl/unittests/pi/cuda/test_primary_context.cpp +++ /dev/null @@ -1,94 +0,0 @@ -//==---------- pi_primary_context.cpp - PI unit tests ----------------------==// -// -// Part of the LLVM Project, 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 "gtest/gtest.h" - -#include - -#include "TestGetPlatforms.hpp" -#include -#include - -#include - -using namespace sycl; - -struct CudaPrimaryContextTests : public ::testing::TestWithParam { - -protected: - device deviceA_; - device deviceB_; - - void SetUp() override { - std::vector CudaDevices = GetParam().get_devices(); - - deviceA_ = CudaDevices[0]; - deviceB_ = CudaDevices.size() > 1 ? CudaDevices[1] : deviceA_; - } - - void TearDown() override {} -}; - -TEST_P(CudaPrimaryContextTests, piSingleContext) { - std::cout << "create single context" << std::endl; - context Context( - deviceA_, async_handler{}, - {sycl::ext::oneapi::cuda::property::context::use_primary_context{}}); - - CUdevice CudaDevice = get_native(deviceA_); - CUcontext CudaContext = get_native(Context); - - CUcontext PrimaryCudaContext; - cuDevicePrimaryCtxRetain(&PrimaryCudaContext, CudaDevice); - - ASSERT_EQ(CudaContext, PrimaryCudaContext); - - cuDevicePrimaryCtxRelease(CudaDevice); -} - -TEST_P(CudaPrimaryContextTests, piMultiContextSingleDevice) { - std::cout << "create multiple contexts for one device" << std::endl; - context ContextA( - deviceA_, async_handler{}, - {sycl::ext::oneapi::cuda::property::context::use_primary_context{}}); - context ContextB( - deviceA_, async_handler{}, - {sycl::ext::oneapi::cuda::property::context::use_primary_context{}}); - - CUcontext CudaContextA = get_native(ContextA); - CUcontext CudaContextB = get_native(ContextB); - - ASSERT_EQ(CudaContextA, CudaContextB); -} - -TEST_P(CudaPrimaryContextTests, piMultiContextMultiDevice) { - if (deviceA_ == deviceB_) - return; - - CUdevice CudaDeviceA = get_native(deviceA_); - CUdevice CudaDeviceB = get_native(deviceB_); - - ASSERT_NE(CudaDeviceA, CudaDeviceB); - - std::cout << "create multiple contexts for multiple devices" << std::endl; - context ContextA( - deviceA_, async_handler{}, - {sycl::ext::oneapi::cuda::property::context::use_primary_context{}}); - context ContextB( - deviceB_, async_handler{}, - {sycl::ext::oneapi::cuda::property::context::use_primary_context{}}); - - CUcontext CudaContextA = get_native(ContextA); - CUcontext CudaContextB = get_native(ContextB); - - ASSERT_NE(CudaContextA, CudaContextB); -} - -INSTANTIATE_TEST_SUITE_P( - OnCudaPlatform, CudaPrimaryContextTests, - ::testing::ValuesIn(pi::getPlatformsWithName("CUDA BACKEND"))); diff --git a/sycl/unittests/pi/cuda/test_sampler_properties.cpp b/sycl/unittests/pi/cuda/test_sampler_properties.cpp deleted file mode 100644 index 793703d2bd1ca..0000000000000 --- a/sycl/unittests/pi/cuda/test_sampler_properties.cpp +++ /dev/null @@ -1,135 +0,0 @@ -//==---- PlatformTest.cpp --- PI unit tests --------------------------------==// -// -// Part of the LLVM Project, 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 "gtest/gtest.h" - -#include "TestGetPlugin.hpp" -#include -#include -#include - -#include - -namespace { - -using namespace sycl; - -class SamplerPropertiesTest - : public ::testing::TestWithParam> { -protected: - std::optional &plugin = - pi::initializeAndGet(backend::ext_oneapi_cuda); - - pi_platform platform_; - pi_device device_; - pi_context context_; - pi_sampler sampler_; - - pi_bool normalizedCoords_; - pi_sampler_filter_mode filterMode_; - pi_sampler_addressing_mode addressMode_; - - SamplerPropertiesTest() = default; - - ~SamplerPropertiesTest() override = default; - - void SetUp() override { - // skip the tests if the CUDA backend is not available - if (!plugin.has_value()) { - GTEST_SKIP(); - } - - std::tie(normalizedCoords_, filterMode_, addressMode_) = GetParam(); - - pi_uint32 numPlatforms = 0; - ASSERT_EQ(plugin->hasBackend(backend::ext_oneapi_cuda), PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - 0, nullptr, &numPlatforms)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - numPlatforms, &platform_, nullptr)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - platform_, PI_DEVICE_TYPE_GPU, 1, &device_, nullptr)), - PI_SUCCESS); - ASSERT_EQ((plugin->call_nocheck( - nullptr, 1, &device_, nullptr, nullptr, &context_)), - PI_SUCCESS); - EXPECT_NE(context_, nullptr); - - pi_sampler_properties sampler_properties[] = { - PI_SAMPLER_PROPERTIES_NORMALIZED_COORDS, - static_cast(normalizedCoords_), - PI_SAMPLER_PROPERTIES_ADDRESSING_MODE, - static_cast(addressMode_), - PI_SAMPLER_PROPERTIES_FILTER_MODE, - static_cast(filterMode_), - 0}; - - ASSERT_EQ((plugin->call_nocheck( - context_, sampler_properties, &sampler_)), - PI_SUCCESS); - } - - void TearDown() override { - if (plugin.has_value()) { - plugin->call(sampler_); - plugin->call(device_); - plugin->call(context_); - } - } -}; - -TEST_P(SamplerPropertiesTest, piCheckNormalizedCoords) { - pi_bool actualNormalizedCoords = !normalizedCoords_; - - plugin->call( - sampler_, PI_SAMPLER_INFO_NORMALIZED_COORDS, sizeof(pi_bool), - &actualNormalizedCoords, nullptr); - - ASSERT_EQ(actualNormalizedCoords, normalizedCoords_); -} - -TEST_P(SamplerPropertiesTest, piCheckFilterMode) { - pi_sampler_filter_mode actualFilterMode; - - plugin->call( - sampler_, PI_SAMPLER_INFO_FILTER_MODE, sizeof(pi_sampler_filter_mode), - &actualFilterMode, nullptr); - - ASSERT_EQ(actualFilterMode, filterMode_); -} - -TEST_P(SamplerPropertiesTest, piCheckAddressingMode) { - pi_sampler_addressing_mode actualAddressMode; - - plugin->call( - sampler_, PI_SAMPLER_INFO_ADDRESSING_MODE, - sizeof(pi_sampler_addressing_mode), &actualAddressMode, nullptr); - - ASSERT_EQ(actualAddressMode, addressMode_); -} - -INSTANTIATE_TEST_SUITE_P( - SamplerPropertiesTestImpl, SamplerPropertiesTest, - ::testing::Combine( - ::testing::Values(PI_TRUE, PI_FALSE), - ::testing::Values(PI_SAMPLER_FILTER_MODE_LINEAR, - PI_SAMPLER_FILTER_MODE_NEAREST), - ::testing::Values(PI_SAMPLER_ADDRESSING_MODE_CLAMP, - PI_SAMPLER_ADDRESSING_MODE_CLAMP_TO_EDGE, - PI_SAMPLER_ADDRESSING_MODE_NONE, - PI_SAMPLER_ADDRESSING_MODE_MIRRORED_REPEAT, - PI_SAMPLER_ADDRESSING_MODE_REPEAT))); -} // namespace diff --git a/sycl/unittests/pi/hip/CMakeLists.txt b/sycl/unittests/pi/hip/CMakeLists.txt deleted file mode 100644 index eee75b0447551..0000000000000 --- a/sycl/unittests/pi/hip/CMakeLists.txt +++ /dev/null @@ -1,42 +0,0 @@ -add_sycl_unittest(PiHipTests OBJECT - test_base_objects.cpp - test_commands.cpp - test_contexts.cpp - test_device.cpp - test_interop_get_native.cpp - test_kernels.cpp - test_mem_obj.cpp - test_primary_context.cpp - test_sampler_properties.cpp -) - -add_dependencies(PiHipTests sycl) - -target_compile_definitions(PiHipTests - PRIVATE - GTEST_HAS_COMBINE=1) - -target_include_directories(PiHipTests - PRIVATE - "../" - "${sycl_inc_dir}/sycl/detail/" - "${sycl_inc_dir}" - "${sycl_plugin_dir}/hip/" - "${sycl_plugin_dir}/unified_runtime/" -) - -if("${SYCL_BUILD_PI_HIP_PLATFORM}" STREQUAL "AMD") - # Set HIP define to select AMD platform - target_compile_definitions(PiHipTests PRIVATE __HIP_PLATFORM_AMD__) -elseif("${SYCL_BUILD_PI_HIP_PLATFORM}" STREQUAL "NVIDIA") - # Set HIP define to select NVIDIA platform - target_compile_definitions(PiHipTests PRIVATE __HIP_PLATFORM_NVIDIA__) -else() - message(FATAL_ERROR "Unspecified PI HIP platform, please set SYCL_BUILD_PI_HIP_PLATFORM to 'AMD' or 'NVIDIA'") -endif() - -target_link_libraries(PiHipTests - PRIVATE - rocmdrv - UnifiedRuntime-Headers -) diff --git a/sycl/unittests/pi/hip/HipUtils.hpp b/sycl/unittests/pi/hip/HipUtils.hpp deleted file mode 100644 index c62bf7dfefb08..0000000000000 --- a/sycl/unittests/pi/hip/HipUtils.hpp +++ /dev/null @@ -1,20 +0,0 @@ -// Part of the LLVM Project, 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 - -#pragma once - -#include - -namespace pi { - -// utility function to clear the HIP context stack -inline void clearHipContext() { - hipCtx_t ctxt = nullptr; - do { - hipCtxSetCurrent(nullptr); - hipCtxGetCurrent(&ctxt); - } while (ctxt != nullptr); -} - -} // namespace pi diff --git a/sycl/unittests/pi/hip/test_base_objects.cpp b/sycl/unittests/pi/hip/test_base_objects.cpp deleted file mode 100644 index 86458aa62c0b1..0000000000000 --- a/sycl/unittests/pi/hip/test_base_objects.cpp +++ /dev/null @@ -1,141 +0,0 @@ -//==---- test_base_objects.cpp --- PI unit tests ---------------------------==// -// -// Part of the LLVM Project, 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 "gtest/gtest.h" - -#include - -#include "TestGetPlugin.hpp" -#include -#include -#include -#include - -#include - -// https://sep5.readthedocs.io/en/latest/ROCm_API_References/ -// HIP_API/Context-Management.html#_CPPv419hipCtxGetApiVersion8hipCtx_tPi -const int HIP_DRIVER_API_VERSION = 4; - -using namespace sycl; - -class HipBaseObjectsTest : public ::testing::Test { -protected: - std::optional &plugin = - pi::initializeAndGet(backend::ext_oneapi_hip); - - void SetUp() override { - // skip the tests if the HIP backend is not available - if (!plugin.has_value()) { - GTEST_SKIP(); - } - } - - HipBaseObjectsTest() = default; - - ~HipBaseObjectsTest() = default; -}; - -TEST_F(HipBaseObjectsTest, piContextCreate) { - pi_uint32 numPlatforms = 0; - pi_platform platform = nullptr; - pi_device device; - ASSERT_EQ(plugin->hasBackend(backend::ext_oneapi_hip), PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - 0, nullptr, &numPlatforms)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - numPlatforms, &platform, nullptr)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_GE(numPlatforms, 1u); - ASSERT_NE(platform, nullptr); - - ASSERT_EQ((plugin->call_nocheck( - platform, PI_DEVICE_TYPE_GPU, 1, &device, nullptr)), - PI_SUCCESS) - << "piDevicesGet failed.\n"; - - pi_context ctxt = nullptr; - ASSERT_EQ((plugin->call_nocheck( - nullptr, 1, &device, nullptr, nullptr, &ctxt)), - PI_SUCCESS) - << "piContextCreate failed.\n"; - - EXPECT_NE(ctxt, nullptr); - EXPECT_EQ(ctxt->get_device(), device); - - // Retrieve the hipCtxt to check information is correct - hipCtx_t hipContext = ctxt->get(); - int version = 0; - auto hipErr = hipCtxGetApiVersion(hipContext, &version); - EXPECT_EQ(hipErr, PI_SUCCESS); - EXPECT_EQ(version, HIP_DRIVER_API_VERSION); - - ASSERT_EQ((plugin->call_nocheck(ctxt)), - PI_SUCCESS); -} - -TEST_F(HipBaseObjectsTest, piContextCreateChildThread) { - pi_uint32 numPlatforms = 0; - pi_platform platform; - pi_device device; - - ASSERT_EQ((plugin->call_nocheck( - 0, nullptr, &numPlatforms)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - numPlatforms, &platform, nullptr)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - platform, PI_DEVICE_TYPE_GPU, 1, &device, nullptr)), - PI_SUCCESS); - - pi_context ctxt; - ASSERT_EQ((plugin->call_nocheck( - nullptr, 1, &device, nullptr, nullptr, &ctxt)), - PI_SUCCESS); - EXPECT_NE(ctxt, nullptr); - - // Retrieve the cuCtxt to check information is correct - auto checkValue = [=]() { - hipCtx_t hipContext = ctxt->get(); - int version = 0; - auto hipErr = hipCtxGetApiVersion(hipContext, &version); - EXPECT_EQ(hipErr, PI_SUCCESS); - EXPECT_EQ(version, HIP_DRIVER_API_VERSION); - - // The current context is different from the current thread - hipCtx_t current; - hipErr = hipCtxGetCurrent(¤t); - EXPECT_EQ(hipErr, PI_SUCCESS); - EXPECT_NE(hipContext, current); - - // Set the context from PI API as the current one - hipErr = hipCtxPushCurrent(hipContext); - EXPECT_EQ(hipErr, PI_SUCCESS); - - hipErr = hipCtxGetCurrent(¤t); - EXPECT_EQ(hipErr, PI_SUCCESS); - EXPECT_EQ(hipContext, current); - }; - auto callContextFromOtherThread = std::thread(checkValue); - - callContextFromOtherThread.join(); - - ASSERT_EQ((plugin->call_nocheck(ctxt)), - PI_SUCCESS); -} diff --git a/sycl/unittests/pi/hip/test_commands.cpp b/sycl/unittests/pi/hip/test_commands.cpp deleted file mode 100644 index d453e9b9da1ea..0000000000000 --- a/sycl/unittests/pi/hip/test_commands.cpp +++ /dev/null @@ -1,145 +0,0 @@ -//==---- test_commands.cpp --- PI unit tests -------------------------------==// -// -// Part of the LLVM Project, 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 "gtest/gtest.h" - -#include - -#include "HipUtils.hpp" -#include "TestGetPlugin.hpp" -#include -#include -#include -#include - -using namespace sycl; - -struct HipCommandsTest : public ::testing::Test { - -protected: - std::optional &plugin = - pi::initializeAndGet(backend::ext_oneapi_hip); - - pi_platform platform_; - pi_device device_; - pi_context context_; - pi_queue queue_; - - void SetUp() override { - // skip the tests if the HIP backend is not available - if (!plugin.has_value()) { - GTEST_SKIP(); - } - - pi::clearHipContext(); - pi_uint32 numPlatforms = 0; - ASSERT_EQ(plugin->hasBackend(backend::ext_oneapi_hip), PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - 0, nullptr, &numPlatforms)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - numPlatforms, &platform_, nullptr)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - platform_, PI_DEVICE_TYPE_GPU, 1, &device_, nullptr)), - PI_SUCCESS); - ASSERT_EQ((plugin->call_nocheck( - nullptr, 1, &device_, nullptr, nullptr, &context_)), - PI_SUCCESS); - ASSERT_NE(context_, nullptr); - - ASSERT_EQ((plugin->call_nocheck( - context_, device_, 0, &queue_)), - PI_SUCCESS); - ASSERT_NE(queue_, nullptr); - auto tmpCtxt = queue_->get_context(); - ASSERT_EQ(tmpCtxt, context_); - } - - void TearDown() override { - if (plugin.has_value()) { - plugin->call(queue_); - plugin->call(context_); - } - } - - HipCommandsTest() = default; - - ~HipCommandsTest() = default; -}; - -TEST_F(HipCommandsTest, PIEnqueueReadBufferBlocking) { - constexpr const size_t memSize = 10u; - constexpr const size_t bytes = memSize * sizeof(int); - const int data[memSize] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - int output[memSize] = {}; - - pi_mem memObj; - ASSERT_EQ( - (plugin->call_nocheck( - context_, PI_MEM_FLAGS_ACCESS_RW, bytes, nullptr, &memObj, nullptr)), - PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - queue_, memObj, true, 0, bytes, data, 0, nullptr, nullptr)), - PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - queue_, memObj, true, 0, bytes, output, 0, nullptr, nullptr)), - PI_SUCCESS); - - bool isSame = - std::equal(std::begin(output), std::end(output), std::begin(data)); - EXPECT_TRUE(isSame); - if (!isSame) { - std::for_each(std::begin(output), std::end(output), - [](int &elem) { std::cout << elem << ","; }); - std::cout << std::endl; - } -} - -TEST_F(HipCommandsTest, PIEnqueueReadBufferNonBlocking) { - constexpr const size_t memSize = 10u; - constexpr const size_t bytes = memSize * sizeof(int); - const int data[memSize] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - int output[memSize] = {}; - - pi_mem memObj; - ASSERT_EQ( - (plugin->call_nocheck( - context_, PI_MEM_FLAGS_ACCESS_RW, bytes, nullptr, &memObj, nullptr)), - PI_SUCCESS); - - pi_event cpIn, cpOut; - ASSERT_EQ((plugin->call_nocheck( - queue_, memObj, false, 0, bytes, data, 0, nullptr, &cpIn)), - PI_SUCCESS); - ASSERT_NE(cpIn, nullptr); - - ASSERT_EQ((plugin->call_nocheck( - queue_, memObj, false, 0, bytes, output, 0, nullptr, &cpOut)), - PI_SUCCESS); - ASSERT_NE(cpOut, nullptr); - - ASSERT_EQ((plugin->call_nocheck(1, &cpOut)), - PI_SUCCESS); - - bool isSame = - std::equal(std::begin(output), std::end(output), std::begin(data)); - EXPECT_TRUE(isSame); - if (!isSame) { - std::for_each(std::begin(output), std::end(output), - [](int &elem) { std::cout << elem << ","; }); - std::cout << std::endl; - } -} diff --git a/sycl/unittests/pi/hip/test_contexts.cpp b/sycl/unittests/pi/hip/test_contexts.cpp deleted file mode 100644 index fa20e101d00e2..0000000000000 --- a/sycl/unittests/pi/hip/test_contexts.cpp +++ /dev/null @@ -1,250 +0,0 @@ -//==---- test_contexts.cpp --- PI unit tests -------------------------------==// -// -// Part of the LLVM Project, 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 "gtest/gtest.h" - -#include -#include -#include - -#include - -#include "HipUtils.hpp" -#include "TestGetPlugin.hpp" -#include -#include -#include -#include - -using namespace sycl; - -struct HipContextsTest : public ::testing::Test { - -protected: - std::optional &plugin = - pi::initializeAndGet(backend::ext_oneapi_hip); - - pi_platform platform_; - pi_device device_; - - void SetUp() override { - // skip the tests if the HIP backend is not available - if (!plugin.has_value()) { - GTEST_SKIP(); - } - - pi_uint32 numPlatforms = 0; - ASSERT_EQ(plugin->hasBackend(backend::ext_oneapi_hip), PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - 0, nullptr, &numPlatforms)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - numPlatforms, &platform_, nullptr)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - platform_, PI_DEVICE_TYPE_GPU, 1, &device_, nullptr)), - PI_SUCCESS); - } - - void TearDown() override {} - - HipContextsTest() = default; - - ~HipContextsTest() = default; -}; - -TEST_F(HipContextsTest, ContextLifetime) { - // start with no active context - pi::clearHipContext(); - - // create a context - pi_context context; - ASSERT_EQ((plugin->call_nocheck( - nullptr, 1, &device_, nullptr, nullptr, &context)), - PI_SUCCESS); - ASSERT_NE(context, nullptr); - - // create a queue from the context, this should use the ScopedContext - pi_queue queue; - ASSERT_EQ((plugin->call_nocheck( - context, device_, 0, &queue)), - PI_SUCCESS); - ASSERT_NE(queue, nullptr); - - // ensure the queue has the correct context - ASSERT_EQ(context, queue->get_context()); - - // check that the context is now the active HIP context - hipCtx_t hipCtxt = nullptr; - hipCtxGetCurrent(&hipCtxt); - ASSERT_EQ(hipCtxt, context->get()); - - plugin->call(queue); - plugin->call(context); - - // check that the context was cleaned up properly by the destructor - hipCtxGetCurrent(&hipCtxt); - ASSERT_EQ(hipCtxt, nullptr); -} - -TEST_F(HipContextsTest, ContextLifetimeExisting) { - // start by setting up a HIP context on the thread - hipCtx_t original; - hipCtxCreate(&original, hipDeviceMapHost, device_->get()); - - // ensure the HIP context is active - hipCtx_t current = nullptr; - hipCtxGetCurrent(¤t); - ASSERT_EQ(original, current); - - // create a PI context - pi_context context; - ASSERT_EQ((plugin->call_nocheck( - nullptr, 1, &device_, nullptr, nullptr, &context)), - PI_SUCCESS); - ASSERT_NE(context, nullptr); - - // create a queue from the context, this should use the ScopedContext - pi_queue queue; - ASSERT_EQ((plugin->call_nocheck( - context, device_, 0, &queue)), - PI_SUCCESS); - ASSERT_NE(queue, nullptr); - - // ensure the queue has the correct context - ASSERT_EQ(context, queue->get_context()); - - // check that the context is now the active HIP context - hipCtxGetCurrent(¤t); - ASSERT_EQ(current, context->get()); - - plugin->call(queue); - plugin->call(context); - - // check that the context was cleaned up, the old context will be restored - // automatically by hipCtxDestroy in piContextRelease, as it was pushed on the - // stack bu hipCtxCreate - hipCtxGetCurrent(¤t); - ASSERT_EQ(current, original); - - // release original context - hipCtxDestroy(original); -} - -// In some cases (for host_task), the SYCL runtime may call PI API functions -// from threads of the thread pool, this can cause issues because with the HIP -// plugin these functions will set an active HIP context on these threads, but -// never clean it up, as it will only get cleaned up in the main thread. -// -// So the following test aims to reproduce the scenario where there is a -// dangling deleted context in a separate thread and seeing if the PI calls are -// still able to work correctly in that thread. -TEST_F(HipContextsTest, ContextThread) { - // start with no active context - pi::clearHipContext(); - - // create two PI contexts - pi_context context1; - ASSERT_EQ((plugin->call_nocheck( - nullptr, 1, &device_, nullptr, nullptr, &context1)), - PI_SUCCESS); - ASSERT_NE(context1, nullptr); - - pi_context context2; - ASSERT_EQ((plugin->call_nocheck( - nullptr, 1, &device_, nullptr, nullptr, &context2)), - PI_SUCCESS); - ASSERT_NE(context2, nullptr); - - // setup synchronization variables between the main thread and the testing - // thread - std::mutex m; - std::condition_variable cv; - bool released = false; - bool thread_done = false; - - // create a testing thread that will create a queue with the first context, - // release the queue, then wait for the main thread to release the first - // context, and then create and release another queue with the second context - // this time - auto test_thread = std::thread([&] { - hipCtx_t current = nullptr; - - // create a queue with the first context - pi_queue queue; - ASSERT_EQ((plugin->call_nocheck( - context1, device_, 0, &queue)), - PI_SUCCESS); - ASSERT_NE(queue, nullptr); - - // ensure the queue has the correct context - ASSERT_EQ(context1, queue->get_context()); - - // check that the first context is now the active HIP context - hipCtxGetCurrent(¤t); - ASSERT_EQ(current, context1->get()); - - plugin->call(queue); - - // mark the first set of processing as done and notify the main thread - std::unique_lock lock(m); - thread_done = true; - lock.unlock(); - cv.notify_one(); - - // wait for the main thread to release the first context - lock.lock(); - cv.wait(lock, [&] { return released; }); - - // check that the first context is still active, this is because deleting a - // context only cleans up the current thread - hipCtxGetCurrent(¤t); - ASSERT_EQ(current, context1->get()); - - // create a queue with the second context - ASSERT_EQ((plugin->call_nocheck( - context2, device_, 0, &queue)), - PI_SUCCESS); - ASSERT_NE(queue, nullptr); - - // ensure the queue has the correct context - ASSERT_EQ(context2, queue->get_context()); - - // check that the second context is now the active HIP context - hipCtxGetCurrent(¤t); - ASSERT_EQ(current, context2->get()); - - plugin->call(queue); - }); - - // wait for the thread to be done with the first queue to release the first - // context - std::unique_lock lock(m); - cv.wait(lock, [&] { return thread_done; }); - plugin->call(context1); - - // notify the other thread that the context was released - released = true; - lock.unlock(); - cv.notify_one(); - - // wait for the thread to finish - test_thread.join(); - - plugin->call(context2); - - // check that there is no context set on the main thread - hipCtx_t current = nullptr; - hipCtxGetCurrent(¤t); - ASSERT_EQ(current, nullptr); -} diff --git a/sycl/unittests/pi/hip/test_device.cpp b/sycl/unittests/pi/hip/test_device.cpp deleted file mode 100644 index a2d61c6ee87fc..0000000000000 --- a/sycl/unittests/pi/hip/test_device.cpp +++ /dev/null @@ -1,111 +0,0 @@ -//==---- test_device.cpp --- PI unit tests ---------------------------------==// -// -// Part of the LLVM Project, 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 "gtest/gtest.h" - -#include - -#include "TestGetPlugin.hpp" -#include -#include -#include -#include - -using namespace sycl; - -struct HipDeviceTests : public ::testing::Test { - -protected: - std::optional &plugin = - pi::initializeAndGet(backend::ext_oneapi_hip); - - pi_platform platform_; - pi_device device_; - pi_context context_; - - void SetUp() override { - // skip the tests if the HIP backend is not available - if (!plugin.has_value()) { - GTEST_SKIP(); - } - - pi_uint32 numPlatforms = 0; - ASSERT_EQ(plugin->hasBackend(backend::ext_oneapi_hip), PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - 0, nullptr, &numPlatforms)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - numPlatforms, &platform_, nullptr)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - platform_, PI_DEVICE_TYPE_GPU, 1, &device_, nullptr)), - PI_SUCCESS); - ASSERT_EQ((plugin->call_nocheck( - nullptr, 1, &device_, nullptr, nullptr, &context_)), - PI_SUCCESS); - EXPECT_NE(context_, nullptr); - } - - void TearDown() override { - if (plugin.has_value()) { - plugin->call(device_); - plugin->call(context_); - } - } - - HipDeviceTests() = default; - ~HipDeviceTests() = default; -}; - -TEST_F(HipDeviceTests, PIDeviceGetInfoSimple) { - - size_t return_size = 0; - pi_device_type device_type; - ASSERT_EQ((plugin->call_nocheck( - device_, PI_DEVICE_INFO_TYPE, sizeof(pi_device_type), - &device_type, &return_size)), - PI_SUCCESS); - EXPECT_EQ(return_size, sizeof(pi_device_type)); - EXPECT_EQ( - device_type, - PI_DEVICE_TYPE_GPU); // backend pre-defined value, device must be a GPU - - pi_device parent_device = nullptr; - ASSERT_EQ((plugin->call_nocheck( - device_, PI_DEVICE_INFO_PARENT_DEVICE, sizeof(pi_device), - &parent_device, &return_size)), - PI_SUCCESS); - EXPECT_EQ(return_size, sizeof(pi_device)); - EXPECT_EQ(parent_device, - nullptr); // backend pre-set value, device cannot have a parent - - pi_platform platform = nullptr; - ASSERT_EQ((plugin->call_nocheck( - device_, PI_DEVICE_INFO_PLATFORM, sizeof(pi_platform), - &platform, &return_size)), - PI_SUCCESS); - EXPECT_EQ(return_size, sizeof(pi_platform)); - EXPECT_EQ(platform, platform_); // test fixture device was created from the - // test fixture platform - - cl_device_partition_property device_partition_property = -1; - ASSERT_EQ((plugin->call_nocheck( - device_, PI_DEVICE_INFO_PARTITION_TYPE, - sizeof(cl_device_partition_property), - &device_partition_property, &return_size)), - PI_SUCCESS); - EXPECT_EQ(device_partition_property, - 0); // PI HIP backend will not support device partitioning, this - // function should just return 0. - EXPECT_EQ(return_size, sizeof(cl_device_partition_property)); -} diff --git a/sycl/unittests/pi/hip/test_interop_get_native.cpp b/sycl/unittests/pi/hip/test_interop_get_native.cpp deleted file mode 100644 index 39e357430036b..0000000000000 --- a/sycl/unittests/pi/hip/test_interop_get_native.cpp +++ /dev/null @@ -1,127 +0,0 @@ -//==------- test_interop_get_native.cpp - SYCL HIP get_native tests --------==// -// -// Part of the LLVM Project, 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 "gtest/gtest.h" - -#include - -#include - -#include - -#include "TestGetPlatforms.hpp" - -#include - -using namespace sycl; - -struct HipInteropGetNativeTests : public ::testing::TestWithParam { - -protected: - std::unique_ptr syclQueue_; - device syclDevice_; - - void SetUp() override { - syclDevice_ = GetParam().get_devices()[0]; - syclQueue_ = std::unique_ptr{new queue{syclDevice_}}; - } - - void TearDown() override { syclQueue_.reset(); } -}; - -TEST_P(HipInteropGetNativeTests, getNativeDevice) { - hipDevice_t hipDevice = get_native(syclDevice_); - char hipDeviceName[2] = {0, 0}; - hipError_t result = hipDeviceGetName(hipDeviceName, 2, hipDevice); - ASSERT_EQ(result, PI_SUCCESS); - ASSERT_NE(hipDeviceName[0], 0); -} - -TEST_P(HipInteropGetNativeTests, getNativeContext) { - hipCtx_t hipContext = - get_native(syclQueue_->get_context()); - ASSERT_NE(hipContext, nullptr); -} - -TEST_P(HipInteropGetNativeTests, interopTaskGetMem) { - buffer syclBuffer(range<1>{1}); - syclQueue_->submit([&](handler &cgh) { - auto syclAccessor = syclBuffer.get_access(cgh); - cgh.host_task([=](interop_handle ih) { - hipDeviceptr_t hipPtr = - ih.get_native_mem(syclAccessor); - hipDeviceptr_t hipPtrBase; - size_t hipPtrSize = 0; - hipCtx_t hipContext = - get_native(syclQueue_->get_context()); - ASSERT_EQ(PI_SUCCESS, hipCtxPushCurrent(hipContext)); - ASSERT_EQ(PI_SUCCESS, - hipMemGetAddressRange(&hipPtrBase, &hipPtrSize, hipPtr)); - ASSERT_EQ(PI_SUCCESS, hipCtxPopCurrent(nullptr)); - ASSERT_EQ(sizeof(int), hipPtrSize); - }); - }); -} - -TEST_P(HipInteropGetNativeTests, interopTaskGetQueue) { - hipStream_t hipStream = get_native(*syclQueue_); - syclQueue_->submit([&](handler &cgh) { - cgh.host_task([=](interop_handle ih) { - hipStream_t hipInteropStream = - ih.get_native_queue(); - ASSERT_EQ(hipInteropStream, hipStream); - }); - }); -} - -TEST_P(HipInteropGetNativeTests, hostTaskGetNativeMem) { - buffer syclBuffer(range<1>{1}); - syclQueue_->submit([&](handler &cgh) { - auto syclAccessor = syclBuffer.get_access(cgh); - cgh.host_task([=](interop_handle ih) { - hipDeviceptr_t hipPtr = - ih.get_native_mem(syclAccessor); - hipDeviceptr_t hipPtrBase; - size_t hipPtrSize = 0; - hipCtx_t hipContext = - get_native(syclQueue_->get_context()); - ASSERT_EQ(PI_SUCCESS, hipCtxPushCurrent(hipContext)); - ASSERT_EQ(PI_SUCCESS, - hipMemGetAddressRange(&hipPtrBase, &hipPtrSize, hipPtr)); - ASSERT_EQ(PI_SUCCESS, hipCtxPopCurrent(nullptr)); - ASSERT_EQ(sizeof(int), hipPtrSize); - }); - }); -} - -TEST_P(HipInteropGetNativeTests, hostTaskGetNativeQueue) { - hipStream_t hipStream = get_native(*syclQueue_); - syclQueue_->submit([&](handler &cgh) { - cgh.host_task([=](interop_handle ih) { - hipStream_t hipInteropStream = - ih.get_native_queue(); - ASSERT_EQ(hipInteropStream, hipStream); - }); - }); -} - -TEST_P(HipInteropGetNativeTests, hostTaskGetNativeContext) { - hipCtx_t hipContext = - get_native(syclQueue_->get_context()); - syclQueue_->submit([&](handler &cgh) { - cgh.host_task([=](interop_handle ih) { - hipCtx_t hipInteropContext = - ih.get_native_context(); - ASSERT_EQ(hipInteropContext, hipContext); - }); - }); -} - -INSTANTIATE_TEST_SUITE_P( - OnHipPlatform, HipInteropGetNativeTests, - ::testing::ValuesIn(pi::getPlatformsWithName("HIP BACKEND"))); diff --git a/sycl/unittests/pi/hip/test_kernels.cpp b/sycl/unittests/pi/hip/test_kernels.cpp deleted file mode 100644 index 51463a5e23c29..0000000000000 --- a/sycl/unittests/pi/hip/test_kernels.cpp +++ /dev/null @@ -1,79 +0,0 @@ -//==---- test_kernels.cpp --- PI unit tests --------------------------------==// -// -// Part of the LLVM Project, 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 "gtest/gtest.h" - -#include - -#include "TestGetPlugin.hpp" -#include -#include -#include -#include - -// PI HIP kernels carry an additional argument for the implicit global offset. -#define NUM_IMPLICIT_ARGS 1 - -using namespace sycl; - -struct HipKernelsTest : public ::testing::Test { - -protected: - std::optional &plugin = - pi::initializeAndGet(backend::ext_oneapi_hip); - pi_platform platform_; - pi_device device_; - pi_context context_; - pi_queue queue_; - - void SetUp() override { - // skip the tests if the HIP backend is not available - if (!plugin.has_value()) { - GTEST_SKIP(); - } - - pi_uint32 numPlatforms = 0; - ASSERT_EQ(plugin->hasBackend(backend::ext_oneapi_hip), PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - 0, nullptr, &numPlatforms)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - numPlatforms, &platform_, nullptr)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - platform_, PI_DEVICE_TYPE_GPU, 1, &device_, nullptr)), - PI_SUCCESS); - ASSERT_EQ((plugin->call_nocheck( - nullptr, 1, &device_, nullptr, nullptr, &context_)), - PI_SUCCESS); - ASSERT_NE(context_, nullptr); - - ASSERT_EQ((plugin->call_nocheck( - context_, device_, 0, &queue_)), - PI_SUCCESS); - ASSERT_NE(queue_, nullptr); - ASSERT_EQ(queue_->get_context(), context_); - } - - void TearDown() override { - if (plugin.has_value()) { - plugin->call(device_); - plugin->call(queue_); - plugin->call(context_); - } - } - - HipKernelsTest() = default; - - ~HipKernelsTest() = default; -}; diff --git a/sycl/unittests/pi/hip/test_mem_obj.cpp b/sycl/unittests/pi/hip/test_mem_obj.cpp deleted file mode 100644 index 382a510bf97d9..0000000000000 --- a/sycl/unittests/pi/hip/test_mem_obj.cpp +++ /dev/null @@ -1,206 +0,0 @@ -//==---- test_mem_obj.cpp --- PI unit tests --------------------------------==// -// -// Part of the LLVM Project, 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 "gtest/gtest.h" - -#include - -#include "HipUtils.hpp" -#include "TestGetPlugin.hpp" -#include -#include -#include -#include - -using namespace sycl; - -struct HipTestMemObj : public ::testing::Test { - -protected: - std::optional &plugin = - pi::initializeAndGet(backend::ext_oneapi_hip); - - pi_platform platform_; - pi_device device_; - pi_context context_; - - void SetUp() override { - // skip the tests if the HIP backend is not available - if (!plugin.has_value()) { - GTEST_SKIP(); - } - - pi::clearHipContext(); - pi_uint32 numPlatforms = 0; - ASSERT_EQ(plugin->hasBackend(backend::ext_oneapi_hip), PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - 0, nullptr, &numPlatforms)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - numPlatforms, &platform_, nullptr)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - platform_, PI_DEVICE_TYPE_GPU, 1, &device_, nullptr)), - PI_SUCCESS); - ASSERT_EQ((plugin->call_nocheck( - nullptr, 1, &device_, nullptr, nullptr, &context_)), - PI_SUCCESS); - EXPECT_NE(context_, nullptr); - } - - void TearDown() override { - if (plugin.has_value()) { - plugin->call(device_); - plugin->call(context_); - } - } - - HipTestMemObj() = default; - - ~HipTestMemObj() = default; -}; - -TEST_F(HipTestMemObj, piMemBufferCreateSimple) { - const size_t memSize = 1024u; - pi_mem memObj; - ASSERT_EQ((plugin->call_nocheck( - context_, PI_MEM_FLAGS_ACCESS_RW, memSize, nullptr, &memObj, - nullptr)), - PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck(memObj)), - PI_SUCCESS); -} - -TEST_F(HipTestMemObj, piMemBufferAllocHost) { - const size_t memSize = 1024u; - pi_mem memObj; - ASSERT_EQ((plugin->call_nocheck( - context_, PI_MEM_FLAGS_ACCESS_RW | PI_MEM_FLAGS_HOST_PTR_ALLOC, - memSize, nullptr, &memObj, nullptr)), - PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck(memObj)), - PI_SUCCESS); -} - -TEST_F(HipTestMemObj, piMemBufferCreateNoActiveContext) { - const size_t memSize = 1024u; - // Context has been destroyed - - hipCtx_t current = nullptr; - - // pop HIP contexts until there is not a HIP context bound to the thread - do { - hipCtx_t oldContext = nullptr; - auto hipErr = hipCtxPopCurrent(&oldContext); - EXPECT_EQ(hipErr, PI_SUCCESS); - - // There should not be any active HIP context - hipErr = hipCtxGetCurrent(¤t); - ASSERT_EQ(hipErr, PI_SUCCESS); - } while (current != nullptr); - - // The context object is passed, even if its not active it should be used - // to allocate the memory object - pi_mem memObj; - ASSERT_EQ((plugin->call_nocheck( - context_, PI_MEM_FLAGS_ACCESS_RW, memSize, nullptr, &memObj, - nullptr)), - PI_SUCCESS); - ASSERT_NE(memObj, nullptr); - - ASSERT_EQ((plugin->call_nocheck(memObj)), - PI_SUCCESS); -} - -TEST_F(HipTestMemObj, piMemBufferPinnedMappedRead) { - const size_t memSize = sizeof(int); - const int value = 20; - - pi_queue queue; - ASSERT_EQ((plugin->call_nocheck( - context_, device_, 0, &queue)), - PI_SUCCESS); - ASSERT_NE(queue, nullptr); - ASSERT_EQ(queue->get_context(), context_); - - pi_mem memObj; - ASSERT_EQ((plugin->call_nocheck( - context_, PI_MEM_FLAGS_ACCESS_RW | PI_MEM_FLAGS_HOST_PTR_ALLOC, - memSize, nullptr, &memObj, nullptr)), - PI_SUCCESS); - - ASSERT_EQ( - (plugin->call_nocheck( - queue, memObj, true, 0, sizeof(int), &value, 0, nullptr, nullptr)), - PI_SUCCESS); - - int *host_ptr = nullptr; - ASSERT_EQ((plugin->call_nocheck( - queue, memObj, true, PI_MAP_READ, 0, sizeof(int), 0, nullptr, - nullptr, (void **)&host_ptr)), - PI_SUCCESS); - - ASSERT_EQ(*host_ptr, value); - - ASSERT_EQ((plugin->call_nocheck( - queue, memObj, host_ptr, 0, nullptr, nullptr)), - PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck(memObj)), - PI_SUCCESS); - plugin->call(queue); -} - -TEST_F(HipTestMemObj, piMemBufferPinnedMappedWrite) { - const size_t memSize = sizeof(int); - const int value = 30; - - pi_queue queue; - ASSERT_EQ((plugin->call_nocheck( - context_, device_, 0, &queue)), - PI_SUCCESS); - ASSERT_NE(queue, nullptr); - ASSERT_EQ(queue->get_context(), context_); - - pi_mem memObj; - ASSERT_EQ((plugin->call_nocheck( - context_, PI_MEM_FLAGS_ACCESS_RW | PI_MEM_FLAGS_HOST_PTR_ALLOC, - memSize, nullptr, &memObj, nullptr)), - PI_SUCCESS); - - int *host_ptr = nullptr; - ASSERT_EQ((plugin->call_nocheck( - queue, memObj, true, PI_MAP_WRITE, 0, sizeof(int), 0, nullptr, - nullptr, (void **)&host_ptr)), - PI_SUCCESS); - - *host_ptr = value; - - ASSERT_EQ((plugin->call_nocheck( - queue, memObj, host_ptr, 0, nullptr, nullptr)), - PI_SUCCESS); - - int read_value = 0; - ASSERT_EQ((plugin->call_nocheck( - queue, memObj, true, 0, sizeof(int), &read_value, 0, nullptr, - nullptr)), - PI_SUCCESS); - - ASSERT_EQ(read_value, value); - - ASSERT_EQ((plugin->call_nocheck(memObj)), - PI_SUCCESS); - plugin->call(queue); -} diff --git a/sycl/unittests/pi/hip/test_primary_context.cpp b/sycl/unittests/pi/hip/test_primary_context.cpp deleted file mode 100644 index 1ed80159d32d9..0000000000000 --- a/sycl/unittests/pi/hip/test_primary_context.cpp +++ /dev/null @@ -1,85 +0,0 @@ -//==---------- test_primary_context.cpp - PI unit tests --------------------==// -// -// Part of the LLVM Project, 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 "gtest/gtest.h" - -#include - -#include "TestGetPlatforms.hpp" -#include -#include -#include - -#include - -using namespace sycl; - -struct HipPrimaryContextTests : public ::testing::TestWithParam { - -protected: - device deviceA_; - device deviceB_; - - void SetUp() override { - std::vector HipDevices = GetParam().get_devices(); - - deviceA_ = HipDevices[0]; - deviceB_ = HipDevices.size() > 1 ? HipDevices[1] : deviceA_; - } - - void TearDown() override {} -}; - -TEST_P(HipPrimaryContextTests, piSingleContext) { - std::cout << "create single context" << std::endl; - context Context(deviceA_, async_handler{}); - - hipDevice_t HipDevice = get_native(deviceA_); - hipCtx_t HipContext = get_native(Context); - - hipCtx_t PrimaryHipContext; - hipDevicePrimaryCtxRetain(&PrimaryHipContext, HipDevice); - - ASSERT_EQ(HipContext, PrimaryHipContext); - - hipDevicePrimaryCtxRelease(HipDevice); -} - -TEST_P(HipPrimaryContextTests, piMultiContextSingleDevice) { - std::cout << "create multiple contexts for one device" << std::endl; - context ContextA(deviceA_, async_handler{}); - context ContextB(deviceA_, async_handler{}); - - hipCtx_t HipContextA = get_native(ContextA); - hipCtx_t HipContextB = get_native(ContextB); - - ASSERT_EQ(HipContextA, HipContextB); -} - -TEST_P(HipPrimaryContextTests, piMultiContextMultiDevice) { - if (deviceA_ == deviceB_) - return; - - hipDevice_t HipDeviceA = get_native(deviceA_); - hipDevice_t HipDeviceB = get_native(deviceB_); - - ASSERT_NE(HipDeviceA, HipDeviceB); - - std::cout << "create multiple contexts for multiple devices" << std::endl; - context ContextA(deviceA_, async_handler{}); - context ContextB(deviceB_, async_handler{}); - - hipCtx_t HipContextA = get_native(ContextA); - hipCtx_t HipContextB = get_native(ContextB); - - ASSERT_NE(HipContextA, HipContextB); -} - -INSTANTIATE_TEST_SUITE_P( - OnHipPlatform, HipPrimaryContextTests, - ::testing::ValuesIn(pi::getPlatformsWithName("HIP BACKEND"))); diff --git a/sycl/unittests/pi/hip/test_sampler_properties.cpp b/sycl/unittests/pi/hip/test_sampler_properties.cpp deleted file mode 100644 index bed0bb9b053a4..0000000000000 --- a/sycl/unittests/pi/hip/test_sampler_properties.cpp +++ /dev/null @@ -1,135 +0,0 @@ -//==---- test_sampler_properties.cpp --- PI unit tests ---------------------==// -// -// Part of the LLVM Project, 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 "gtest/gtest.h" - -#include "TestGetPlugin.hpp" -#include -#include -#include - -#include - -namespace { - -using namespace sycl; - -class SamplerPropertiesTest - : public ::testing::TestWithParam> { -protected: - std::optional &plugin = - pi::initializeAndGet(backend::ext_oneapi_hip); - - pi_platform platform_; - pi_device device_; - pi_context context_; - pi_sampler sampler_; - - pi_bool normalizedCoords_; - pi_sampler_filter_mode filterMode_; - pi_sampler_addressing_mode addressMode_; - - SamplerPropertiesTest() = default; - - ~SamplerPropertiesTest() override = default; - - void SetUp() override { - // skip the tests if the HIP backend is not available - if (!plugin.has_value()) { - GTEST_SKIP(); - } - - std::tie(normalizedCoords_, filterMode_, addressMode_) = GetParam(); - - pi_uint32 numPlatforms = 0; - ASSERT_EQ(plugin->hasBackend(backend::ext_oneapi_hip), PI_SUCCESS); - - ASSERT_EQ((plugin->call_nocheck( - 0, nullptr, &numPlatforms)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - numPlatforms, &platform_, nullptr)), - PI_SUCCESS) - << "piPlatformsGet failed.\n"; - - ASSERT_EQ((plugin->call_nocheck( - platform_, PI_DEVICE_TYPE_GPU, 1, &device_, nullptr)), - PI_SUCCESS); - ASSERT_EQ((plugin->call_nocheck( - nullptr, 1, &device_, nullptr, nullptr, &context_)), - PI_SUCCESS); - EXPECT_NE(context_, nullptr); - - pi_sampler_properties sampler_properties[] = { - PI_SAMPLER_PROPERTIES_NORMALIZED_COORDS, - static_cast(normalizedCoords_), - PI_SAMPLER_PROPERTIES_ADDRESSING_MODE, - static_cast(addressMode_), - PI_SAMPLER_PROPERTIES_FILTER_MODE, - static_cast(filterMode_), - 0}; - - ASSERT_EQ((plugin->call_nocheck( - context_, sampler_properties, &sampler_)), - PI_SUCCESS); - } - - void TearDown() override { - if (plugin.has_value()) { - plugin->call(sampler_); - plugin->call(device_); - plugin->call(context_); - } - } -}; - -TEST_P(SamplerPropertiesTest, piCheckNormalizedCoords) { - pi_bool actualNormalizedCoords = !normalizedCoords_; - - plugin->call( - sampler_, PI_SAMPLER_INFO_NORMALIZED_COORDS, sizeof(pi_bool), - &actualNormalizedCoords, nullptr); - - ASSERT_EQ(actualNormalizedCoords, normalizedCoords_); -} - -TEST_P(SamplerPropertiesTest, piCheckFilterMode) { - pi_sampler_filter_mode actualFilterMode; - - plugin->call( - sampler_, PI_SAMPLER_INFO_FILTER_MODE, sizeof(pi_sampler_filter_mode), - &actualFilterMode, nullptr); - - ASSERT_EQ(actualFilterMode, filterMode_); -} - -TEST_P(SamplerPropertiesTest, piCheckAddressingMode) { - pi_sampler_addressing_mode actualAddressMode; - - plugin->call( - sampler_, PI_SAMPLER_INFO_ADDRESSING_MODE, - sizeof(pi_sampler_addressing_mode), &actualAddressMode, nullptr); - - ASSERT_EQ(actualAddressMode, addressMode_); -} - -INSTANTIATE_TEST_SUITE_P( - SamplerPropertiesTestImpl, SamplerPropertiesTest, - ::testing::Combine( - ::testing::Values(PI_TRUE, PI_FALSE), - ::testing::Values(PI_SAMPLER_FILTER_MODE_LINEAR, - PI_SAMPLER_FILTER_MODE_NEAREST), - ::testing::Values(PI_SAMPLER_ADDRESSING_MODE_CLAMP, - PI_SAMPLER_ADDRESSING_MODE_CLAMP_TO_EDGE, - PI_SAMPLER_ADDRESSING_MODE_NONE, - PI_SAMPLER_ADDRESSING_MODE_MIRRORED_REPEAT, - PI_SAMPLER_ADDRESSING_MODE_REPEAT))); -} // namespace