Skip to content

xlnet_preprocess_kernels: blockAttnMask primary template is written as an illegal function-template partial specialization #799

Description

@diskdog

src/fastertransformer/kernels/xlnet_preprocess_kernels.cu defines the primary template of blockAttnMask with a template-argument list after the function name:

template<typename T>
void blockAttnMask<T>(dim3& grid, dim3& block, int batch_size, int seq_len)
{
    ...
}

The primary template is already declared in xlnet_preprocess_kernels.h as template<typename T> void blockAttnMask(dim3&, dim3&, int, int);. Writing the definition as blockAttnMask<T>(...) makes it a partial specialization of a function template, which C++ does not permit (only class templates can be partially specialized). nvcc/EDG tolerates it as an extension, but standard-conforming CUDA compilers (clang-CUDA, and AMD-targeting CUDA toolchains) reject it:

error: function template partial specialization is not allowed

The template<> void blockAttnMask<float>(...) further down is a legal full explicit specialization and stays as-is. The call site blockAttnMask<T>(...) in preProcess is also fine (explicit template arguments in a call are allowed).

Fix: drop the stray <T> on the primary-template definition

template<typename T>
void blockAttnMask(dim3& grid, dim3& block, int batch_size, int seq_len)
{
    ...
}

Verified

Minimal reproducer mirroring the header declaration plus the definition, compiled with NVIDIA nvcc (CUDA 13.1, sm_75) and a clang-based CUDA compiler:

code nvcc non-nvcc CUDA
original (blockAttnMask<T> definition) compiles fails (function template partial specialization)
fix (<T> removed) compiles compiles

Behaviour is identical; the fix is a no-op under nvcc and standard-correct, which makes the kernel portable to other CUDA compilers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions