diff --git a/core/test/gtest/environments.hpp b/core/test/gtest/environments.hpp index 856763d4105..125fa7b9b8b 100644 --- a/core/test/gtest/environments.hpp +++ b/core/test/gtest/environments.hpp @@ -30,8 +30,8 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *************************************************************/ -#ifndef GINKGO_ENVIRONMENTS_HPP -#define GINKGO_ENVIRONMENTS_HPP +#ifndef GKO_CORE_TEST_GTEST_ENVIRONMENTS_HPP_ +#define GKO_CORE_TEST_GTEST_ENVIRONMENTS_HPP_ #include #include @@ -55,6 +55,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endif +#if GKO_COMPILING_DPCPP +#include "dpcpp/base/device.hpp" +#endif + + #include #include #include @@ -111,8 +116,11 @@ class ResourceEnvironment : public ::testing::Environment { auto rs_count_env = std::getenv("CTEST_RESOURCE_GROUP_COUNT"); auto rs_count = rs_count_env ? std::stoi(rs_count_env) : 0; if (rs_count == 0) { - std::cerr << "Running without CTest ctest_resource configuration" - << std::endl; + if (rank == 0) { + std::cerr + << "Running without CTest ctest_resource configuration" + << std::endl; + } return; } if (rs_count != size) { @@ -121,38 +129,25 @@ class ResourceEnvironment : public ::testing::Environment { } // parse CTest ctest_resource group descriptions - if (rank == 0) { - std::cerr << "Running with CTest ctest_resource configuration:" - << std::endl; - } // OpenMP CPU threads if (auto rs_omp_env = get_ctest_group("cpu", rank)) { auto resource = parse_ctest_resources(rs_omp_env); omp_threads = resource.slots; - if (rank == 0) { - std::cerr << omp_threads << " CPU threads" << std::endl; - } } // CUDA GPUs if (auto rs_cuda_env = get_ctest_group("cudagpu", rank)) { auto resource = parse_ctest_resources(rs_cuda_env); cuda_device_id = resource.id; - std::cerr << "Rank " << rank << ": CUDA device " << cuda_device_id - << std::endl; } // HIP GPUs if (auto rs_hip_env = get_ctest_group("hipgpu", rank)) { auto resource = parse_ctest_resources(rs_hip_env); hip_device_id = resource.id; - std::cerr << "Rank " << rank << ": HIP device " << cuda_device_id - << std::endl; } // SYCL GPUs (no other devices!) if (auto rs_sycl_env = get_ctest_group("syclgpu", rank)) { auto resource = parse_ctest_resources(rs_sycl_env); sycl_device_id = resource.id; - std::cerr << "Rank " << rank << ": SYCL device " << cuda_device_id - << std::endl; } } @@ -167,18 +162,31 @@ class ResourceEnvironment : public ::testing::Environment { class OmpEnvironment : public ::testing::Environment { public: + explicit OmpEnvironment(int rank) : rank_(rank) {} + void SetUp() override { if (ResourceEnvironment::omp_threads > 0) { - omp_set_num_threads(ResourceEnvironment::omp_threads); + omp_set_num_threads(num_threads); } +#pragma omp parallel +#pragma single + std::cerr << "Rank " << rank_ << ": OMP threads " + << omp_get_num_threads(); + << std::endl; } + +private: + int rank_; }; #else -class OmpEnvironment : public ::testing::Environment {}; +class OmpEnvironment : public ::testing::Environment { +public: + explicit OmpEnvironment(int){}; +}; #endif @@ -187,15 +195,31 @@ class OmpEnvironment : public ::testing::Environment {}; class CudaEnvironment : public ::testing::Environment { public: + explicit CudaEnvironment(int rank) : rank_(rank) {} + + void SetUp() override + { + auto device_id = ResourceEnvironment::cuda_device_id; + std::cerr << "Rank " << rank_ << ": CUDA device " + << gko::kernels::cuda::get_device_name(device_id) << " ID " + << device_id << std::endl; + } + void TearDown() override { gko::kernels::cuda::reset_device(ResourceEnvironment::cuda_device_id); } + +private: + int rank_; }; #else -class CudaEnvironment : public ::testing::Environment {}; +class CudaEnvironment : public ::testing::Environment { +public: + explicit CudaEnvironment(int){}; +}; #endif @@ -204,17 +228,61 @@ class CudaEnvironment : public ::testing::Environment {}; class HipEnvironment : public ::testing::Environment { public: + explicit HipEnvironment(int rank) : rank_(rank) {} + + void SetUp() override + { + auto device_id = ResourceEnvironment::hip_device_id; + std::cerr << "Rank " << rank_ << ": HIP device " + << gko::kernels::hip::get_device_name(device_id) << " ID " + << device_id << std::endl; + } + void TearDown() override { gko::kernels::hip::reset_device(ResourceEnvironment::hip_device_id); } + +private: + int rank_; +}; + +#else + +class HipEnvironment : public ::testing::Environment { +public: + explicit HipEnvironment(int){}; +}; + +#endif + + +#ifdef GKO_COMPILING_DPCPP + +class SyclEnvironment : public ::testing::Environment { +public: + explicit SyclEnvironment(int rank) : rank_(rank) {} + + void SetUp() override + { + auto device_id = ResourceEnvironment::sycl_device_id; + std::cerr << "Rank " << rank_ << ": SYCL device " + << gko::kernels::dpcpp::get_device_name(device_id) << " ID " + << device_id << std::endl; + } + +private: + int rank_; }; #else -class HipEnvironment : public ::testing::Environment {}; +class SyclEnvironment : public ::testing::Environment { +public: + explicit SyclEnvironment(int){}; +}; #endif -#endif // GINKGO_ENVIRONMENTS_HPP +#endif // GKO_CORE_TEST_GTEST_ENVIRONMENTS_HPP_ diff --git a/core/test/gtest/ginkgo_main.cpp b/core/test/gtest/ginkgo_main.cpp index 4d69b421875..01d1fc393c3 100644 --- a/core/test/gtest/ginkgo_main.cpp +++ b/core/test/gtest/ginkgo_main.cpp @@ -47,9 +47,10 @@ int main(int argc, char** argv) ::testing::InitGoogleTest(&argc, argv); ::testing::AddGlobalTestEnvironment(new ResourceEnvironment); - ::testing::AddGlobalTestEnvironment(new CudaEnvironment); - ::testing::AddGlobalTestEnvironment(new HipEnvironment); - ::testing::AddGlobalTestEnvironment(new OmpEnvironment); + ::testing::AddGlobalTestEnvironment(new CudaEnvironment(0)); + ::testing::AddGlobalTestEnvironment(new HipEnvironment(0)); + ::testing::AddGlobalTestEnvironment(new SyclEnvironment(0)); + ::testing::AddGlobalTestEnvironment(new OmpEnvironment(0)); int result = RUN_ALL_TESTS(); return result; } diff --git a/core/test/gtest/ginkgo_mpi_main.cpp b/core/test/gtest/ginkgo_mpi_main.cpp index 945ec7ec7cd..f7fe71981d2 100644 --- a/core/test/gtest/ginkgo_mpi_main.cpp +++ b/core/test/gtest/ginkgo_mpi_main.cpp @@ -394,9 +394,10 @@ int main(int argc, char** argv) testing::AddGlobalTestEnvironment(new GTestMPIListener::MPIEnvironment); ::testing::AddGlobalTestEnvironment(new ResourceEnvironment(rank, size)); - ::testing::AddGlobalTestEnvironment(new CudaEnvironment); - ::testing::AddGlobalTestEnvironment(new HipEnvironment); - ::testing::AddGlobalTestEnvironment(new OmpEnvironment); + ::testing::AddGlobalTestEnvironment(new CudaEnvironment(rank)); + ::testing::AddGlobalTestEnvironment(new HipEnvironment(rank)); + ::testing::AddGlobalTestEnvironment(new SyclEnvironment(rank)); + ::testing::AddGlobalTestEnvironment(new OmpEnvironment(rank)); ::testing::TestEventListeners& listeners = ::testing::UnitTest::GetInstance()->listeners(); diff --git a/cuda/base/device.cpp b/cuda/base/device.cpp index 2db0876ca95..32cf6265160 100644 --- a/cuda/base/device.cpp +++ b/cuda/base/device.cpp @@ -58,6 +58,14 @@ void destroy_event(CUevent_st* event) } +std::string get_device_name(int device_id) +{ + cudaDeviceProp prop; + GKO_ASSERT_NO_CUDA_ERRORS(cudaGetDeviceProperties(&prop, device_id)); + return {prop.name}; +} + + } // namespace cuda } // namespace kernels } // namespace gko diff --git a/cuda/base/device.hpp b/cuda/base/device.hpp index 7bd9390c54e..e363f455300 100644 --- a/cuda/base/device.hpp +++ b/cuda/base/device.hpp @@ -50,6 +50,10 @@ void reset_device(int device_id); void destroy_event(CUevent_st* event); +/** returns cudaDeviceProp.name for the given device */ +std::string get_device_name(int device_id); + + } // namespace cuda } // namespace kernels } // namespace gko diff --git a/dpcpp/base/device.hpp b/dpcpp/base/device.hpp index 6047fbed615..658ccbe18f4 100644 --- a/dpcpp/base/device.hpp +++ b/dpcpp/base/device.hpp @@ -46,6 +46,9 @@ namespace dpcpp { void destroy_event(sycl::event* event); +std::string get_device_name(int device_id); + + } // namespace dpcpp } // namespace kernels } // namespace gko diff --git a/dpcpp/base/executor.dp.cpp b/dpcpp/base/executor.dp.cpp index 3d01e271f15..6d6bbbe0388 100644 --- a/dpcpp/base/executor.dp.cpp +++ b/dpcpp/base/executor.dp.cpp @@ -323,6 +323,17 @@ namespace dpcpp { void destroy_event(sycl::event* event) { delete event; } +std::string get_device_name(int device_id) +{ + auto devices = ::gko::detail::get_devices("gpu"); + if (devices.empty()) { + return "CPU"; + } + + return devices[device_id].get_info(); +} + + } // namespace dpcpp } // namespace kernels } // namespace gko diff --git a/hip/base/device.hip.cpp b/hip/base/device.hip.cpp index 9a01d6aacee..d539fa69b43 100644 --- a/hip/base/device.hip.cpp +++ b/hip/base/device.hip.cpp @@ -62,6 +62,14 @@ void destroy_event(GKO_HIP_EVENT_STRUCT* event) } +std::string get_device_name(int device_id) +{ + hipDeviceProp_t prop; + GKO_ASSERT_NO_HIP_ERRORS(hipGetDeviceProperties(&prop, device_id)); + return {prop.name}; +} + + } // namespace hip } // namespace kernels } // namespace gko diff --git a/hip/base/device.hpp b/hip/base/device.hpp index dcc8c3ba0f1..fceffe4a503 100644 --- a/hip/base/device.hpp +++ b/hip/base/device.hpp @@ -49,6 +49,10 @@ void reset_device(int device_id); void destroy_event(GKO_HIP_EVENT_STRUCT* event); +/** returns hipDeviceProp.name for the given device */ +std::string get_device_name(int device_id); + + } // namespace hip } // namespace kernels } // namespace gko