Skip to content

Commit

Permalink
Merge pull request #877 from valassi/color2
Browse files Browse the repository at this point in the history
Further fixes/improvements for iconfig-channel mappings in coloramps.h
  • Loading branch information
valassi authored Jul 3, 2024
2 parents 3ffb82a + 7260a27 commit 6ba6bae
Show file tree
Hide file tree
Showing 249 changed files with 13,306 additions and 8,924 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/testsuite_oneprocess.sh
Original file line number Diff line number Diff line change
Expand Up @@ -535,11 +535,11 @@ if [ $BYPASS_KNOWN_ISSUES -eq 1 ] && [ $status -ne 0 ]; then
# Known issues in tmad_test
if [ "$stage" == "tmad_test" ]; then
# No cross section in susy_gg_t1t1 (#826)
###if [ "${proc%.mad}" == "susy_gg_t1t1" ]; then bypassIssue "No cross section in ${proc%.mad} for FPTYPE=d,f,m (#826)"; fi
if [ "${proc%.mad}" == "susy_gg_t1t1" ]; then bypassIssue "No cross section in ${proc%.mad} for FPTYPE=d,f,m (#826)"; fi
# LHE color mismatch in gg_ttgg for iconfig=104 (#856)
###if [ "${proc%.mad}" == "gg_ttgg" ]; then bypassIssue "LHE color mismatch for iconfig=104 in ${proc%.mad} for FPTYPE=d,f,m (#856)"; fi
if [ "${proc%.mad}" == "gg_ttgg" ]; then bypassIssue "LHE color mismatch for iconfig=104 in ${proc%.mad} for FPTYPE=d,f,m (#856)"; fi
# Cross section mismatch in pp_tt012j for P2_gu_ttxgu (#872)
###if [ "${proc%.mad}" == "pp_tt012j" ]; then bypassIssue "Cross section mismatch for P2_gu_ttxgu in ${proc%.mad} for FPTYPE=d,f,m (#856)"; fi
if [ "${proc%.mad}" == "pp_tt012j" ]; then bypassIssue "Cross section mismatch for P2_gu_ttxgu in ${proc%.mad} for FPTYPE=d,f,m (#856)"; fi
# Final printout
if [ $status -ne 0 ]; then echo "[testsuite_oneprocess.sh] $stage ($proc) FPTYPE=${FPTYPE}: issue will not be bypassed, test has FAILED"; fi
fi
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/testsuite_oneprocess.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ jobs:
echo "Workflow PR number is ${{ steps.split.outputs.prnum }}"
echo "Current directory is $(pwd)"
echo "Current git commit is $(git log --oneline -n1 | cut -d' ' -f1)"
echo "=== START git log for current git commit"
git log -n1
echo "=== END git log for current git commit"
# See https://github.com/actions/cache/blob/main/tips-and-workarounds.md#force-deletion-of-caches-overriding-default-cache-eviction-policy
gh extension install actions/gh-actions-cache
REPO=${{ github.repository }}
Expand Down Expand Up @@ -189,7 +192,7 @@ jobs:
echo "Workflow ref_name is ${{ github.ref_name }}"
echo "Workflow PR number is ${{ steps.split.outputs.prnum }}"
echo "Current directory is $(pwd)"
###echo "Current git commit is $(git log --oneline -n1 | cut -d' ' -f1)"
echo "Current git commit is $(git log --oneline -n1 | cut -d' ' -f1)"
# See https://github.com/actions/cache/blob/main/tips-and-workarounds.md#force-deletion-of-caches-overriding-default-cache-eviction-policy
gh extension install actions/gh-actions-cache
REPO=${{ github.repository }}
Expand Down
2 changes: 1 addition & 1 deletion MG5aMC/mg5amcnlo
Original file line number Diff line number Diff line change
@@ -1,41 +1,45 @@
// Copyright (C) 2020-2024 CERN and UCLouvain.
// Licensed under the GNU Lesser General Public License (version 3 or later).
// Created by: A. Valassi (Dec 2022) for the MG5aMC CUDACPP plugin.
// Further modified by: A. Valassi (2022-2024) for the MG5aMC CUDACPP plugin.
// Further modified by: O. Mattelaer, A. Valassi (2022-2024) for the MG5aMC CUDACPP plugin.

#ifndef COLORAMPS_H
#define COLORAMPS_H 1

#include <map>
// Note: strictly speaking the check '#ifdef MGONGPU_SUPPORTS_MULTICHANNEL' is not needed here,
// because coloramps.h is not included otherwise, but adding it does not harm and makes the code clearer

#ifdef MGONGPU_SUPPORTS_MULTICHANNEL /* clang-format off */

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 (CHANNEL_ID) in [0, N_diagrams]: not all values are allowed (N_config <= N_diagrams distinct values)
// => this number (with indexing like ps/pdf output) is passed around as an API argument between cudacpp functions
// 0 is allowed to fallback to no multi-channel mode.
// - Channel number in C indexing: "IconfiC", this is the equivalent of the Fortran iconfig
// iconfigC = iconfig -1
// provides a continuous index [0, N_config-1] for array
// iconfigC = ChannelId_to_iconfigC[channelId]
//NOTE: All those ordering are event by event specific (with the intent to have those fix within a vector size/wrap

// Map channelId to iconfigC
// This array has N_diagrams+1 elements, but only N_config <= N_diagrams valid values
// unvalid values are set to -1
// 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_iconfigC[%(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
// - Channel number ("channelId" in C, CHANNEL_ID in F) in [1, N_diagrams]: not all values are allowed (N_config <= N_diagrams distinct values)
// => this number (with F indexing as in ps/pdf output) is passed around as an API argument between cudacpp functions
// Note: the old API passes around a single CHANNEL_ID (and uses CHANNEL_ID=0 to indicate no-multichannel mode, but this is not used in coloramps.h),
// while the new API passes around an array of CHANNEL_ID's (and uses a NULL array pointer to indicate no-multichannel mode)
// - Channel number in C indexing: "channelID - 1"
// => this number (with C indexing) is used as the index of the channel2iconfig array below
// - Config number ("iconfig" in C, ICONFIG in F) in [1, N_config]: all values are allowed (N_config <= N_diagrams distinct values)
// - Config number in C indexing: "iconfig - 1"
// => this number (with C indexing) is used as the index of the icolamp array below

// Map channel to iconfig (e.g. "iconfig = channel2iconfig[channelId - 1]": input index uses C indexing, output index uses F indexing)
// Note: iconfig=-1 indicates channels/diagrams with no associated iconfig for single-diagram enhancement in the MadEvent sampling algorithm (presence of 4-point interaction?)
// This array has N_diagrams elements, but only N_config <= N_diagrams valid values (iconfig>0)
__device__ constexpr int channel2iconfig[%(nb_diag)i] = { // note: a trailing comma in the initializer list is allowed
%(channelc2iconfig_lines)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] = {
// Map iconfig to the mask of allowed colors (e.g. "colormask = icolamp[iconfig - 1]": input index uses C indexing)
// This array has N_config <= N_diagrams elements
__device__ constexpr bool icolamp[%(nb_channel)s][%(nb_color)s] = { // note: a trailing comma in the initializer list is allowed
%(is_LC)s
};

}
#endif /* clang-format on */

#endif // COLORAMPS_H
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
// *** COLOR CHOICE BELOW ***
// Store the leading color flows for choice of color
if( jamp2_sv ) // disable color choice if nullptr
for( int icolC = 0; icolC < ncolor; icolC++ )
jamp2_sv[ncolor * iParity + icolC] += cxabs2( jamp_sv[icolC] ); // may underflow #831
for( int icol = 0; icol < ncolor; icol++ )
jamp2_sv[ncolor * iParity + icol] += cxabs2( jamp_sv[icol] ); // may underflow #831

// *** COLOR MATRIX BELOW ***
// (This method used to be called %(process_class_name)s::matrix_%(proc_name)s(%(matrix_args)s)?)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
! Copyright (C) 2020-2024 CERN and UCLouvain.
! Licensed under the GNU Lesser General Public License (version 3 or later).
! Modified by: A. Valassi (Sep 2021) for the MG5aMC CUDACPP plugin.
! Further modified by: J. Teig, A. Valassi (2021-2024) for the MG5aMC CUDACPP plugin.
! Further modified by: O. Mattelaer, J. Teig, A. Valassi (2021-2024) for the MG5aMC CUDACPP plugin.
!==========================================================================

#include "GpuAbstraction.h"
Expand Down Expand Up @@ -72,15 +72,18 @@
// 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 iconfigC = mgOnGpu::channelId_to_iconfigC[channelId]; // coloramps.h uses a channel ordering not the diagram id
// NB (see #877): in the array channel2iconfig, the input index uses C indexing (channelId -1), the output index uses F indexing (iconfig)
const unsigned int iconfig = mgOnGpu::channel2iconfig[channelId - 1]; // map N_diagrams to N_config <= N_diagrams configs (fix LHE color mismatch #856: see also #826, #852, #853)
fptype targetamp[ncolor] = { 0 };
// NB (see #877): explicitly use 'icolC' rather than 'icol' to indicate that icolC uses C indexing in [0, N_colors-1]
for( int icolC = 0; icolC < ncolor; icolC++ )
{
if( icolC == 0 )
targetamp[icolC] = 0;
else
targetamp[icolC] = targetamp[icolC - 1];
if( mgOnGpu::icolamp[iconfigC][icolC] ) targetamp[icolC] += jamp2_sv[icolC];
// NB (see #877): in the array icolamp, the input index uses C indexing (iconfig -1)
if( mgOnGpu::icolamp[iconfig - 1][icolC] ) targetamp[icolC] += jamp2_sv[icolC];
}
//printf( "sigmaKin: ievt=%%4d rndcol=%%f\n", ievt, allrndcol[ievt] );
for( int icolC = 0; icolC < ncolor; icolC++ )
Expand Down Expand Up @@ -115,7 +118,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::channelId_to_iconfigC
#define _OMPLIST1 , allDenominators, allNumerators, channelId, mgOnGpu::icolamp, mgOnGpu::channel2iconfig
#else
#define _OMPLIST1
#endif
Expand Down Expand Up @@ -187,26 +190,28 @@
// 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 iconfigC = mgOnGpu::channelId_to_iconfigC[channelId]; // coloramps.h uses a channel ordering not the diagram id
// NB (see #877): in the array channel2iconfig, the input index uses C indexing (channelId -1), the output index uses F indexing (iconfig)
const unsigned int iconfig = mgOnGpu::channel2iconfig[channelId - 1]; // map N_diagrams to N_config <= N_diagrams configs (fix LHE color mismatch #856: see also #826, #852, #853)
fptype_sv targetamp[ncolor] = { 0 };
// NB (see #877): explicitly use 'icolC' rather than 'icol' to indicate that icolC uses C indexing in [0, N_colors-1]
for( int icolC = 0; icolC < ncolor; icolC++ )
{
if( icolC == 0 )
targetamp[icolC] = fptype_sv{ 0 };
else
targetamp[icolC] = targetamp[icolC - 1];
if( mgOnGpu::icolamp[iconfigC][icolC] ) targetamp[icolC] += jamp2_sv[icolC];
if( mgOnGpu::icolamp[iconfig - 1][icolC] ) targetamp[icolC] += jamp2_sv[icolC];
}
#if defined MGONGPU_CPPSIMD and defined MGONGPU_FPTYPE_DOUBLE and defined MGONGPU_FPTYPE2_FLOAT
const unsigned int iconfigC = mgOnGpu::channelId_to_iconfigC[channelId]; // coloramps.h uses a channel ordering not the diagram id
fptype_sv targetamp2[ncolor] = { 0 };
for( int icolC = 0; icolC < ncolor; icolC++ )
{
if( icolC == 0 )
targetamp2[icolC] = fptype_sv{ 0 };
else
targetamp2[icolC] = targetamp2[icolC - 1];
if( mgOnGpu::icolamp[iconfigC][icolC] ) targetamp2[icolC] += jamp2_sv[ncolor + icolC];
// NB (see #877): in the array icolamp, the input index uses C indexing (iconfig -1)
if( mgOnGpu::icolamp[iconfig - 1][icolC] ) targetamp2[icolC] += jamp2_sv[ncolor + icolC];
}
#endif
for( int ieppV = 0; ieppV < neppV; ++ieppV )
Expand Down
37 changes: 17 additions & 20 deletions epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/model_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1548,45 +1548,42 @@ def edit_coloramps(self, config_subproc_map):
# 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)
import math
ndigits = str(int(math.log10(nb_diag))+1+1) # the additional +1 is for the -sign
# 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):
channelidf = diag
channelidc = channelidf - 1 # C convention
if diag in diag_to_iconfig:
iconfigf = diag_to_iconfig[diag]
iconfigc = iconfigf - 1 # C convention
text = " %(iconfigc)i, // channelId=%(diag)i (diagram=%(diag)i) --> iconfig=%(iconfigf)i (f77 conv) and iconfigC=%(iconfigc)i (c conv)"
iconfigftxt = '%i'%iconfigf
else:
iconfigc = -1
iconfigf = -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, 'iconfigc': iconfigc, 'iconfigf':iconfigf})

