Skip to content

Commit

Permalink
Minor fixes of GPU support and auto-comp.
Browse files Browse the repository at this point in the history
  • Loading branch information
ochubar committed Mar 24, 2024
1 parent 2830104 commit b600ef9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 9 deletions.
1 change: 0 additions & 1 deletion cpp/src/core/srercode.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@
#define SRWL_INCORRECT_PARAM_FOR_CONV_WITH_GAUS 181 + FIRST_XOP_ERR
#define SRWL_INCORRECT_PARAM_FOR_CONV_MAG_2_PER 182 + FIRST_XOP_ERR
#define IMPROPER_OPTICAL_COMPONENT_MIRROR_SPHERE 183 + FIRST_XOP_ERR
//#define IMPROPER_OPTICAL_COMPONENT_MIRROR_USE_CASE 184 + FIRST_XOP_ERR
#define IMPROPER_OPTICAL_COMPONENT_CRYSTAL_USE_CASE 184 + FIRST_XOP_ERR
#define SRWL_INCORRECT_PARAM_FOR_UND_FLD_INTERP_IND_SEARCH 185 + FIRST_XOP_ERR
#define SRWL_INCORRECT_PARAM_FOR_SPHER_WAVE_COMP 186 + FIRST_XOP_ERR
Expand Down
5 changes: 5 additions & 0 deletions cpp/src/lib/srerror.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@ CErrWarn::CErrWarn()
warning.push_back("Electron beam is not ultra-relativistic. The resulting accuracy may be poor.");
warning.push_back("To calculate emission at harmonics (HGHG), this version of GENESIS requires Electron Distribution data."); //#define GENESIS_RAD_HARM_CALC_NEEDS_ELEC_DISTRIB 24 + SRW_WARNINGS_OFFSET
warning.push_back("Zero wavefront radius of curvature was submitted; the corresponding quadratic phase term was not treated."); //#define ZERO_WFR_RAD_CURV_PH_TERM_NOT_TREATED 25 + SRW_WARNINGS_OFFSET
#ifdef _OFFLOAD_GPU //HG21032024
warning.push_back("GPU usage is requested, but GPU offloading failed. Computation will be performed on CPU."); //#define GPU_COMPUTATION_FAILED 26 + SRW_WARNINGS_OFFSET
#else
warning.push_back("GPU usage is requested, but GPU offloading is not compiled in. Computation will be performed on CPU."); //#define GPU_COMPUTATION_FAILED 26 + SRW_WARNINGS_OFFSET
#endif

//};
}
Expand Down
40 changes: 33 additions & 7 deletions cpp/src/lib/srwlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,8 +768,8 @@ EXP int CALL srwlCalcIntFromElecField(char* pInt, SRWLWfr* pWfr, char polar, cha

//HG26022024 (commented-out)
//#ifdef _OFFLOAD_GPU //HG07022024
// srwlUtiGPUProc(1, arParGPU); //OC20022024
// //srwlUtiGPUProc(1, pvGPU); //initialize GPU
srwlUtiGPUProc(1, arParGPU); //HG21042024 Uncommented (required, must've been missed in previous exchanges) //OC20022024
//srwlUtiGPUProc(1, pvGPU); //initialize GPU
//#endif

SRWLPrtTrj *pTrj=0; //OC23022020
Expand Down Expand Up @@ -1032,10 +1032,10 @@ EXP int CALL srwlPropagElecField(SRWLWfr* pWfr, SRWLOptC* pOpt, int nInt, char**
//double start;
//get_walltime (&start);

#ifdef _OFFLOAD_GPU //HG07022024
//#ifdef _OFFLOAD_GPU //HG21032024 (commented-out) //HG07022024
srwlUtiGPUProc(1, arParGPU); //OC20022024
//srwlUtiGPUProc(1, pvGPU);
#endif
//#endif //HG21032024 (commented-out)
try
{
srTCompositeOptElem optCont(*pOpt);
Expand Down Expand Up @@ -1109,10 +1109,10 @@ EXP int CALL srwlUtiFFT(char* pcData, char typeData, double* arMesh, int nMesh,
if(ny > 1) dimFFT = 2;
//float *pfData = (float*)pcData; //OC31012019 (commented-out)

#ifdef _OFFLOAD_GPU //HG07022024
//#ifdef _OFFLOAD_GPU //HG21032024 (commented-out) //HG07022024
srwlUtiGPUProc(1, arParGPU); //OC20022024
//srwlUtiGPUProc(1, pvGPU);
#endif
//#endif //HG21032024 (commented-out)

if(dimFFT == 1)
{
Expand Down Expand Up @@ -1609,7 +1609,33 @@ EXP int CALL srwlUtiGPUProc(int op, double* arParGPU) //OC20022024
{
#ifdef _OFFLOAD_GPU //HG07022024
if(op == 0) CAuxGPU::Fini();
if(op == 1) CAuxGPU::Init();
//if(op == 1) CAuxGPU::Init();
if(op == 1) //HG22032024
{
CAuxGPU::Init();
if(arParGPU != 0 && arParGPU[0] > 0 && arParGPU[1] > 0) //HG07022024
{
//Check if any GPU is available
if(!CAuxGPU::GPUAvailable())
{
CErrWarn::AddWarningMessage(&gVectWarnNos, GPU_COMPUTATION_FAILED);
return 0;
}

//Make sure that the specific GPU index requested is available
TGPUUsageArg parGPU(arParGPU);
if(!CAuxGPU::GPUEnabled(&parGPU))
{
CErrWarn::AddWarningMessage(&gVectWarnNos, GPU_COMPUTATION_FAILED);
return 0;
}
}
}
#else
//Emits warning message that GPU offloading is not compiled in if GPU is requested during initialization
if(arParGPU != 0 && arParGPU[0] > 0 && arParGPU[1] > 0 && op == 1)
CErrWarn::AddWarningMessage(&gVectWarnNos, GPU_COMPUTATION_FAILED);

#endif //HG07022024
return 0;
}
Expand Down
1 change: 0 additions & 1 deletion env/python/srwpy/SRWLIB_ExampleViewDataFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def main(): #HG22032024
uti_plot_data_file(opt.infile, opt.readlab, opt.e, opt.x, opt.y, opt.joined,
opt.multicol_data, opt.multicol_data_col_x, opt.multicol_data_col_y, #OC14112017 #MR31102017
opt.scale, opt.width_pixels)

uti_plot_show()

if __name__=='__main__': #HG22032024
Expand Down
1 change: 1 addition & 0 deletions env/python/srwpy/examples/SRWLIB_Example17.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
#[10]: New Horizontal wavefront Center position after Shift
#[11]: New Vertical wavefront Center position after Shift
# [0][1][2] [3][4] [5] [6] [7] [8] [9][10][11]

ppSmp = [0, 0, 1., 0, 0, 1., 55., 1., 55., 0, 0, 0]
ppSmp_Det = [0, 0, 1., 3, 0, 1., 1., 1., 1., 0, 0, 0]
ppFin = [0, 0, 1., 0, 0, 1., 1., 1., 1., 0, 0, 0]
Expand Down

0 comments on commit b600ef9

Please sign in to comment.