Skip to content

HEXHEX Packed List Implementation - #682

Open
michaelmckinsey1 wants to merge 18 commits into
developfrom
hexhex-opt
Open

HEXHEX Packed List Implementation#682
michaelmckinsey1 wants to merge 18 commits into
developfrom
hexhex-opt

Conversation

@michaelmckinsey1

@michaelmckinsey1 michaelmckinsey1 commented May 20, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR adds GPU optimizations to the INTSC_HEXHEX kernel. In summary the following changes are made

  1. Switch from a linked list(which was getting spilled to local memory) to a 64-bit packed list that uses much less memory and much more frequently gets accessed from the registers.
  2. Use shared memeory to store thread-local arrays to prevent local memory usage due to indirect array indexing

NOTE: This PR also adds a functionality to associate a caliper file with a git_hash for each commit so we have uniquely associate a .cali file to a commit. This was requested by @pearce8. Not sure if that needs to be included in this PR and can be taken out if needed.

  • This PR is an optimization
  • It does the following (modify list as needed):
    • Modifies src/apps/INTSC_HEXHEX_BODY.hpp
    • Modifies src/rajaperf_config.hpp.in

@michaelmckinsey1 michaelmckinsey1 self-assigned this May 20, 2026
@MrBurmark

Copy link
Copy Markdown
Member

Having both for now seems like a good idea. @jmgrandy can decide if we want to merge them or not as he added the kernel and knows what it's trying to represent.

@michaelmckinsey1

Copy link
Copy Markdown
Contributor Author

Having both for now seems like a good idea. @jmgrandy can decide if we want to merge them or not as he added the kernel and knows what it's trying to represent.

Ok that's fine. We'll end up renaming it if we keep it separate.

@MrBurmark

Copy link
Copy Markdown
Member

@stingyemperor Can you add slirp and .codex to the .gitignore?

@MrBurmark

MrBurmark commented Jun 9, 2026

Copy link
Copy Markdown
Member

Also please remove the run outputs and build stuff.

@rhornung67

Copy link
Copy Markdown
Member

Please don't commit build directories, run output, codex files, etc. I suggest that when you execute git add you specify specific files rather than using wildcard.

Comment thread src/apps/.gitignore Outdated
Comment thread src/apps/compile_commands.json Outdated
Comment thread src/apps/.codex Outdated
Comment thread src/apps/slirp.out Outdated
Comment thread src/apps/slurm-238759.out Outdated
Comment thread src/apps/slurm-238789.out Outdated
Comment thread src/apps/slurm-238793.out Outdated
Comment thread src/apps/slurm-238920.out Outdated
Comment thread build-linux-rhel8-sapphirerapids-ef7ukeq Outdated
Comment thread build-linux-rhel8-sapphirerapids-lzhesv4 Outdated
Comment thread dane-toss_4_x86_64_ib-intel-oneapi-compilers@2025.2.0-lzhesv42.cmake Outdated
Comment thread matrix-toss_4_x86_64_ib-gcc@12.1.1-ef7ukeql.cmake Outdated
Comment thread kernel_256_profile_raw.ncu-rep Outdated
Comment thread kernel_256_profile-base.cali Outdated
Comment thread matrix-toss_4_x86_64_ib-intel-oneapi-compilers@2025.2.0-lzhesv42.cmake Outdated
@stingyemperor

Copy link
Copy Markdown

Sorry, when I made initial commit, 610525e, I forgot that I was tracking all the changed files. I will only track changes for the kernel related files similar to 305652f .

I will make a new commit to fix this.

Please don't commit build directories, run output, codex files, etc. I suggest that when you execute git add you specify specific files rather than using wildcard.

@pearce8
pearce8 self-requested a review June 17, 2026 16:23
@pearce8 pearce8 changed the title [WIP] HEXHEX opt HEXHEX opt Jun 26, 2026
@pearce8 pearce8 changed the title HEXHEX opt [draft] HEXHEX opt Jun 26, 2026
@stingyemperor
stingyemperor marked this pull request as ready for review July 17, 2026 16:12
@stingyemperor stingyemperor changed the title [draft] HEXHEX opt HEXHEX opt Jul 17, 2026
@michaelmckinsey1 michaelmckinsey1 changed the title HEXHEX opt HEXHEX Packed List Implementation Jul 21, 2026
@michaelmckinsey1 michaelmckinsey1 added this to the July 2026 Release milestone Jul 28, 2026
Comment thread src/apps/INTSC_HEXHEX_BODY.hpp Outdated
Comment thread src/apps/INTSC_HEXHEX_BODY.hpp Outdated
Comment thread src/apps/INTSC_HEXHEX_BODY.hpp Outdated
Comment thread src/apps/INTSC_HEXHEX_BODY.hpp Outdated
Comment on lines +259 to +264
( HexHexScratchArray xdt, // donor triangle coordinates
HexHexScratchArray ydt,
HexHexScratchArray zdt,
HexHexScratchArray xtt, // target tet coordinates (modified here)
HexHexScratchArray ytt,
HexHexScratchArray ztt,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do these come in with HexHexScratchView &scratch? In fact why take scratch by reference instead of const ref or value here?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No, these are separate form HexHexScratchView &scratch. They are not const ref to signal that they get modified. I can change them to be const if needed.

Comment thread src/apps/INTSC_HEXHEX_BODY.hpp Outdated
Comment on lines +62 to +69
template < Size_type BlockSize >
struct HexHexScratchStorage {
// Element-major layout keeps lanes contiguous for shared-memory accesses.
Real_type xdt[3][BlockSize], ydt[3][BlockSize], zdt[3][BlockSize] ;
Real_type xtt[4][BlockSize], ytt[4][BlockSize], ztt[4][BlockSize] ;
Real_type xa[9][BlockSize], ya[9][BlockSize], za[9][BlockSize] ;
Real_type ha[9][BlockSize], h2[9][BlockSize] ;
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is 66 * BlockSize * sizeof(Real_type) is 33KiB when blocksize is 64. The max static shared memory is 48KiB on cuda. It might be a good idea to ensure that blocksize is limited based on this if the blocksize is allowed to be different than the default.

Comment thread src/rajaperf_config.hpp.in Outdated
@rhornung67

Copy link
Copy Markdown
Member

@jmgrandy please take a look at this and approve if you are OK with it, or comment if you want changes.

@MrBurmark

MrBurmark commented Sep 2, 2026

Copy link
Copy Markdown
Member

@stingyemperor I was able to avoid most of the scratch memory usage by indexing in a weird way. It performs the same as the version using shared memory on hip, however it is worse on cuda.
https://godbolt.org/z/xGr7nEqPK

template <size_t N>
struct HexHexScratchArray {
  Real_ptr data ;
  Index_type stride ;
  Index_type lane ;

  RAJA_HOST_DEVICE
  RAJA_INLINE HexHexScratchArray(Real_ptr const data_in,
                                 Index_type const stride_in,
                                 Index_type const lane_in)
      : data(data_in),
        stride(stride_in),
        lane(lane_in)
  {
  }

  RAJA_HOST_DEVICE
  RAJA_INLINE Real_type& operator[](Int_type const i) const
  {
    return access(i, std::make_index_sequence<N>{});
  }

  template < size_t... Is >
  RAJA_HOST_DEVICE
  RAJA_INLINE Real_type& access(Int_type const i, std::index_sequence<Is...>) const
  {
    Real_ptr d = data;
    (..., ((i == Is) ? (d = data + Is* stride + lane) : 0));
    return *d;
  }
};

@MrBurmark

Copy link
Copy Markdown
Member

I was able to remove the extra 20 scratch bytes with hip. They appeared to be caused by a failure to optimize the first and avail arguments to clip_polygon_ge_0. I changed them to pass by value and return, instead of passing by reference, and that removed the last of the scratch use. https://godbolt.org/z/sd4E43jn5

michaelmckinsey1 and others added 18 commits September 3, 2026 10:50
Will add flattened linked list algorithm developed by Samraat
Gupta and an array-like abstraction.
This speeds up the Hip kernel for INTSC_HEXHEX on the MI300 with
Rocm 7.2.1.  The CPU is a 96 core AMD Genoa.
The cuda test is run on an H100 with gcc 13.3.1 and Cuda 12.9.1
The CPU is a 56 core Intel Sapphire Rapids.  OpenMP is currently
available in RAJAPerf on the Sapphire Rapids but not on the Genoa.

This change reduces the difference between Base and RAJA for the CPU
sequential variant on both machines.  The flattened linked list is
faster than the original version on the Genoa but slower than the
original version on the Sapphire Rapids.

           original          flattened
	   version           linked list

MI300 / Genoa:

Base_Hip    2.549 ms          1.487 ms
RAJA_Hip    2.408 ms          1.516 ms

Base_Seq    0.834 sec         0.649 sec
RAJA_Seq    0.894 sec         0.676 sec

H100 / SPR:

RAJA_CUDA   2.625 ms          1.923 ms

Base_OpenMP 7.500 ms          8.905 ms
RAJA_OpenMP 7.458 ms          8.855 ms

Base_Seq    0.624 sec         0.750 sec
RAJA_Seq    0.663 sec         0.750 sec

The problem size is 15625 intersections so the flattened linked list
is slightly over 10 million intersections per second on the MI300 GPU.
This removes the initialization time that affects the first call
to the kernel, from the reported execution time.

The warmup calls were already in place for Hip; this is the
corresponding application of warmup calls for Cuda.
This is intended to improve the test by representing variations of
intersections in an actual application.  Although the zones are still
Cartesian aligned the x, y, z shifts of the target relative to the
donor varies in an irregular manner using a sine function.  This means
there are a considerable number of small intersections which may
produce different numbers of operations from the large intersections
in the prior version.  Although we thread over individual triangles,
the small intersections may create subtle effects on the branch
divergence between the individual triangle contributions.

Base_Hip time is 1.873 ms for this test (8.34 million intersections
per second, 15625 standard intersections) vs 1.487 ms in the prior
version (10.5 million intersections per second).  The value of 8.34
million intersections is reasonably close to what I obtain when
testing in an application code.  The prior version gave a result that
is too good to be true.

This is not a slowdown of the Hip kernel (on the MI300) because this
commit merely changes the input data of the test.

The checksums are showing agreement between the variants, and our
check indicates that the volumes and moments are being computed
correctly.
Also replaced a few int declarations with Int_type.
Signedness of comparison : change loop indices to Size_type.
Potential uninitialized use of "width" if caller makes an error
to INTSC_HEXHEX::shiftTarget.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants