Skip to content
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

Adding HeterogeneousCore/AlpakaUtilities and changes into HeterogeneousCore/AlpakaInterface #40932

Closed
wants to merge 4 commits into from

Conversation

borzari
Copy link
Contributor

@borzari borzari commented Mar 2, 2023

Part 1/? of porting pixel track reconstruction code from CUDA to Alpaka. AlpakaUtilities have methods and tools to ease the work with Alpaka (based and modified from https://github.com/cms-patatrack/pixeltrack-standalone/tree/master/src/alpaka/AlpakaCore). AlpakaInterface changes comprise addition of functions for block/thread iteration inside kernels.

This PR is a suggestion from @makortel during 12th Patatrack Hackathon to split the work in several PRs to make incremental reviews.

@cmsbuild
Copy link
Contributor

cmsbuild commented Mar 2, 2023

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-40932/34416

  • This PR adds an extra 24KB to repository

  • Found files with invalid states:

    • HeterogeneousCore/AlpakaUtilities/interface/initialise.h:
    • HeterogeneousCore/AlpakaUtilities/interface/demangle.h:

@cmsbuild
Copy link
Contributor

cmsbuild commented Mar 2, 2023

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

It involves the following packages:

  • HeterogeneousCore/AlpakaInterface (heterogeneous)
  • HeterogeneousCore/AlpakaUtilities (****)

The following packages do not have a category, yet:

HeterogeneousCore/AlpakaUtilities
Please create a PR for https://github.com/cms-sw/cms-bot/blob/master/categories_map.py to assign category

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

cms-bot commands are listed here

@cmsbuild
Copy link
Contributor

cmsbuild commented Mar 2, 2023

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-40932/34417

  • This PR adds an extra 24KB to repository

@cmsbuild
Copy link
Contributor

cmsbuild commented Mar 2, 2023

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

@makortel
Copy link
Contributor

makortel commented Mar 3, 2023

My first high-level question is if the code really warrants a new package HeterogeneousCore/AlpakaUtilities, or could just be placed in HeterogeneousCore/AlpakaInterface.

Last week we discussed with @fwyzard and @rovere about the placement of VecArray, and the outcome was to just place it/them in HeterogeneousCore/AlpakaInterface. @fwyzard Do you still agree with this decision?

@fwyzard
Copy link
Contributor

fwyzard commented Mar 3, 2023

In principle yes, I didn't look at the implementation in this PR.

From a quick look, this code needs a thorough review (for example, I'm convinced there is a lot of duplication), but I won't have much time until Thursday.

Copy link
Contributor

@makortel makortel left a comment

Choose a reason for hiding this comment

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

From first pass

Comment on lines 1 to 6
<use name="rootcore"/>
<use name="boost"/>
<use name="eigen"/>
<use name="DataFormats/Common"/>
<use name="DataFormats/Portable"/>
<use name="DataFormats/SoATemplate"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I can tell, none of these dependencies are used. Or is there further code in the pipeline that would bring in some of these dependencies?

<use name="DataFormats/Portable"/>
<use name="DataFormats/SoATemplate"/>
<use name="HeterogeneousCore/AlpakaInterface"/>
<flags ALPAKA_BACKENDS="1"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

The ALPAKA_BACKENDS flag is not needed either as there is no code making use of ALPAKA_ACCELERATOR_NAMESPACE.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if that even does anything, for files that are just header files and are not inside the alpaka/ subdirectory ?

Comment on lines 10 to 12
#include "AtomicPairCounter.h"
#include "alpakastdAlgorithm.h"
#include "prefixScan.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Our convention is use full paths to the headers even if they are in the interface/ directory of the same package (only exceptions are cases where the source and header files are in src, plugins, or test).

};

template <typename TAcc, typename Histo, typename TQueue>
ALPAKA_FN_HOST ALPAKA_FN_INLINE __attribute__((always_inline)) void launchZero(Histo *__restrict__ h,
Copy link
Contributor

Choose a reason for hiding this comment

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

How necessary is ALPAKA_FN_HOST?

How necessary is ALPAKA_FN_INLINE given the __attribute__((always_inline))?

Comment on lines 75 to 77
alpaka::enqueue(
queue,
alpaka::createTaskKernel<TAcc>(workDiv, multiBlockPrefixScanFirstStep<uint32_t>(), poff, poff, num_items));
Copy link
Contributor

Choose a reason for hiding this comment

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

How about

Suggested change
alpaka::enqueue(
queue,
alpaka::createTaskKernel<TAcc>(workDiv, multiBlockPrefixScanFirstStep<uint32_t>(), poff, poff, num_items));
alpaka::exec<TAcc>(
queue,
workDiv, multiBlockPrefixScanFirstStep<uint32_t>(), poff, poff, num_items);

instead? (also below)

#include "prefixScan.h"

#include "HeterogeneousCore/AlpakaInterface/interface/memory.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

On a cursory look the config.h looks like it would not be needed here. Is it needed?

#include <type_traits>
#include <utility>

#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be replaced as

Suggested change
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include <alpaka/alpaka.hpp>

?


#include <utility>

#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be replaced as

Suggested change
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include <alpaka/alpaka.hpp>

?


template <typename T = void>
struct less {
ALPAKA_FN_HOST_ACC constexpr bool operator()(const T &lhs, const T &rhs) const { return lhs < rhs; }
Copy link
Contributor

Choose a reason for hiding this comment

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

According to cppreference, std::less::operator() has been constexpr since C++14. Is a separate implementation still needed?

#include <cstdint>
#include <type_traits>

#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be replaced as

Suggested change
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include <alpaka/alpaka.hpp>

?

@@ -302,6 +302,237 @@ namespace cms::alpakatools {
const Vec extent_;
};

/*********************************************
Copy link
Contributor

Choose a reason for hiding this comment

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

@borzari @nothingface0 could you point me to the use cases for

element_index_range_in_block
element_index_range_in_block_truncated
element_index_range_in_grid
element_index_range_in_grid_truncated

and

for_each_element_in_block
for_each_element_in_block_strided
for_each_element_in_grid_strided

?

Regarding the latter, do you prefer the lambda approach (pass a function object or lambda to the for_each_element_in_... call) or the range loop approach (get the index via a range loop, as with elements_with_stride) ?

Copy link
Contributor

@nothingface0 nothingface0 Mar 6, 2023

Choose a reason for hiding this comment

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

element_index_range_in_block

workdivision.h

here and here. It's then used by element_index_range_in_block_truncated and element_index_range_in_grid.

gpuClusterChargeCut.h

here

gpuPixelRecHits.h

here

gpuFishbone.h

here

gpuPixelDoubletsAlgos.h

here

element_index_range_in_block_truncated

workdivision.h

here. See for_each_element_in_block for implicit uses.

element_index_range_in_grid

workdivision.h

Inside for_each_element_in_grid_strided here.

gpuFishbone.h

here

gpuPixelDoubletsAlgos.h

here

element_index_range_in_grid_truncated

workdivision.h

Only used from overloaded function here. Not used anywhere else, can be deleted.


for_each_element_in_block

workdivision.h

Call from overloaded function here.

radixSort.h

here, here, here, here, here.

for_each_element_in_block_strided

workdivision.h

Call from overloaded function here.

radixSort.h

here, here, here, here, here, here, here, here, here, here, here, and here.

for_each_element_in_grid_strided

workdivision.h

Call from overloaded function here.

HistoContainer.h

here, here and here.

Comments

Since we didn't have the time to go in-depth in the patatrack-standalone algorithms, we did not try to change different ways of looping over the elements so that they're more uniform.
That said, personally speaking, the range approach (elements_with_stride) seems more intuitive, and it's cleaner in the code, too.

A visualized overview of the functions that depend on those functions can be seen below for easier(?) comprehension:

workdivision_usage drawio


static constexpr c_type incr = 1UL << 32;

ALPAKA_FN_HOST_ACC Counters get() const { return counter.counters; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be ALPAKA_FN_HOST_ACC or would it be enough to be ALPAKA_FN_ACC ?

// reimplementation of std algorithms able to compile with Alpaka,
// mostly by declaring them constexpr

namespace alpaka_std {
Copy link
Contributor

Choose a reason for hiding this comment

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

@makortel a technical question: would it work (and be allowed) to declare this as namespace alpaka::std ?

If we do that, any code inside namespace alpaka { ... } that uses std::lower_bound would pick which version ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd be wary in using namespace std even inside another namespace.

If we do that, any code inside namespace alpaka { ... } that uses std::lower_bound would pick which version ?

Based on our early attempts to use cms::alpaka namespace, and alpaka::<X> types there, I guess std::lower_bound inside namespace alpaka { ... } would resolve to alpaka::std::lower_bound, if the header defining it is #included, and otherwise to ::std::lower_bound. I also guess #includeng a header defining anything in alpaka::std namespace would cause code in alpaka namespace to need to use ::std:: for all std:: names that are not found in alpaka::std.

But within CMSSW we are not going to add names in alpaka namespace, are we?

Copy link
Contributor

Choose a reason for hiding this comment

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

But within CMSSW we are not going to add names in alpaka namespace, are we?

No, but I'm wondering in case we push these upstream into Alpaka.

@cmsbuild
Copy link
Contributor

cmsbuild commented Mar 5, 2023

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-40932/34443

  • This PR adds an extra 24KB to repository

@smuzaffar
Copy link
Contributor

Milestone for this pull request has been moved to CMSSW_14_0_X.Please open a backport if it should also go in to CMSSW_13_3_X.

@cmsbuild
Copy link
Contributor

cmsbuild commented Feb 6, 2024

Milestone for this pull request has been moved to CMSSW_14_1_X. Please open a backport if it should also go in to CMSSW_14_0_X.

@cmsbuild cmsbuild modified the milestones: CMSSW_14_0_X, CMSSW_14_1_X Feb 6, 2024
@fwyzard
Copy link
Contributor

fwyzard commented Feb 6, 2024

@borzari am I right that these changes have been merged as part of the large Alpaka migration ?

If so, can you close this PR ?

@cmsbuild cmsbuild modified the milestones: CMSSW_14_0_X, CMSSW_14_1_X Feb 6, 2024
@borzari
Copy link
Contributor Author

borzari commented Feb 6, 2024

@borzari am I right that these changes have been merged as part of the large Alpaka migration ?

If so, can you close this PR ?

Hi @fwyzard. Yes, it was all included in the Alpaka migration. I am closing this.

@borzari borzari closed this Feb 6, 2024
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.

6 participants