Skip to content

Added macro for generating element-wise methods #47625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

leobeltra
Copy link

@leobeltra leobeltra commented Mar 19, 2025

PR description:

Added two new macros: SOA_ELEMENT_METHODS and SOA_CONST_ELEMENT_METHODS. The user can declare functions with an arbitrary number of input and template arguments inside these macros. The functions will act on the elements (rows) of the SoA. A static assert has been added to ensure no multiple calls to these macros within the main macro are done.

PR validation:

Added a unit test that passes.

@cmsbuild
Copy link
Contributor

cmsbuild commented Mar 19, 2025

cms-bot internal usage

@cmsbuild
Copy link
Contributor

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-47625/44146

@cmsbuild
Copy link
Contributor

A new Pull Request was created by @leobeltra for master.

It involves the following packages:

  • DataFormats/Portable (heterogeneous)
  • DataFormats/SoATemplate (heterogeneous)

@cmsbuild, @fwyzard, @makortel can you please review it and eventually sign? Thanks.
@missirol, @mmusich, @rovere this is something you requested to watch as well.
@antoniovilela, @mandrenguyen, @rappoccio, @sextonkennedy you are the release manager for this.

cms-bot commands are listed here

@cmsbuild
Copy link
Contributor

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-47625/44151

@cmsbuild
Copy link
Contributor

Pull request #47625 was updated. @cmsbuild, @fwyzard, @makortel can you please check and sign again.

@fwyzard
Copy link
Contributor

fwyzard commented Mar 19, 2025

enable gpu

@fwyzard
Copy link
Contributor

fwyzard commented Mar 19, 2025

please test

@cmsbuild
Copy link
Contributor

-1

Failed Tests: rocmUnitTests
Size: This PR adds an extra 48KB to repository
Summary: https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-53d8ae/45077/summary.html
COMMIT: bcbb332
CMSSW: CMSSW_15_1_X_2025-03-19-1100/el8_amd64_gcc12
Additional Tests: CUDA ROCM
User test area: For local testing, you can use /cvmfs/cms-ci.cern.ch/week1/cms-sw/cmssw/47625/45077/install.sh to create a dev area with all the needed externals and cmssw changes.

ROCm Unit Tests

I found 1 errors in the following unit tests:

---> test testRocmSoALayoutAndView_t had ERRORS

Comparison Summary

Summary:

  • You potentially removed 2 lines from the logs
  • Reco comparison results: 4 differences found in the comparisons
  • DQMHistoTests: Total files compared: 50
  • DQMHistoTests: Total histograms compared: 3928069
  • DQMHistoTests: Total failures: 6
  • DQMHistoTests: Total nulls: 0
  • DQMHistoTests: Total successes: 3928043
  • DQMHistoTests: Total skipped: 20
  • DQMHistoTests: Total Missing objects: 0
  • DQMHistoSizes: Histogram memory added: 0.0 KiB( 49 files compared)
  • Checked 215 log files, 184 edm output root files, 50 DQM output files
  • TriggerResults: no differences found

CUDA Comparison Summary

Summary:

  • No significant changes to the logs found
  • Reco comparison results: 9 differences found in the comparisons
  • DQMHistoTests: Total files compared: 7
  • DQMHistoTests: Total histograms compared: 53071
  • DQMHistoTests: Total failures: 385
  • DQMHistoTests: Total nulls: 0
  • DQMHistoTests: Total successes: 52686
  • DQMHistoTests: Total skipped: 0
  • DQMHistoTests: Total Missing objects: 0
  • DQMHistoSizes: Histogram memory added: 0.0 KiB( 6 files compared)
  • Checked 24 log files, 30 edm output root files, 7 DQM output files
  • TriggerResults: no differences found

ROCM Comparison Summary

There are some workflows for which there are errors in the baseline:
12834.403 step 3
The results for the comparisons for these workflows could be incomplete
This means most likely that the IB is having errors in the relvals.The error does NOT come from this pull request

Summary:

  • You potentially removed 104 lines from the logs
  • ROOTFileChecks: Some differences in event products or their sizes found
  • Reco comparison results: 0 differences found in the comparisons
  • DQMHistoTests: Total files compared: 6
  • DQMHistoTests: Total histograms compared: 36901
  • DQMHistoTests: Total failures: 22
  • DQMHistoTests: Total nulls: 0
  • DQMHistoTests: Total successes: 36879
  • DQMHistoTests: Total skipped: 0
  • DQMHistoTests: Total Missing objects: 0
  • DQMHistoSizes: Histogram memory added: 0.0 KiB( 5 files compared)
  • Checked 23 log files, 30 edm output root files, 6 DQM output files

@fwyzard
Copy link
Contributor

fwyzard commented Mar 19, 2025

The ROCm failure is expected, as it is testing some error conditions... but I guess we need to rewrite the test so that it report it as "success" rather than "failure".

@fwyzard
Copy link
Contributor

fwyzard commented Mar 19, 2025

ignore tests-rejected with ib-failure

BOOST_PP_EMPTY())

/* Preprocessing loop for managing functions generation: only macros containing valid content are expanded */
#define ENUM_FOR_PRED(r, state) BOOST_PP_LESS(BOOST_PP_TUPLE_ELEM(0, state), BOOST_PP_TUPLE_ELEM(1, state))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed this earlier.

