Host Functions#

The following utilities are intended to be called from host code when preparing cuPQC-NTT kernel launches.

template<uint32_t N, typename Precision>
constexpr size_t ntt_shared_workspace_size(
)#

Returns the number of bytes of shared memory required for a single-stage NTT with N leaves and element type Precision.

Template Parameters:
  • N – Transform size (number of coefficients); must match the NTT descriptor Size<N>.

  • Precision – Field element type stored in the coefficient buffer.

template<uint32_t N, uint32_t M, typename Precision>
constexpr size_t fwd_stage_1_ntt_shared_workspace_size(
)#

Returns the number of bytes of shared memory required for the forward NTT first stage, with K = N/M elements per block.

Template Parameters:
  • N – Total transform size.

  • M – Sub-block size used with SubSize<M>() in the descriptor; K = N/M coefficients per block in this pass.

  • Precision – Field element type.

template<uint32_t N, uint32_t M, typename Precision>
constexpr size_t fwd_stage_2_ntt_shared_workspace_size(
)#

Returns the number of bytes of shared memory required for the forward NTT second stage, with M elements per block.

Template Parameters:
  • N – Total transform size.

  • M – Sub-block size; this pass uses M strided coefficients per block.

  • Precision – Field element type.

template<uint32_t N, uint32_t M, typename Precision>
constexpr size_t inv_stage_1_ntt_shared_workspace_size(
)#

Returns the number of bytes of shared memory required for the inverse NTT first stage, with M elements per block.

Template Parameters:
  • N – Total transform size.

  • M – Sub-block size; this pass uses M strided coefficients per block.

  • Precision – Field element type.

template<uint32_t N, uint32_t M, typename Precision>
constexpr size_t inv_stage_2_ntt_shared_workspace_size(
)#

Returns the number of bytes of shared memory required for the inverse NTT second stage, with K = N/M elements per block.

Template Parameters:
  • N – Total transform size.

  • M – Sub-block size; K = N/M consecutive coefficients per block in this pass.

  • Precision – Field element type.

template<uint32_t N, typename Precision>
Precision n_inv(Precision p)#

Computes N-1 mod p using Fermat’s little theorem. You can call this function to compute the normalisation factor N_inv, and then pass the return value as the N_inv argument to execute() (inverse) and stage_2_execute() (inverse). Note this function is supported for uint16_t and uint32_t only.

Template Parameters:
  • N – Transform size whose modular inverse is required (the same N as the NTT).

  • Precision – Unsigned integer type for p and the return value; must be uint16_t or uint32_t.

Parameters:

p – Odd prime modulus p with gcd(N, p) = 1 so N-1 mod p exists.