Skip to content

getting false negative error by SYCLomatic when migrating external CUDA host device function template #2192

@ArberSephirotheca

Description

@ArberSephirotheca

Describe the bug

When I try to migrate the code containing extern template

#include <cuda_runtime.h>


template <typename Outtype>
class foo1{};

template <typename Out>
 __device__ __host__ foo1<Out> foo()
{

    return foo1<Out>{};
    
}


extern template foo1<float> foo();
extern template foo1<double> foo();

int main(){
    foo1<float> foo();
}

I got the following errors:

error: explicit instantiation of 'foo' does not refer to a function template, variable template, member function, member class, or static data member
   16 | extern template foo1<float> foo();
note: candidate template ignored: target attributes do not match
    8 |  __device__ __host__ foo1<Out> foo()
 error: explicit instantiation of 'foo' does not refer to a function template, variable template, member function, member class, or static data member
   17 | extern template foo1<double> foo();
 note: candidate template ignored: target attributes do not match
    8 |  __device__ __host__ foo1<Out> foo()

code after migration:

#include <sycl/sycl.hpp>
#include <dpct/dpct.hpp>

template <typename Outtype>
class foo1{};

template <typename Out>
 foo1<Out> foo()
{

    return foo1<Out>{};
    
}


extern template foo1<float> foo();
extern template foo1<double> foo();

int main(){
    foo1<float> foo();
}

However, icpx is able to compile the migrated code without any issues.

To reproduce

#include <cuda_runtime.h>


template <typename Outtype>
class foo1{};

template <typename Out>
 __device__ __host__ foo1<Out> foo()
{

    return foo1<Out>{};
    
}


extern template foo1<float> foo();
extern template foo1<double> foo();

int main(){
    foo1<float> foo();
}

Environment

  • OS: Linux
  • Target device and vendor: Nvidia GPU
  • DPC++ version: Intel(R) oneAPI DPC++/C++ Compiler 2024.2.0 (2024.2.0.20240602)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions