The Quantum Exact Simulation Toolkit v4.0.0
Loading...
Searching...
No Matches
Synchronisation

Functions for copying memory between a Qureg's CPU (RAM) and GPU (VRAM) memory. More...

Functions

void syncQuregFromGpu (Qureg qureg)
 
void syncQuregToGpu (Qureg qureg)
 
void syncSubQuregFromGpu (Qureg qureg, qindex localStartInd, qindex numLocalAmps)
 
void syncSubQuregToGpu (Qureg qureg, qindex localStartInd, qindex numLocalAmps)
 

Detailed Description

Functions for copying memory between a Qureg's CPU (RAM) and GPU (VRAM) memory.

These functions are only necessary when the user wishes to manually probe or modify the Qureg amplitudes (rather than use functions like getQuregAmps() and setQuregAmps()), to ensure that the CPU and GPU copies of the Qureg are identical. These functions have no effect when running without GPU-acceleration, but remain legal and harmless to call, to achieve platform agnosticism.

Function Documentation

◆ syncQuregFromGpu()

void syncQuregFromGpu ( Qureg qureg)
Note
Documentation for this function or struct is under construction!
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!

Definition at line 399 of file qureg.cpp.

399 {
400 validate_quregFields(qureg, __func__);
401
402 // permit this to be called even in non-GPU mode
403 if (qureg.isGpuAccelerated)
404 gpu_copyGpuToCpu(qureg); // syncs then overwrites all local CPU amps
405}

Referenced by TEST_CASE(), and TEST_CASE().

◆ syncQuregToGpu()

void syncQuregToGpu ( Qureg qureg)
Note
Documentation for this function or struct is under construction!
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!

Definition at line 392 of file qureg.cpp.

392 {
393 validate_quregFields(qureg, __func__);
394
395 // permit this to be called even in non-GPU mode
396 if (qureg.isGpuAccelerated)
397 gpu_copyCpuToGpu(qureg); // syncs then overwrites all local GPU amps
398}

◆ syncSubQuregFromGpu()

void syncSubQuregFromGpu ( Qureg qureg,
qindex localStartInd,
qindex numLocalAmps )
Note
Documentation for this function or struct is under construction!
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!

Definition at line 427 of file qureg.cpp.

427 {
428 validate_quregFields(qureg, __func__);
429 validate_localAmpIndices(qureg, localStartInd, numLocalAmps, __func__);
430
431 // the above validation communicates for node consensus in
432 // distributed settings, because params can differ per-node.
433 // note also this function accepts statevectors AND density
434 // matrices, because the latter does not need a bespoke
435 // (row,col) interface, because the user can only access/modify
436 // local density matrix amps via a flat index anyway!
437
438 // we permit this function to do nothing when not GPU-accelerated
439 if (!qureg.isGpuAccelerated)
440 return;
441
442 // otherwise, every node merely copies its local subset, which
443 // may differ per-node, in an embarrassingly parallel manner
444 gpu_copyGpuToCpu(&qureg.gpuAmps[localStartInd], &qureg.cpuAmps[localStartInd], numLocalAmps);
445}

◆ syncSubQuregToGpu()

void syncSubQuregToGpu ( Qureg qureg,
qindex localStartInd,
qindex numLocalAmps )
Note
Documentation for this function or struct is under construction!
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!

Definition at line 408 of file qureg.cpp.

408 {
409 validate_quregFields(qureg, __func__);
410 validate_localAmpIndices(qureg, localStartInd, numLocalAmps, __func__);
411
412 // the above validation communicates for node consensus in
413 // distributed settings, because params can differ per-node.
414 // note also this function accepts statevectors AND density
415 // matrices, because the latter does not need a bespoke
416 // (row,col) interface, because the user can only access/modify
417 // local density matrix amps via a flat index anyway!
418
419 // we permit this function to do nothing when not GPU-accelerated
420 if (!qureg.isGpuAccelerated)
421 return;
422
423 // otherwise, every node merely copies its local subset, which
424 // may differ per-node, in an embarrassingly parallel manner
425 gpu_copyCpuToGpu(&qureg.cpuAmps[localStartInd], &qureg.gpuAmps[localStartInd], numLocalAmps);
426}