hcc icon indicating copy to clipboard operation
hcc copied to clipboard

__attribute__((cpu, hc)) leads to linking errors (undefined reference)

Open jszuppe opened this issue 7 years ago • 1 comments

// When functions in classes tuple_value and tuple_impl are marked with
// hc and cpu attributes there are linking problems:
//
// /tmp/tmp.xgmMisjvuh/test_hc.cpp.host.o: In function `main':
// (.text+0x7af): undefined reference to `tuple_value<int>::tuple_value(int)'
// /tmp/tmp.xgmMisjvuh/test_hc.cpp.host.o: In function `main':
// (.text+0x7c1): undefined reference to `tuple_value<double>::tuple_value(double)'
// /tmp/tmp.xgmMisjvuh/test_hc.cpp.host.o: In function `main':
// (.text+0x7d3): undefined reference to `tuple_value<float>::tuple_value(float)'
// /tmp/tmp.xgmMisjvuh/test_hc.cpp.host.o: In function `main':
// (.text+0x7e2): undefined reference to `tuple_value<char>::tuple_value(char)'
// /tmp/tmp.xgmMisjvuh/test_hc.cpp.host.o: In function `main':
// (.text+0x7f1): undefined reference to `tuple_value<short>::tuple_value(short)'
// clang-7.0: error: linker command failed with exit code 1 (use -v to see invocation)
#define HOST_DEVICE __attribute__((hc, cpu))

// However, work when HOST_DEVICE is empty (pure C++)
// #define HOST_DEVICE

template<class T>
struct tuple_value
{
    HOST_DEVICE inline
    tuple_value(const tuple_value&) = default;
    HOST_DEVICE inline
    tuple_value(tuple_value&&) = default;
    HOST_DEVICE inline
    ~tuple_value() = default;

    template<class U>
    HOST_DEVICE
    explicit tuple_value(U&& v) noexcept : value(std::forward<U>(v))  
    {}

   (..)    

    T value;
};

template<class... Types>
struct tuple_impl : tuple_value<Types>...
{
    (...)

    template<class... UTypes>
    HOST_DEVICE inline
    explicit tuple_impl(UTypes&&... values)
        : tuple_value<Types>(std::forward<UTypes>(values))...
    { }
};

int main(int, char**)
{
    tuple_impl<int, double, float> t1(1, 1.0, 1.0f);
}

Full example code: undefined_reference_to_ctor.zip.

jszuppe avatar Aug 30 '18 11:08 jszuppe

Reproducible with latest ROCm 1.9. Investigating.

david-salinas avatar Oct 19 '18 21:10 david-salinas