Skip to content

Update CP2K easyblock for CUDA version#3983

Open
pavelToman wants to merge 4 commits intoeasybuilders:developfrom
pavelToman:patch-10
Open

Update CP2K easyblock for CUDA version#3983
pavelToman wants to merge 4 commits intoeasybuilders:developfrom
pavelToman:patch-10

Conversation

@pavelToman
Copy link
Copy Markdown
Contributor

@pavelToman pavelToman commented Nov 4, 2025

@pavelToman pavelToman marked this pull request as draft November 4, 2025 15:40
@pavelToman pavelToman changed the title Update cp2k easyblock for CUDA version Update CP2K easyblock for CUDA version Nov 4, 2025
@pavelToman pavelToman marked this pull request as ready for review November 5, 2025 16:01
@boegel boegel added the update label Nov 19, 2025
@boegel boegel added this to the release after 5.2.0 milestone Nov 19, 2025
Comment on lines +241 to +243
# ensure C++ linker flags are OK
if not options.get('CXX'):
options['CXX'] = os.getenv('MPICXX') or 'mpicxx'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If this is required then it would be more correct to complain if the usempi toolchain opts is not set.
Just changing compiler like this won't really work unless the EC's toolchain is verified to be something that includes MPI in the first place.
I know that is a user error but this is not good practice.

Comment on lines +245 to +248
# library search paths
for libdir in (os.path.join(sirius, 'lib'), os.path.join(sirius, 'lib64')):
if os.path.isdir(libdir):
options['LDFLAGS'] += f' -L{libdir}'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we really need this? Isn't this handled by our framework already?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Compare with the other options, like ELPA or CUDA, they aren't setting LDFLAGS

Comment on lines +276 to +279
# find cuda compute capabilities and pass it to ARCH_NUMBER
# from https://github.com/cp2k/cp2k/blob/v2025.2/exts/build_dbcsr/Makefile#L78
get_gpu_cc = run_shell_cmd('nvidia-smi --query-gpu=compute_cap', hidden=True)
gpu_arch = get_gpu_cc.output.splitlines()[-1].strip().replace('.', '')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is not correct, this sets ARCH_NUMBER to whatever compute_cap that the GPU the build is running on has instead of what the cuda-compute-capabilities configuration option specifies.

options['DFLAGS'] += ' -D__OFFLOAD_CUDA -D__DBCSR_ACC '
options['LIBS'] += ' -lcufft -lcudart -lnvrtc -lcuda -lcublas'
options['OFFLOAD_CC'] = 'nvcc'
options['OFFLOAD_FLAGS'] = "-O3 -g -w --std=c++11 $(DFLAGS) -Xcompiler='-fopenmp -Wall -Wextra' "
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should take the EB settings of the flags into account. Hardcoding is bad practice.

Copy link
Copy Markdown
Contributor

@akesandgren akesandgren Mar 4, 2026

Choose a reason for hiding this comment

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

and the fopenmp should not be hardcoded, it should only be used when toolchainopts openmp is true, see usage of

self.toolchain.get_flag('openmp')

below (~line 368)

options['OFFLOAD_FLAGS'] = "-O3 -g -w --std=c++11 $(DFLAGS) -Xcompiler='-fopenmp -Wall -Wextra' "
options['OFFLOAD_TARGET'] = 'cuda'
options['ARCH_NUMBER'] = gpu_arch
options['CXX'] = 'mpicxx'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Again, should not hardcode to mpicxx, must use the toolchains setting, i.e. toolchainopts usempi must be true and then CXX will already be correctly set.

options['OFFLOAD_TARGET'] = 'cuda'
options['ARCH_NUMBER'] = gpu_arch
options['CXX'] = 'mpicxx'
options['CXXFLAGS'] = '-O3 -fopenmp -g -w --std=c++14 -fPIC $(DFLAGS) $(INCS)'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here, don't hardcode options.


options['DFLAGS'] += ' -D__OFFLOAD_CUDA -D__DBCSR_ACC '
options['LIBS'] += ' -lcufft -lcudart -lnvrtc -lcuda -lcublas'
options['OFFLOAD_CC'] = 'nvcc'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think there is a framework setting for this too, @boegel ?
I.e. what nvcc is supposed to be instead of hardcoding

def configure_common(self):
"""Common configuration for all toolchains"""

cp2k_version = LooseVersion(self.version)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should be set once as self.cp2k_version probably in init and then used

if hasattr(self.toolchain, 'MPI_FAMILY') and self.toolchain.MPI_FAMILY is not None:
known_mpi2_fams = [toolchain.MPICH, toolchain.MPICH2, toolchain.MVAPICH2, toolchain.OPENMPI,
toolchain.INTELMPI]
known_mpi2_fams = [
Copy link
Copy Markdown
Contributor

@akesandgren akesandgren Mar 4, 2026

Choose a reason for hiding this comment

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

The check for mpi should probably be done much earlier in the code, then it should also check that openmpi toochainopts is true, and then there would be no reason to change CXX/CC

Comment on lines +436 to +438
options['INCS'] += f' -I{self.libsmm_path}/include'
# library search path (keep both lib and lib64 in case)
options['LDFLAGS'] += f' -L{self.libsmm_path}/lib'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should consistently use os.path.join, not hardcoded "/"

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CP2K

3 participants