Skip to content

Commit c357267

Browse files
bound isCuQuantumEnabled to QuESTEnv
so that the COMPILE_CUQUANTUM preprocessor need only ever be consulted by the source during compilation, as proposed by Oliver in #645
1 parent d4706b9 commit c357267

File tree

5 files changed

+28
-21
lines changed

5 files changed

+28
-21
lines changed

quest/include/environment.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,14 @@ extern "C" {
3232
/// @notyetdoced
3333
typedef struct {
3434

35-
// deployment mode
35+
// deployment modes which can be runtime disabled
3636
int isMultithreaded;
3737
int isGpuAccelerated;
3838
int isDistributed;
3939

40+
// deployment modes which cannot be directly changed after compilation
41+
int isCuQuantumEnabled;
42+
4043
// distributed configuration
4144
int rank;
4245
int numNodes;

quest/include/qureg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ Qureg createForcedDensityQureg(int numQubits);
329329
* </center>
330330
*
331331
* @constraints
332-
* - Cannot use any deployment which has not been prior enabled during compilation, or disabled by createCustomQuESTEnv().
332+
* - Cannot use any deployment which has not been prior enabled during compilation, or disabled by initCustomQuESTEnv().
333333
* - Cannot distribute @f$ N @f$ qubits over more than @f$ 2^N @f$ nodes (regardless of @p isDensMatr).
334334
* - Cannot distribute when the executable was not launched using MPI (e.g. via @c mpirun).
335335
* - Cannot GPU-accelerate when a GPU is not available at runtime, or has insufficient memory.

quest/src/api/environment.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@ void validateAndInitCustomQuESTEnv(int useDistrib, int useGpuAccel, int useMulti
114114
/// should we warn here if each machine contains
115115
/// more GPUs than deployed MPI-processes (some GPUs idle)?
116116

117-
// use cuQuantum if compiled
118-
if (useGpuAccel && gpu_isCuQuantumCompiled()) {
117+
// cuQuantum is always used in GPU-accelerated envs when available
118+
bool useCuQuantum = useGpuAccel && gpu_isCuQuantumCompiled();
119+
if (useCuQuantum) {
119120
validate_gpuIsCuQuantumCompatible(caller); // assesses above bound GPU
120121
gpu_initCuQuantum();
121122
}
@@ -131,9 +132,10 @@ void validateAndInitCustomQuESTEnv(int useDistrib, int useGpuAccel, int useMulti
131132
error_allocOfQuESTEnvFailed();
132133

133134
// bind deployment info to global instance
134-
globalEnvPtr->isMultithreaded = useMultithread;
135-
globalEnvPtr->isGpuAccelerated = useGpuAccel;
136-
globalEnvPtr->isDistributed = useDistrib;
135+
globalEnvPtr->isMultithreaded = useMultithread;
136+
globalEnvPtr->isGpuAccelerated = useGpuAccel;
137+
globalEnvPtr->isDistributed = useDistrib;
138+
globalEnvPtr->isCuQuantumEnabled = useCuQuantum;
137139

138140
// bind distributed info
139141
globalEnvPtr->rank = (useDistrib)? comm_getRank() : 0;
@@ -174,7 +176,7 @@ void printCompilationInfo() {
174176

175177
print_table(
176178
"compilation", {
177-
{"isMpiCompiled", comm_isMpiCompiled()},
179+
{"isMpiCompiled", comm_isMpiCompiled()},
178180
{"isGpuCompiled", gpu_isGpuCompiled()},
179181
{"isOmpCompiled", cpu_isOpenmpCompiled()},
180182
{"isCuQuantumCompiled", gpu_isCuQuantumCompiled()},
@@ -186,9 +188,10 @@ void printDeploymentInfo() {
186188

187189
print_table(
188190
"deployment", {
189-
{"isMpiEnabled", globalEnvPtr->isDistributed},
190-
{"isGpuEnabled", globalEnvPtr->isGpuAccelerated},
191-
{"isOmpEnabled", globalEnvPtr->isMultithreaded},
191+
{"isMpiEnabled", globalEnvPtr->isDistributed},
192+
{"isGpuEnabled", globalEnvPtr->isGpuAccelerated},
193+
{"isOmpEnabled", globalEnvPtr->isMultithreaded},
194+
{"isCuQuantumEnabled", globalEnvPtr->isCuQuantumEnabled},
192195
});
193196
}
194197

tests/main.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ class startListener : public Catch::EventListenerBase {
8888
QuESTEnv env = getQuESTEnv();
8989
std::cout << std::endl;
9090
std::cout << "QuEST execution environment:" << std::endl;
91-
std::cout << " precision: " << FLOAT_PRECISION << std::endl;
92-
std::cout << " multithreaded: " << env.isMultithreaded << std::endl;
93-
std::cout << " distributed: " << env.isDistributed << std::endl;
94-
std::cout << " GPU-accelerated: " << env.isGpuAccelerated << std::endl;
95-
std::cout << " cuQuantum: " << (env.isGpuAccelerated && COMPILE_CUQUANTUM) << std::endl;
96-
std::cout << " num nodes: " << env.numNodes << std::endl;
97-
std::cout << " num qubits: " << getNumCachedQubits() << std::endl;
91+
std::cout << " precision: " << FLOAT_PRECISION << std::endl;
92+
std::cout << " multithreaded: " << env.isMultithreaded << std::endl;
93+
std::cout << " distributed: " << env.isDistributed << std::endl;
94+
std::cout << " GPU-accelerated: " << env.isGpuAccelerated << std::endl;
95+
std::cout << " cuQuantum: " << env.isCuQuantumEnabled << std::endl;
96+
std::cout << " num nodes: " << env.numNodes << std::endl;
97+
std::cout << " num qubits: " << getNumCachedQubits() << std::endl;
9898
std::cout << " num qubit perms: " << TEST_MAX_NUM_QUBIT_PERMUTATIONS << std::endl;
9999
std::cout << std::endl;
100100

tests/unit/environment.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,10 @@ TEST_CASE( "getQuESTEnv", TEST_CATEGORY ) {
133133

134134
QuESTEnv env = getQuESTEnv();
135135

136-
REQUIRE( (env.isMultithreaded == 0 || env.isMultithreaded == 1) );
137-
REQUIRE( (env.isGpuAccelerated == 0 || env.isGpuAccelerated == 1) );
138-
REQUIRE( (env.isDistributed == 0 || env.isDistributed == 1) );
136+
REQUIRE( (env.isMultithreaded == 0 || env.isMultithreaded == 1) );
137+
REQUIRE( (env.isGpuAccelerated == 0 || env.isGpuAccelerated == 1) );
138+
REQUIRE( (env.isDistributed == 0 || env.isDistributed == 1) );
139+
REQUIRE( (env.isCuQuantumEnabled == 0 || env.isCuQuantumEnabled == 1) );
139140

140141
REQUIRE( env.rank >= 0 );
141142
REQUIRE( env.numNodes >= 0 );

0 commit comments

Comments
 (0)