Skip to content

Commit

Permalink
increase readibility and move from map to array
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviermattelaer committed Jun 3, 2024
1 parent 41ddc38 commit 5b6d065
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,27 @@

namespace mgOnGpu
{
// Summary of numbering and indexing conventions for the relevant concepts (see issue #826 and PR #852)
// - Diagram number (no variable) in [1, N_diagrams]: all values are allowed (N_diagrams distinct values)
// => this number is displayed for information before each block of code in CPPProcess.cc
// - Channel number ("channelId" in C, CHANNEL_ID in F) in [1, N_diagrams]: not all values are allowed (N_config <= N_diagrams distinct values)
// 0 is allowed to fallback to no multi-channel mode.
// => this number (with indexing like ps/pdf output) is passed around as an API argument between cudacpp functions
// - Channel number in C indexing: "channelIdC" = channelIdC_to_iconfig[channelId]
// => this number (with C indexing) is used as the index of the channelIdC_to_iconfig array below
// This correspond to iconfig on the fortran side (with iconfig = channelIdC + 1)
//NOTE: All those ordering are event by event specific (with the intent to have those fix within a vector size/wrap

// Map channelId to channelIdC
// This array has N_diagrams+1 elements, but only N_config <= N_diagrams valid (non-zero) values
// The 0 entry is a fall back to still write events even if no multi-channel is setup (wrong color selected in that mode)
__device__ constexpr int channelId_to_channelIdC[%(nb_diag_plus_one)i] = {
0, // channelId=0: This value means not multi-channel, color will be wrong anyway -> pick the first
%(diag_to_channel)s
};

__device__ std::map<int,int> diag_to_channel = {
%(diag_to_channel)s
};
// Map iconfigC (in C indexing, i.e. iconfig-1) to the set of allowed colors
// This array has N_config <= N_diagrams elements
__device__ constexpr bool icolamp[%(nb_channel)s][%(nb_color)s] = {
%(is_LC)s
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
// Event-by-event random choice of color #402
if( channelId != 0 ) // no event-by-event choice of color if channelId == 0 (fix FPE #783)
{
const unsigned int channelIdC = mgOnGpu::diag_to_channel[channelId]; // coloramps.h uses a channel ordering not the diagram id
const unsigned int channelIdC = mgOnGpu::channelId_to_channelIdC[channelId]; // coloramps.h uses a channel ordering not the diagram id
fptype targetamp[ncolor] = { 0 };
for( int icolC = 0; icolC < ncolor; icolC++ )
{
Expand Down Expand Up @@ -115,7 +115,7 @@
// - firstprivate: give each thread its own copy, and initialise with value from outside
#define _OMPLIST0 allcouplings, allMEs, allmomenta, allrndcol, allrndhel, allselcol, allselhel, cGoodHel, cNGoodHel, npagV2
#ifdef MGONGPU_SUPPORTS_MULTICHANNEL
#define _OMPLIST1 , allDenominators, allNumerators, channelId, mgOnGpu::icolamp,mgOnGpu::diag_to_channel
#define _OMPLIST1 , allDenominators, allNumerators, channelId, mgOnGpu::icolamp,mgOnGpu::channelId_to_channelIdC
#else
#define _OMPLIST1
#endif
Expand Down Expand Up @@ -187,7 +187,7 @@
// Event-by-event random choice of color #402
if( channelId != 0 ) // no event-by-event choice of color if channelId == 0 (fix FPE #783)
{
const unsigned int channelIdC = mgOnGpu::diag_to_channel[channelId]; // coloramps.h uses a channel ordering not the diagram id
const unsigned int channelIdC = mgOnGpu::channelId_to_channelIdC[channelId]; // coloramps.h uses a channel ordering not the diagram id
fptype_sv targetamp[ncolor] = { 0 };
for( int icolC = 0; icolC < ncolor; icolC++ )
{
Expand Down
49 changes: 42 additions & 7 deletions epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/model_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1531,30 +1531,65 @@ def edit_coloramps(self, config_subproc_map):
# The following five lines from OneProcessExporterCPP.get_sigmaKin_lines (using OneProcessExporterCPP.get_icolamp_lines)
replace_dict={}

lines = []
# Output only configs that have some corresponding diagrams
iconfig = 0

iconfig_to_diag = {}
diag_to_iconfig = {}
iconfig = 0
for config in config_subproc_map:
if set(config) == set([0]):
continue
lines.append(" {%i, %i}," % (config[0], iconfig))
iconfig += 1
iconfig_to_diag[iconfig] = config[0]
diag_to_iconfig[config[0]] = iconfig

misc.sprint(iconfig_to_diag)
misc.sprint(diag_to_iconfig)

# Note that if the last diagram is/are not mapped to a channel nb_diag
# will be smaller than the true number of diagram. This is fine for color
# but maybe not for something else.
nb_diag = max(config[0] for config in config_subproc_map)
# Output which diagrams correspond ot a channel to get information for valid color
lines = []
# Note: line for index 0 (no multi-channel is hardcoded in the template, so here we fill the array from index 1)
for diag in range(1, nb_diag+1):
if diag in diag_to_iconfig:
iconfig = diag_to_iconfig[diag]
channel = iconfig -1 # C convention
text = " %(channel)i, // channelId=%(diag)i (diagram=%(diag)i) i.e. channelIdC=%(channel)i --> iconfig=%(iconfig)i "
else:
iconfig = -1
channel = -1
text = " -1, // channelId=%(diag)i (diagram=%(diag)i): Not consider as a channel of integration (presence of 4 point interaction?)"
lines.append(text % {'diag': diag, 'channel': channel, 'iconfig': iconfig})

replace_dict['diag_to_channel'] = '\n'.join(lines)
misc.sprint(replace_dict)

if self.include_multi_channel: # NB unnecessary as edit_coloramps is not called otherwise...
multi_channel = self.get_multi_channel_dictionary(self.matrix_elements[0].get('diagrams'), self.include_multi_channel)
replace_dict['is_LC'] = self.get_icolamp_lines(multi_channel, self.matrix_elements[0], 1)
replace_dict['nb_channel'] = len(multi_channel)
replace_dict['nb_diag_plus_one'] = max(config[0] for config in config_subproc_map)+1
replace_dict['nb_color'] = max(1,len(self.matrix_elements[0].get('color_basis')))

misc.sprint(multi_channel)
misc.sprint(self.path, os.getcwd())
#raise Exception

# AV extra formatting (e.g. gg_tt was "{{true,true};,{true,false};,{false,true};};")
replace_dict['is_LC'] = replace_dict['is_LC'].replace(',',', ').replace('{{',' { ').replace('};, {',' },\n { ').replace('};};',' }')
ff.write(template % replace_dict)
split = replace_dict['is_LC'].split(';,')
misc.sprint(replace_dict['is_LC'])
for i in range(len(split)):
misc.sprint(split[i])
split[i] = ' ' + split[i].replace(',',', ').replace('{{', '{')
misc.sprint(split[i])
if '};};' in split[i]:
split[i] = split[i][:-4] + '}, // channelIdC=%i' % i
elif 'false' in split[i] or 'true' in split[i]:
split[i] += ', // channelIdC=%i' % i
misc.sprint(split[i])
replace_dict['is_LC'] = '\n'.join(split)
ff.write(template % replace_dict)
ff.close()

# AV - new method
Expand Down

0 comments on commit 5b6d065

Please sign in to comment.