Here and below, can you change the arguments to uppercase, to keep the same convention as the rest of the code ?

Suggested change
#define ENUM_FOR_PRED(r, state) BOOST_PP_LESS(BOOST_PP_TUPLE_ELEM(0, state), BOOST_PP_TUPLE_ELEM(1, state))
#define ENUM_FOR_PRED(R, STATE) BOOST_PP_LESS(BOOST_PP_TUPLE_ELEM(0, STATE), BOOST_PP_TUPLE_ELEM(1, STATE))

Also, what are 0 and 1 here ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those 0and 1 are the arguments of state, a tuple composed by: a number starting from 0 and incrementing at every step, until the second argument, that is the size of the variadic sequence. The third argument is the sequence which will be unrolled. This BOOST_PP_FOR loop is needed to let the user define methods with an arbitrary number of commas inside the macro.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks.

@fwyzard
Copy link
Contributor

fwyzard commented Apr 1, 2025

@leobeltra do you have a preference if we should merge first #47306 or #47625 (this PR) ?

@leobeltra
Copy link
Author

@leobeltra do you have a preference if we should merge first #47306 or #47625 (this PR) ?

We could merge #47306 first since it will be easier to rebase this on top of that.

@@ -2,4 +2,4 @@
<use name="DataFormats/Portable"/>
<use name="DataFormats/SoATemplate"/>
<use name="catch2"/>
</bin>
</bin>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add back the final newline.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, this file and package should not have any changes.

@@ -52,6 +52,10 @@ of elements in the SoA), `byteSize()`, `byteAlignment()`, `data()` (a pointer to
function computes the first byte of a structure right after a layout, allowing using a single buffer for multiple
layouts.

## Customized methods

It is possible to generate methods inside the `element` and `const_element` nested structs using the `SOA_METHODS` and `SOA_CONST_METHODS` macros. More than one declaration of these macros are not allowed and all the customized methods can be implemented as macro argument. [An example is showed below.](#examples)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
It is possible to generate methods inside the `element` and `const_element` nested structs using the `SOA_METHODS` and `SOA_CONST_METHODS` macros. More than one declaration of these macros are not allowed and all the customized methods can be implemented as macro argument. [An example is showed below.](#examples)
It is possible to generate methods inside the `element` and `const_element` nested structs using the `SOA_METHODS` and `SOA_CONST_METHODS` macros. Each of these macros can be called only once, and can define multiple methods. [An example is showed below.](#examples)

y() *= arg;
z() *= arg;
}
),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
),
),

Comment on lines 14 to 27
SOA_ELEMENT_METHODS(void normalise() {
float norm_position = square_norm_position();
if (norm_position > 0.0f) {
x() /= norm_position;
y() /= norm_position;
z() /= norm_position;
};
double norm_velocity = square_norm_velocity();
if (norm_velocity > 0.0f) {
v_x() /= norm_velocity;
v_y() /= norm_velocity;
v_z() /= norm_velocity;
};
}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SOA_ELEMENT_METHODS(void normalise() {
float norm_position = square_norm_position();
if (norm_position > 0.0f) {
x() /= norm_position;
y() /= norm_position;
z() /= norm_position;
};
double norm_velocity = square_norm_velocity();
if (norm_velocity > 0.0f) {
v_x() /= norm_velocity;
v_y() /= norm_velocity;
v_z() /= norm_velocity;
};
}),
SOA_ELEMENT_METHODS(
void normalise() {
float norm_position = square_norm_position();
if (norm_position > 0.0f) {
x() /= norm_position;
y() /= norm_position;
z() /= norm_position;
};
double norm_velocity = square_norm_velocity();
if (norm_velocity > 0.0f) {
v_x() /= norm_velocity;
v_y() /= norm_velocity;
v_z() /= norm_velocity;
};
}
),

that is, move the method to a new line, like in the example below.

const { return sqrt(v_x() * v_x() + v_y() * v_y() + v_z() * v_z()); };

template <typename T1, typename T2>
auto time(T1 pos, T2 vel) const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function does not use any of the element data members.
Should it be marked as static ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The examples mix the syntax view[i].x() and view.x()[i] in a seemingly random way.

Is it intended to show that both syntaxes work ?
Otherwise I would prefer to consistently use the former, view[i].x().

@fwyzard
Copy link
Contributor

fwyzard commented Apr 4, 2025

I trust you on the macro definitions :-)

@fwyzard
Copy link
Contributor

fwyzard commented Apr 4, 2025

I have only trivial comments about the documentation and test.

@fwyzard
Copy link
Contributor

fwyzard commented Apr 5, 2025

Now that #47306 has been merged, this PR needs to be rebased.

@cmsbuild
Copy link
Contributor

cmsbuild commented Apr 7, 2025

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-47625/44394

@cmsbuild
Copy link
Contributor

cmsbuild commented Apr 7, 2025

Pull request #47625 was updated. @cmsbuild, @fwyzard, @makortel can you please check and sign again.

@cmsbuild
Copy link
Contributor

cmsbuild commented Apr 9, 2025

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-47625/44430

@cmsbuild
Copy link
Contributor

cmsbuild commented Apr 9, 2025

Pull request #47625 was updated. @cmsbuild, @fwyzard, @makortel can you please check and sign again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants