tfel
Loading...
Searching...
No Matches
GPUStackSize.hxx File Reference

This file declares a function adapting the stack size of the threads of the device to a CUDA or HIP kernel, used by the generic-parallel interface for material properties. This file must be compiled by a CUDA or a HIP compiler. The HIP runtime is used if the hip/hip_runtime.h header has been included before this file or if the HIP language is enabled, the CUDA runtime otherwise. More...

#include <mutex>
#include <string>
#include <cstddef>
#include <cuda_runtime.h>
#include "MFront/GenericParallel/DeviceStackSize.hxx"

Classes

struct  mfront::generic_parallel::gpu::StackSizeCheck
 result of ensureStackSize More...

Namespaces

namespace  mfront
 This namespace contains material used to build the MFront code generator.
namespace  mfront::generic_parallel

Macros

#define MFRONT_GENERIC_PARALLEL_GPU_API(f)

Typedefs

using mfront::generic_parallel::gpu::Error = MFRONT_GENERIC_PARALLEL_GPU_API(Error_t)
 error code of the runtime

Functions

template<auto kernel>
StackSizeCheck mfront::generic_parallel::gpu::ensureStackSize (const bool preserve) noexcept
 increase the stack size of the threads of the current device if the given kernel requires it. The default stack size (1024 bytes with CUDA) is too small for some kernels, and the increase performed by the runtime at kernel launch does not account for the internal routines of the compilers (see setMinimalCUDAStackSize), hence the margin added below to the static estimate of the local memory of the kernel.

Detailed Description

This file declares a function adapting the stack size of the threads of the device to a CUDA or HIP kernel, used by the generic-parallel interface for material properties. This file must be compiled by a CUDA or a HIP compiler. The HIP runtime is used if the hip/hip_runtime.h header has been included before this file or if the HIP language is enabled, the CUDA runtime otherwise.

Date
08/10/2026

Macro Definition Documentation

◆ MFRONT_GENERIC_PARALLEL_GPU_API

#define MFRONT_GENERIC_PARALLEL_GPU_API ( f)
Value:
cuda##f

Function Documentation

◆ ensureStackSize()

template<auto kernel>
StackSizeCheck mfront::generic_parallel::gpu::ensureStackSize ( const bool preserve)
noexcept

increase the stack size of the threads of the current device if the given kernel requires it. The default stack size (1024 bytes with CUDA) is too small for some kernels, and the increase performed by the runtime at kernel launch does not account for the internal routines of the compilers (see setMinimalCUDAStackSize), hence the margin added below to the static estimate of the local memory of the kernel.

The kernel is a template argument, so that this function is instantiated in the library defining the kernel. The CUDA runtime is linked statically by default: each library has its own instance of the runtime, which only knows the kernels of this library. A function shared by several libraries, for instance a function taking the kernel as argument, would be resolved to the instance of one library by the dynamic linker.

Template Parameters
kernelkernel
Parameters
[in]preserveif true, the stack size is not modified, and the required stack size is returned if the current one is too small