replace_dict['diag_to_channel'] = '\n'.join(lines)
iconfigftxt = '-1 (diagram with no associated iconfig for single-diagram enhancement)'
text = ' %(iconfigf){0}i, // CHANNEL_ID=%(channelidf)-{0}i i.e. DIAGRAM=%(diag)-{0}i --> ICONFIG=%(iconfigftxt)s'.format(ndigits)
lines.append(text % {'diag':diag, 'channelidf':channelidf, 'iconfigf':iconfigf, 'iconfigftxt':iconfigftxt})
replace_dict['channelc2iconfig_lines'] = '\n'.join(lines)

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_diag'] = max(config[0] for config in config_subproc_map)
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};};")
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] + '}, // iconfigC=%i, diag=%i' % (i, iconfig_to_diag[i+1])
elif 'false' in split[i] or 'true' in split[i]:
split[i] += ', // iconfigC=%i, diag=%i' % (i, iconfig_to_diag[i+1])
misc.sprint(split[i])
###misc.sprint(replace_dict['is_LC'])
split = replace_dict['is_LC'].replace('{{','{').replace('};};','}').split(';,')
text=', // ICONFIG=%-{0}i <-- CHANNEL_ID=%i'.format(ndigits)
for iconfigc in range(len(split)):
###misc.sprint(split[iconfigc])
split[iconfigc] = ' ' + split[iconfigc].replace(',',', ').replace('true',' true').replace('{','{ ').replace('}',' }')
split[iconfigc] += text % (iconfigc+1, iconfig_to_diag[iconfigc+1])
replace_dict['is_LC'] = '\n'.join(split)
ff.write(template % replace_dict)
ff.close()
Expand Down
2 changes: 1 addition & 1 deletion epochX/cudacpp/CODEGEN/checkFormatting.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function checkProcdir()
cd $TOPDIR
if [ ! -d $procdir ]; then echo "ERROR! Directory not found $TOPDIR/$procdir"; exit 1; fi
# Define the list of files to be checked
files=$(\ls $procdir/src/*.cc $procdir/src/*.h $procdir/SubProcesses/*.cc $procdir/SubProcesses/*.h $procdir/SubProcesses/P*/check_sa.cc $procdir/SubProcesses/P*/CPPProcess.cc $procdir/SubProcesses/P*/CPPProcess.h $procdir/SubProcesses/P*/epoch_process_id.h)
files=$(\ls $procdir/src/*.cc $procdir/src/*.h $procdir/SubProcesses/*.cc $procdir/SubProcesses/*.h $procdir/SubProcesses/P*/check_sa.cc $procdir/SubProcesses/P*/CPPProcess.cc $procdir/SubProcesses/P*/CPPProcess.h $procdir/SubProcesses/P*/epoch_process_id.h $procdir/SubProcesses/P*/coloramps.h)
if [ "$files" == "" ]; then echo "ERROR! No files to check found in directory $TOPDIR/$procdir"; exit 1; fi
# Check each file
status=0
Expand Down
Loading

0 comments on commit 6ba6bae

Please sign in to comment.