Skip to content

Commit

Permalink
added hardware querents
Browse files Browse the repository at this point in the history
but some GPU utilities are TODO
  • Loading branch information
TysonRayJones committed Jun 9, 2024
1 parent a057598 commit 3e2f782
Show file tree
Hide file tree
Showing 9 changed files with 394 additions and 5 deletions.
105 changes: 104 additions & 1 deletion quest/src/comm/communication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,31 @@
#include "quest/include/modes.h"
#include "quest/include/types.h"

#include "quest/src/core/errors.hpp"

#if ENABLE_DISTRIBUTION
#include <mpi.h>
#endif



/*
* WARN ABOUT CUDA-AWARENESS
*/

#if ENABLE_DISTRIBUTION && ENABLE_GPU_ACCELERATION
#include <mpi-ext.h>

#ifndef MPIX_CUDA_AWARE_SUPPORT
#warning "Could not ascertain whether MPI is CUDA-aware, so we will assume it is not. This means inter-GPU communication will be slowly routed through the CPU/RAM."
#elif !MPIX_CUDA_AWARE_SUPPORT
#warning "MPI compiler is not CUDA-aware, so inter-GPU communication will be slowly routed through the CPU/RAM"
#endif

#endif



/*
* MPI COMPLEX TYPE FLAG
*/
Expand All @@ -33,4 +52,88 @@
#define MPI_QCOMP MPI_C_LONG_DOUBLE_COMPLEX
#endif

#endif
#endif



/*
* MPI ENVIRONMENT MANAGEMENT
* all of which is safely callable in non-distributed mode
*/


bool comm_isMpiCompiled() {
return (bool) ENABLE_DISTRIBUTION;
}


bool comm_isMpiGpuAware() {

// TODO: these checks may be OpenMPI specific, so that
// non-OpenMPI MPI compilers are always dismissed as
// not being CUDA-aware. Check e.g. MPICH method!

// definitely not GPU-aware if compiler declares it is not
#if defined(MPIX_CUDA_AWARE_SUPPORT) && ! MPIX_CUDA_AWARE_SUPPORT
return false;
#endif

// check CUDA-awareness at run-time if we know it's principally supported
#if defined(MPIX_CUDA_AWARE_SUPPORT)
return (bool) MPIX_Query_cuda_support();
#endif

// if we can't ascertain CUDA-awareness, just assume no to avoid seg-fault
return false;
}


void comm_init() {
#if ENABLE_DISTRIBUTION
int isInit;
MPI_Initialized(&isInit);

// gracefully handle re-initialisation
if (isInit)
error_commAlreadyInit();

MPI_Init(NULL, NULL);
#endif
}


void comm_end() {
#if ENABLE_DISTRIBUTION
MPI_Barrier(MPI_COMM_WORLD);
MPI_Finalize();
#endif
}


int comm_getRank() {
#if ENABLE_DISTRIBUTION
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
return rank;
#else
return 0;
#endif
}


int comm_getNumNodes() {
#if ENABLE_DISTRIBUTION
int numNodes;
MPI_Comm_size(MPI_COMM_WORLD, &numNodes);
return numNodes;
#else
return 1;
#endif
}


void comm_synch() {
#if ENABLE_DISTRIBUTION
MPI_Barrier(MPI_COMM_WORLD);
#endif
}
20 changes: 20 additions & 0 deletions quest/src/comm/communication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,24 @@



/*
* MPI ENVIRONMENT MANAGEMENT
*/

bool comm_isMpiCompiled();

bool comm_isMpiGpuAware();

void comm_init();

void comm_end();

int comm_getRank();

int comm_getNumNodes();

void comm_synch();



#endif // COMMUNICATION_HPP
24 changes: 23 additions & 1 deletion quest/src/core/errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,26 @@ void error_validationMessageVarNotSubstituted(std::string msg, std::string var)
void error_validationMessageContainedUnsubstitutedVars(std::string msg) {

raiseInternalError("User input validation failed and an error string was prepared. However, the message contained unexpected (and potentially ill-formed) unsubstituted variables. The message was:\n" + msg + "\n");
}
}



/*
* COMMUNICATION ERRORS
*/

void error_commAlreadyInit() {

raiseInternalError("The MPI communication environment was attemptedly re-initialised, despite the QuEST environment already existing.");
}



/*
* GPU ERRORS
*/

void error_gpuQueriedButGpuNotCompiled() {

raiseInternalError("A function attempted to query GPU properties but QuEST was not compiled with GPU acceleration enabled.");
}
16 changes: 16 additions & 0 deletions quest/src/core/errors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,20 @@ void error_validationMessageContainedUnsubstitutedVars(std::string msg);



/*
* COMMUNICATION ERRORS
*/

void error_commAlreadyInit();



/*
* GPU ERRORS
*/

void error_gpuQueriedButGpuNotCompiled();



#endif // ERRORS_HPP
1 change: 1 addition & 0 deletions quest/src/core/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

#include "quest/src/core/errors.hpp"
#include "quest/src/comm/communication.hpp"

#include <iostream>
#include <cstdlib>
Expand Down
52 changes: 50 additions & 2 deletions quest/src/cpu/omp_subroutines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,60 @@
#include "quest/include/modes.h"
#include "quest/include/types.h"

#include "quest/src/core/errors.hpp"


#if ENABLE_MULTITHREADING && !defined(_OPENMP)
#error "Attempted to compile in multithreaded mode without enabling OpenMP."
#endif


#if ENABLE_MULTITHREADING
#include <omp.h>
#endif


// inform OpenMP how to reduce qcomp instances (except on MSVC compilers)

/*
* ENABLE OPENMP REDUCTION OF qcomp (except on MSVC compilers)
*/

#if defined(ENABLE_MULTITHREADING) && !defined(_MSC_VER)
#pragma omp declare reduction(+ : qcomp : omp_out += omp_in ) initializer( omp_priv = omp_orig )
#endif
#endif



/*
* OPENMP CONFIG
*/


bool cpu_isOpenmpCompiled() {
return (bool) ENABLE_MULTITHREADING;
}


int cpu_getCurrentNumThreads() {
#if ENABLE_MULTITHREADING
int n = -1;

#pragma omp parallel shared(n)
n = omp_get_num_threads();

return n;
#else
error_cpuThreadsQueriedButEnvNotMultithreaded();
return -1;
#endif
}


int cpu_getNumOpenmpProcessors() {
#if ENABLE_MULTITHREADING
return omp_get_num_procs();
#else
error_cpuThreadsQueriedButEnvNotMultithreaded();
return -1;
#endif
}
12 changes: 12 additions & 0 deletions quest/src/cpu/omp_subroutines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,16 @@



/*
* OPENMP CONFIG
*/

bool cpu_isOpenmpCompiled();

int cpu_getCurrentNumThreads();

int cpu_getNumOpenmpProcessors();



#endif // OMP_SUBROUTINES_HPP
Loading

0 comments on commit 3e2f782

Please sign in to comment.