diff --git a/projects/hip-tests/catch/CMakeLists.txt b/projects/hip-tests/catch/CMakeLists.txt index 451d4ddef3..a10d61a678 100644 --- a/projects/hip-tests/catch/CMakeLists.txt +++ b/projects/hip-tests/catch/CMakeLists.txt @@ -24,7 +24,22 @@ if(NOT DEFINED HIP_PATH) endif() message(STATUS "HIP Path: ${HIP_PATH}") -set(CMAKE_CXX_COMPILER "${HIP_PATH}/bin/hipcc") +if(UNIX) + set(CMAKE_CXX_COMPILER "${HIP_PATH}/bin/hipcc") + set(CMAKE_C_COMPILER "${HIP_PATH}/bin/hipcc") +else() + # using cmake_path as it handles path correctly. + # Set both compilers else windows cmake complains of mismatch + cmake_path(SET CMAKE_CXX_COMPILER "${HIP_PATH}/bin/hipcc.bat") + cmake_path(SET CMAKE_C_COMPILER "${HIP_PATH}/bin/hipcc.bat") +endif() + + +if(NOT UNIX) + # In linux this reruns the cmake and fails with incorrect vars. + # so the project command is used only for windows + project(build_tests) +endif() if(NOT DEFINED CATCH2_PATH) if(DEFINED ENV{CATCH2_PATH}) @@ -118,10 +133,10 @@ add_subdirectory(unit) add_subdirectory(ABM) add_subdirectory(hipTestMain) add_subdirectory(stress) -add_subdirectory(TypeQualifiers) if(UNIX) add_subdirectory(multiproc) + add_subdirectory(TypeQualifiers) endif() cmake_policy(POP) diff --git a/projects/hip-tests/catch/hipTestMain/hip_test_context.cc b/projects/hip-tests/catch/hipTestMain/hip_test_context.cc index 7c8ec946ee..dd440ce153 100644 --- a/projects/hip-tests/catch/hipTestMain/hip_test_context.cc +++ b/projects/hip-tests/catch/hipTestMain/hip_test_context.cc @@ -2,18 +2,8 @@ #include #include #include - -#if __has_include() -#include -namespace fs = std::filesystem; -#elif __has_include() -#include -namespace fs = std::experimental::filesystem; -#else -#error "gg filesystem" -#endif - #include +#include "hip_test_filesystem.hh" void TestContext::detectOS() { #if (HT_WIN == 1) @@ -49,7 +39,7 @@ void TestContext::fillConfig() { if (config_path.has_parent_path() && config_path.has_filename()) { config_.json_file = config_str; } else if (config_path.has_parent_path()) { - config_.json_file = config_path / def_config_json; + config_.json_file = config_path.string() + def_config_json; } else { config_.json_file = exe_path + def_config_json; } diff --git a/projects/hip-tests/catch/include/hip_test_common.hh b/projects/hip-tests/catch/include/hip_test_common.hh index a7e09a392b..68817ef1c2 100644 --- a/projects/hip-tests/catch/include/hip_test_common.hh +++ b/projects/hip-tests/catch/include/hip_test_common.hh @@ -23,6 +23,7 @@ THE SOFTWARE. #pragma once #include "hip_test_context.hh" #include +#include #define HIP_PRINT_STATUS(status) INFO(hipGetErrorName(status) << " at line: " << __LINE__); @@ -105,4 +106,13 @@ static inline unsigned setNumBlocks(unsigned blocksPerCU, unsigned threadsPerBlo return blocks; } +static inline int RAND_R(unsigned* rand_seed) +{ + #if defined(_WIN32) || defined(_WIN64) + srand(*rand_seed); + return rand(); + #else + return rand_r(rand_seed); + #endif +} } diff --git a/projects/hip-tests/catch/include/hip_test_filesystem.hh b/projects/hip-tests/catch/include/hip_test_filesystem.hh new file mode 100644 index 0000000000..fffda4146b --- /dev/null +++ b/projects/hip-tests/catch/include/hip_test_filesystem.hh @@ -0,0 +1,89 @@ + +/* +Copyright (c) 2021 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#pragma once +// We haven't checked which filesystem to include yet +#ifndef INCLUDE_STD_FILESYSTEM_EXPERIMENTAL +// Check for feature test macro for +#if defined(__cpp_lib_filesystem) +#define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0 +// Check for feature test macro for +#elif defined(__cpp_lib_experimental_filesystem) +#define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1 +// We can't check if headers exist... +// Let's assume experimental to be safe +#elif !defined(__has_include) +#define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1 +// Check if the header "" exists +#elif __has_include() +// If we're compiling on Visual Studio and are not compiling with C++17, +// we need to use experimental +#ifdef _MSC_VER +// Check and include header that defines "_HAS_CXX17" +#if __has_include() +#include + +// Check for enabled C++17 support +#if defined(_HAS_CXX17) && _HAS_CXX17 +// We're using C++17, so let's use the normal version +#define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0 +#endif + +#endif + +// If the marco isn't defined yet, that means any of the other +// VS specific checks failed, so we need to use experimental +#ifndef INCLUDE_STD_FILESYSTEM_EXPERIMENTAL +#define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1 +#endif + +// Not on Visual Studio. Let's use the normal version +#else // #ifdef _MSC_VER +#define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0 +#endif + +// Check if the header "" exists +#elif __has_include() +#define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1 + +// Fail if neither header is available with a nice error message +#else +#error Could not find system header "" || + "" +#endif + +// We priously determined that we need the exprimental version +#if INCLUDE_STD_FILESYSTEM_EXPERIMENTAL +// Include it +#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING 1; +#include +// We need the alias from std::experimental::filesystem to std::filesystem +namespace fs = std::experimental::filesystem; +// We have a decent compiler and can use the normal version +#else +// Include it +#include +namespace fs = std::filesystem; +#endif + +#endif // #ifndef INCLUDE_STD_FILESYSTEM_EXPERIMENTAL \ No newline at end of file diff --git a/projects/hip-tests/catch/include/hip_test_helper.hh b/projects/hip-tests/catch/include/hip_test_helper.hh index add9e40229..04aec9318b 100644 --- a/projects/hip-tests/catch/include/hip_test_helper.hh +++ b/projects/hip-tests/catch/include/hip_test_helper.hh @@ -25,6 +25,9 @@ THE SOFTWARE. #ifdef __linux__ #include +#else + #include + #include #endif namespace HipTest { diff --git a/projects/hip-tests/catch/include/hip_test_process.hh b/projects/hip-tests/catch/include/hip_test_process.hh index b345425405..665f5d6b97 100644 --- a/projects/hip-tests/catch/include/hip_test_process.hh +++ b/projects/hip-tests/catch/include/hip_test_process.hh @@ -29,16 +29,7 @@ THE SOFTWARE. #include #include #include - -#if __has_include() -#include -namespace fs = std::filesystem; -#elif __has_include() -#include -namespace fs = std::experimental::filesystem; -#else -#error "gg filesystem" -#endif +#include "hip_test_filesystem.hh" namespace hip { class SpawnProc { diff --git a/projects/hip-tests/catch/unit/deviceLib/CMakeLists.txt b/projects/hip-tests/catch/unit/deviceLib/CMakeLists.txt index 04c125c7a9..347e6d73c9 100644 --- a/projects/hip-tests/catch/unit/deviceLib/CMakeLists.txt +++ b/projects/hip-tests/catch/unit/deviceLib/CMakeLists.txt @@ -9,12 +9,18 @@ set(TEST_SRC brev.cc popc.cc ldg.cc - syncthreadsand.cc - syncthreadscount.cc - syncthreadsor.cc threadfence_system.cc ) +# skipped for windows compiler issue - Illegal instruction detected +if(UNIX) + set(TEST_SRC ${TEST_SRC} + syncthreadsand.cc + syncthreadscount.cc + syncthreadsor.cc) +endif() + + # AMD only tests set(AMD_TEST_SRC unsafeAtomicAdd.cc diff --git a/projects/hip-tests/catch/unit/event/CMakeLists.txt b/projects/hip-tests/catch/unit/event/CMakeLists.txt index fae1b4264c..6b6ef7c3c4 100644 --- a/projects/hip-tests/catch/unit/event/CMakeLists.txt +++ b/projects/hip-tests/catch/unit/event/CMakeLists.txt @@ -3,10 +3,15 @@ set(TEST_SRC Unit_hipEvent_Negative.cc Unit_hipEvent.cc Unit_hipEventElapsedTime.cc - Unit_hipEventRecord.cc - Unit_hipEventIpc.cc ) +# skipped for windows due to duplicate symbols +if(UNIX) + set(TEST_SRC ${TEST_SRC} + Unit_hipEventRecord.cc + Unit_hipEventIpc.cc) +endif() + hip_add_exe_to_target(NAME EventTest TEST_SRC ${TEST_SRC} TEST_TARGET_NAME build_tests) diff --git a/projects/hip-tests/catch/unit/memory/CMakeLists.txt b/projects/hip-tests/catch/unit/memory/CMakeLists.txt index 8e984c2300..b450921321 100644 --- a/projects/hip-tests/catch/unit/memory/CMakeLists.txt +++ b/projects/hip-tests/catch/unit/memory/CMakeLists.txt @@ -5,8 +5,6 @@ set(TEST_SRC malloc.cc hipMemcpy2DToArray.cc hipMemcpy2DToArrayAsync.cc - hipMemcpyPeer.cc - hipMemcpyPeerAsync.cc hipMemcpy3D.cc hipMemcpy3DAsync.cc hipMemcpyParam2D.cc @@ -17,37 +15,25 @@ set(TEST_SRC hipMemcpy2DFromArrayAsync.cc hipMemcpyAtoH.cc hipMemcpyHtoA.cc - hipMemcpyDtoD.cc - hipMemcpyDtoDAsync.cc - hipMemcpyAsync.cc - hipMemcpy.cc - hipMemcpyWithStream.cc hipMemcpyAllApiNegative.cc - hipMemcpyWithStreamMultiThread.cc hipMemcpy_MultiThread.cc - hipHostMalloc.cc hipHostRegister.cc hipMemPtrGetInfo.cc hipPointerGetAttributes.cc hipHostGetFlags.cc - hipMemoryAllocateCoherent.cc hipMallocManaged_MultiScenario.cc hipMemsetInvalidPtr.cc hipMemset.cc hipMemsetAsyncMultiThread.cc - hipMemsetAsyncAndKernel.cc hipMemset3D.cc hipMemset2D.cc - hipMemset2DAsyncMultiThreadAndKernel.cc hipHostMallocTests.cc - hipMallocConcurrency.cc hipMemset3DFunctional.cc hipMemset3DNegative.cc hipMemset3DRegressMultiThread.cc hipMallocManagedFlagsTst.cc hipMemPrefetchAsyncExtTsts.cc hipMemAdviseMmap.cc - hipMallocManaged.cc hipMemCoherencyTst.cc ) else() @@ -56,8 +42,6 @@ set(TEST_SRC malloc.cc hipMemcpy2DToArray.cc hipMemcpy2DToArrayAsync.cc - hipMemcpyPeer.cc - hipMemcpyPeerAsync.cc hipMemcpy3D.cc hipMemcpy3DAsync.cc hipMemcpyParam2D.cc @@ -68,39 +52,45 @@ set(TEST_SRC hipMemcpy2DFromArrayAsync.cc hipMemcpyAtoH.cc hipMemcpyHtoA.cc - hipMemcpyDtoD.cc - hipMemcpyDtoDAsync.cc - hipMemcpyAsync.cc - hipMemcpy.cc - hipMemcpyWithStream.cc hipMemcpyAllApiNegative.cc - hipMemcpyWithStreamMultiThread.cc hipMemcpy_MultiThread.cc - hipHostMalloc.cc hipHostRegister.cc hipHostGetFlags.cc - hipMemoryAllocateCoherent.cc hipMallocManaged_MultiScenario.cc hipMemsetInvalidPtr.cc hipMemset.cc hipMemsetAsyncMultiThread.cc - hipMemsetAsyncAndKernel.cc hipMemset3D.cc hipMemset2D.cc - hipMemset2DAsyncMultiThreadAndKernel.cc hipHostMallocTests.cc - hipMallocConcurrency.cc hipMemset3DFunctional.cc hipMemset3DNegative.cc hipMemset3DRegressMultiThread.cc hipMallocManagedFlagsTst.cc hipMemPrefetchAsyncExtTsts.cc hipMemAdviseMmap.cc - hipMallocManaged.cc - hipMemCoherencyTst.cc ) endif() +#skipped in windows -duplicate HipTest::vectorADD sym (compiler issue) +if(UNIX) + set(TEST_SRC ${TEST_SRC} + hipMemcpyPeer.cc + hipMemcpyPeerAsync.cc + hipMemcpyWithStream.cc + hipMemcpyWithStreamMultiThread.cc + hipMemsetAsyncAndKernel.cc + hipMemset2DAsyncMultiThreadAndKernel.cc + hipMallocManaged.cc + hipMallocConcurrency.cc + hipMemcpyDtoD.cc + hipMemcpyDtoDAsync.cc + hipMemoryAllocateCoherent.cc + hipHostMalloc.cc + hipMemcpy.cc + hipMemcpyAsync.cc) +endif() + hip_add_exe_to_target(NAME MemoryTest TEST_SRC ${TEST_SRC} TEST_TARGET_NAME build_tests) diff --git a/projects/hip-tests/catch/unit/memory/hipMemcpy.cc b/projects/hip-tests/catch/unit/memory/hipMemcpy.cc index 8063857812..f6343e52fc 100644 --- a/projects/hip-tests/catch/unit/memory/hipMemcpy.cc +++ b/projects/hip-tests/catch/unit/memory/hipMemcpy.cc @@ -572,7 +572,7 @@ TEMPLATE_TEST_CASE("Unit_hipMemcpy_PinnedRegMemWithKernelLaunch", HipTest::checkVectorADD(A_h, B_h, C_h, NUM_ELM); unsigned int seed = time(0); - HIP_CHECK(hipSetDevice(rand_r(&seed) % (numDevices-1)+1)); + HIP_CHECK(hipSetDevice(HipTest::RAND_R(&seed) % (numDevices-1)+1)); int device; hipGetDevice(&device); diff --git a/projects/hip-tests/catch/unit/memory/hipMemcpyAsync.cc b/projects/hip-tests/catch/unit/memory/hipMemcpyAsync.cc index a7e327354d..be5eb26b73 100644 --- a/projects/hip-tests/catch/unit/memory/hipMemcpyAsync.cc +++ b/projects/hip-tests/catch/unit/memory/hipMemcpyAsync.cc @@ -350,7 +350,7 @@ TEMPLATE_TEST_CASE("Unit_hipMemcpyAsync_PinnedRegMemWithKernelLaunch", HipTest::checkVectorADD(A_h, B_h, C_h, NUM_ELM); unsigned int seed = time(0); - HIP_CHECK(hipSetDevice(rand_r(&seed) % (numDevices-1)+1)); + HIP_CHECK(hipSetDevice(HipTest::RAND_R(&seed) % (numDevices-1)+1)); int device; HIP_CHECK(hipGetDevice(&device)); diff --git a/projects/hip-tests/catch/unit/memory/hipMemset3DFunctional.cc b/projects/hip-tests/catch/unit/memory/hipMemset3DFunctional.cc index 421e066ab4..b47798487b 100644 --- a/projects/hip-tests/catch/unit/memory/hipMemset3DFunctional.cc +++ b/projects/hip-tests/catch/unit/memory/hipMemset3DFunctional.cc @@ -236,7 +236,7 @@ static void seekAndSet3DArraySlice(bool bAsync) { // select random slice for memset unsigned int seed = time(nullptr); - int slice_index = rand_r(&seed) % ZSIZE_S; + int slice_index = HipTest::RAND_R(&seed) % ZSIZE_S; INFO("memset3d for sliceindex " << slice_index); diff --git a/projects/hip-tests/catch/unit/memory/hipPointerGetAttributes.cc b/projects/hip-tests/catch/unit/memory/hipPointerGetAttributes.cc index b14ea9858e..4db534c223 100644 --- a/projects/hip-tests/catch/unit/memory/hipPointerGetAttributes.cc +++ b/projects/hip-tests/catch/unit/memory/hipPointerGetAttributes.cc @@ -148,7 +148,7 @@ void clusterAllocs(int numAllocs, size_t minSize, size_t maxSize) { } for (int i = 0; i < numAllocs; i++) { unsigned rand_seed = time(NULL); - bool isDevice = rand_r(&rand_seed) & 0x1; + bool isDevice = HipTest::RAND_R(&rand_seed) & 0x1; reference[i]._sizeBytes = zrand(maxSize - minSize) + minSize; reference[i]._attrib.device = zrand(numDevices); diff --git a/projects/hip-tests/catch/unit/stream/CMakeLists.txt b/projects/hip-tests/catch/unit/stream/CMakeLists.txt index 9b4daf549b..fc528f2b72 100644 --- a/projects/hip-tests/catch/unit/stream/CMakeLists.txt +++ b/projects/hip-tests/catch/unit/stream/CMakeLists.txt @@ -4,14 +4,20 @@ set(TEST_SRC hipStreamGetFlags.cc hipStreamGetPriority.cc hipMultiStream.cc - hipStreamACb_MultiThread.cc hipStreamAddCallback.cc hipStreamCreateWithFlags.cc hipStreamCreateWithPriority.cc - hipStreamWithCUMask.cc hipStreamGetCUMask.cc hipAPIStreamDisable.cc ) + +#skipped in windows - duplicate HipTest::vector_square sym (compiler issue) +if(UNIX) + set(TEST_SRC ${TEST_SRC} + hipStreamWithCUMask.cc + hipStreamACb_MultiThread.cc) +endif() + else() set(TEST_SRC hipStreamCreate.cc diff --git a/projects/hip-tests/catch/unit/stream/hipStreamAddCallback.cc b/projects/hip-tests/catch/unit/stream/hipStreamAddCallback.cc index bc16eda3bd..b03aede98b 100644 --- a/projects/hip-tests/catch/unit/stream/hipStreamAddCallback.cc +++ b/projects/hip-tests/catch/unit/stream/hipStreamAddCallback.cc @@ -26,7 +26,8 @@ Testcase Scenarios : #include #include -#include +#include +#include #define UNUSED(expr) do { (void)(expr); } while (0) @@ -89,7 +90,7 @@ bool testStreamCallbackFunctionality(bool isDefault) { HIP_CHECK(hipMemcpyAsync(C_h, C_d, Nbytes, hipMemcpyDeviceToHost, 0)); HIP_CHECK(hipStreamAddCallback(0, Callback, nullptr, 0)); - while (!gcbDone) usleep(100000); // Sleep for 100 ms + while (!gcbDone) std::this_thread::sleep_for(std::chrono::microseconds(100000)); // Sleep for 100 ms } else { hipStream_t mystream; HIP_CHECK(hipStreamCreateWithFlags(&mystream, hipStreamNonBlocking)); @@ -105,7 +106,7 @@ bool testStreamCallbackFunctionality(bool isDefault) { HIP_CHECK(hipMemcpyAsync(C_h, C_d, Nbytes, hipMemcpyDeviceToHost, mystream)); HIP_CHECK(hipStreamAddCallback(mystream, Callback, nullptr, 0)); - while (!gcbDone) usleep(100000); // Sleep for 100 ms + while (!gcbDone) std::this_thread::sleep_for(std::chrono::microseconds(100000)); // Sleep for 100 ms HIP_CHECK(hipStreamDestroy(mystream)); } HIP_CHECK(hipFree(reinterpret_cast(C_d))); @@ -192,7 +193,7 @@ TEST_CASE("Unit_hipStreamAddCallback_ParamTst") { HIP_CHECK(hipStreamAddCallback(mystream, Callback_ChkUsrdataPtr, gusrptr, 0)); while (!gcbDone) { - usleep(100000); // Sleep for 100 ms + std::this_thread::sleep_for(std::chrono::microseconds(100000)); // Sleep for 100 ms } REQUIRE_FALSE(!gPassed); } @@ -204,7 +205,7 @@ TEST_CASE("Unit_hipStreamAddCallback_ParamTst") { HIP_CHECK(hipStreamAddCallback(mystream, Callback_ChkStreamValue, nullptr, 0)); while (!gcbDone) { - usleep(100000); // Sleep for 100 ms + std::this_thread::sleep_for(std::chrono::microseconds(100000)); // Sleep for 100 ms } REQUIRE_FALSE(!gPassed); } diff --git a/projects/hip-tests/catch/unit/stream/hipStreamWithCUMask.cc b/projects/hip-tests/catch/unit/stream/hipStreamWithCUMask.cc index 0dd855702d..b65cdc4ca1 100644 --- a/projects/hip-tests/catch/unit/stream/hipStreamWithCUMask.cc +++ b/projects/hip-tests/catch/unit/stream/hipStreamWithCUMask.cc @@ -36,7 +36,8 @@ are ignored and hipExtStreamCreateWithCUMask must return hipSuccess. #include #include -#include +#include +#include #include #include @@ -159,7 +160,7 @@ TEST_CASE("Unit_hipExtStreamCreateWithCUMask_ValidateCallbackFunc") { HIP_CHECK(hipMemcpyAsync(C_h, C_d, Nbytes, hipMemcpyDeviceToHost, mystream)); HIP_CHECK(hipStreamAddCallback(mystream, Callback, nullptr, 0)); - while (!cbDone) usleep(100000); // Sleep for 100 ms + while (!cbDone) std::this_thread::sleep_for(std::chrono::microseconds(100000)); // Sleep for 100 ms HIP_CHECK(hipStreamDestroy(mystream)); HIP_CHECK(hipFree(reinterpret_cast(C_d))); HIP_CHECK(hipFree(reinterpret_cast(A_d)));