Files
TheRock/rocm-systems/projects/rccl/test/common/MPITestBase.hpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

115 lines
3.2 KiB
C++

/*************************************************************************
* Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
*
* See LICENSE.txt for license information
************************************************************************/
/**
* @file MPITestBase.hpp
* @brief Base class infrastructure for MPI-based RCCL testing
*
* Provides a common test base class for writing multi-process distributed tests
* using MPI and RCCL. Handles communicator creation, process validation, and
* resource cleanup automatically.
*
* @see MPITestBase for the main base class
* @see MPIEnvironment for global MPI setup
*/
#ifndef MPI_TEST_BASE_HPP
#define MPI_TEST_BASE_HPP
#include "MPITestCore.hpp"
#include "gtest/gtest.h"
#ifdef MPI_TESTS_ENABLED
#include "MPIEnvironment.hpp"
#include "TestChecks.hpp"
#include "rccl/rccl.h"
#include "utils.h" // For getHostName() from RCCL
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <hip/hip_runtime.h>
#include <mpi.h>
#include <string>
/**
* @class MPITestBase
* @brief Google Test adapter for MPI tests
*
* Integrates MPITestCore with Google Test framework for seamless MPI testing.
* Inherits from both ::testing::Test (for GTest integration) and MPITestCore
* (for MPI/RCCL functionality).
*
* **Features:**
* - Process count validation (minimum processes, power-of-two requirements)
* - Node count validation (single-node vs multi-node)
* - Test-specific RCCL communicator creation and management
* - HIP stream management for each test
* - Automatic resource cleanup via GTest TearDown
*
* **Usage Example:**
* @code
* class MyMPITest : public MPITestBase {};
*
* TEST_F(MyMPITest, BasicAllReduce) {
* if (!validateTestPrerequisites(2)) {
* GTEST_SKIP() << "Need at least 2 processes";
* }
* ASSERT_EQ(ncclSuccess, createTestCommunicator());
*
* ncclComm_t comm = getActiveCommunicator();
* hipStream_t stream = getActiveStream();
*
* // Your test logic here...
* // Cleanup happens automatically in TearDown()
* }
* @endcode
*
* @note For standalone tests without GTest, use MPIStandaloneTest instead
* @see MPITestCore for the base framework-agnostic functionality
* @see MPIEnvironment for global MPI initialization
*/
/**
* @brief Google Test adapter for MPI tests
*
* Integrates MPITestCore with Google Test framework by inheriting from both
* ::testing::Test and MPITestCore.
*
* @note For standalone tests (without GTest), use MPIStandaloneTest instead
*/
class MPITestBase
: public ::testing::Test
, public MPITestCore
{
public:
/**
* @brief Google Test SetUp hook - initializes test resources
*
* Automatically called before each test runs. Calls initializeTest()
* from MPITestCore for any custom initialization.
*
* @note No ambiguity with MPITestCore::initializeTest() - different names
*/
void SetUp() override
{
initializeTest();
}
/**
* @brief Google Test TearDown hook - ensures cleanup of test resources
*
* Automatically called after each test completes. Calls cleanupTest()
* from MPITestCore to ensure proper resource cleanup.
*/
void TearDown() override
{
cleanupTest();
}
};
#endif // MPI_TESTS_ENABLED
#endif // MPI_TEST_BASE_HPP