Skip to content

Commit

Permalink
Fixes for AMD OpenCL (require CL2.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonlopaciuk committed Jun 13, 2024
1 parent ae07076 commit 6346f46
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 55 deletions.
88 changes: 41 additions & 47 deletions xtrack/beam_elements/elements_src/solenoid.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void Solenoid_track_local_particle(SolenoidData el, LocalParticle* part0) {
factor_knl_ksl = -1;
#endif

#ifndef XTRACK_SOLENOID_NO_SYNRAD // does this do the right thing?
#ifndef XTRACK_SOLENOID_NO_SYNRAD
double dp_record_entry = 0.;
double dpx_record_entry = 0.;
double dpy_record_entry = 0.;
Expand All @@ -37,68 +37,62 @@ void Solenoid_track_local_particle(SolenoidData el, LocalParticle* part0) {
const double slice_length = length / (num_multipole_kicks + 1);
const double kick_weight = 1. / num_multipole_kicks;

//start_per_particle_block (part0->part)
#ifndef XTRACK_SOLENOID_NO_SYNRAD
double const old_px = LocalParticle_get_px(part);
double const old_py = LocalParticle_get_py(part);
double const old_ax = LocalParticle_get_ax(part);
double const old_ay = LocalParticle_get_ay(part);
double const old_zeta = LocalParticle_get_zeta(part);
double const rvv = LocalParticle_get_rvv(part);
#endif

for (int ii = 0; ii < num_multipole_kicks; ii++) {
//start_per_particle_block (part0->part)
#ifndef XTRACK_SOLENOID_NO_SYNRAD
double const old_px = LocalParticle_get_px(part);
double const old_py = LocalParticle_get_py(part);
double const old_ax = LocalParticle_get_ax(part);
double const old_ay = LocalParticle_get_ay(part);
double const old_zeta = LocalParticle_get_zeta(part);
double const rvv = LocalParticle_get_rvv(part);
#endif

track_solenoid_thick_single_particle(part, slice_length, ks, radiation_flag,
&dp_record_entry, &dpx_record_entry, &dpy_record_entry,
&dp_record_exit, &dpx_record_exit, &dpy_record_exit);
track_solenoid_thick_single_particle(part, slice_length, ks, radiation_flag);

track_multipolar_kick_bend(
part, order, inv_factorial_order, knl, ksl, factor_knl_ksl,
kick_weight, 0, 0, 0, 0);
}

#ifndef XTRACK_SOLENOID_NO_SYNRAD
double l_path, curv;
if (radiation_flag > 0 && length > 0){
double const new_ax = LocalParticle_get_ax(part);
double const new_ay = LocalParticle_get_ay(part);
track_solenoid_thick_single_particle(part, slice_length, ks, radiation_flag);

double const old_px_mech = old_px - old_ax;
double const old_py_mech = old_py - old_ay;
#ifndef XTRACK_SOLENOID_NO_SYNRAD
double l_path, curv;
if (radiation_flag > 0 && length > 0){
double const new_ax = LocalParticle_get_ax(part);
double const new_ay = LocalParticle_get_ay(part);

double const new_px_mech = LocalParticle_get_px(part) - new_ax;
double const new_py_mech = LocalParticle_get_py(part) - new_ay;
double const old_px_mech = old_px - old_ax;
double const old_py_mech = old_py - old_ay;

double const dpx = new_px_mech - old_px_mech;
double const dpy = new_py_mech - old_py_mech;
double const new_px_mech = LocalParticle_get_px(part) - new_ax;
double const new_py_mech = LocalParticle_get_py(part) - new_ay;

curv = sqrt(dpx * dpx + dpy * dpy) / length;
double const dpx = new_px_mech - old_px_mech;
double const dpy = new_py_mech - old_py_mech;

// Path length for radiation
double const dzeta = LocalParticle_get_zeta(part) - old_zeta;
l_path = rvv * (length - dzeta);
curv = sqrt(dpx * dpx + dpy * dpy) / length;

LocalParticle_add_to_px(part, -new_ax);
LocalParticle_add_to_py(part, -new_ay);
// Path length for radiation
double const dzeta = LocalParticle_get_zeta(part) - old_zeta;
l_path = rvv * (length - dzeta);

if (radiation_flag == 1){
synrad_average_kick(part, curv, l_path,
dp_record_exit, dpx_record_exit, dpy_record_exit);
}
else if (radiation_flag == 2){
synrad_emit_photons(part, curv, l_path, NULL, NULL);
}
LocalParticle_add_to_px(part, -new_ax);
LocalParticle_add_to_py(part, -new_ay);

LocalParticle_add_to_px(part, new_ax);
LocalParticle_add_to_py(part, new_ay);
if (radiation_flag == 1){
synrad_average_kick(part, curv, l_path,
&dp_record_exit, &dpx_record_exit, &dpy_record_exit);
}
else if (radiation_flag == 2){
synrad_emit_photons(part, curv, l_path, NULL, NULL);
}
#endif
//end_per_particle_block
}

//start_per_particle_block (part0->part)
Solenoid_thick_track_single_particle(part, slice_length, ks, radiation_flag,
&dp_record_entry, &dpx_record_entry, &dpy_record_entry,
&dp_record_exit, &dpx_record_exit, &dpy_record_exit);
LocalParticle_add_to_px(part, new_ax);
LocalParticle_add_to_py(part, new_ay);
}
#endif
//end_per_particle_block
}

Expand Down
4 changes: 2 additions & 2 deletions xtrack/beam_elements/elements_src/thick_slice_bend.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ void ThickSliceBend_track_local_particle(
const double h = ThickSliceBendData_get__parent_h(el);
const double order = ThickSliceBendData_get__parent_order(el);
const double inv_factorial_order = ThickSliceBendData_get__parent_inv_factorial_order(el);
const double* knl = ThickSliceBendData_getp1__parent_knl(el, 0);
const double* ksl = ThickSliceBendData_getp1__parent_ksl(el, 0);
/*gpuglmem*/ const double* knl = ThickSliceBendData_getp1__parent_knl(el, 0);
/*gpuglmem*/ const double* ksl = ThickSliceBendData_getp1__parent_ksl(el, 0);
const int64_t model = ThickSliceBendData_get__parent_model(el);

const int64_t num_multipole_kicks_parent = ThickSliceBendData_get__parent_num_multipole_kicks(el);
Expand Down
4 changes: 2 additions & 2 deletions xtrack/beam_elements/elements_src/thick_slice_quadrupole.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ void ThickSliceQuadrupole_track_local_particle(
const int64_t num_multipole_kicks_parent = ThickSliceQuadrupoleData_get__parent_num_multipole_kicks(el);
const double order = ThickSliceQuadrupoleData_get__parent_order(el);
const double inv_factorial_order = ThickSliceQuadrupoleData_get__parent_inv_factorial_order(el);
const double* knl = ThickSliceQuadrupoleData_getp1__parent_knl(el, 0);
const double* ksl = ThickSliceQuadrupoleData_getp1__parent_ksl(el, 0);
/*gpuglmem*/ const double* knl = ThickSliceQuadrupoleData_getp1__parent_knl(el, 0);
/*gpuglmem*/ const double* ksl = ThickSliceQuadrupoleData_getp1__parent_ksl(el, 0);

#ifndef XSUITE_BACKTRACK
double const length = weight * ThickSliceQuadrupoleData_get__parent_length(el); // m
Expand Down
2 changes: 1 addition & 1 deletion xtrack/beam_elements/elements_src/track_bend.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
void Bend_track_local_particle_from_params(LocalParticle* part0,
double length, double k0, double k1, double h,
int64_t num_multipole_kicks, int64_t model,
double const* knl, double const* ksl,
/*gpuglmem*/ double const* knl, /*gpuglmem*/ double const* ksl,
int64_t order, double inv_factorial_order,
double factor_knl_ksl){

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
/*gpufun*/
void track_multipolar_kick_bend(
LocalParticle* part, int64_t order, double inv_factorial_order,
const double* knl,
const double* ksl,
/*gpuglmem*/ const double* knl,
/*gpuglmem*/ const double* ksl,
double const factor_knl_ksl,
double kick_weight, double k0, double k1, double h, double length){

Expand Down
2 changes: 1 addition & 1 deletion xtrack/beam_elements/elements_src/track_quadrupole.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void normal_quad_with_rotation_track(
void Quadrupole_from_params_track_local_particle(
double length, double k1, double k1s,
int64_t num_multipole_kicks,
double const* knl, double const* ksl,
/*gpuglmem*/ double const* knl, /*gpuglmem*/ double const* ksl,
int64_t order, double inv_factorial_order,
double factor_knl_ksl,
LocalParticle* part0
Expand Down

0 comments on commit 6346f46

Please sign in to comment.