Issue 55501
Summary clang -cl-std=clc++2021 --target spirv64 *.cpp failed
Labels new issue
Assignees
Reporter jonasbhjulstad
    Note: I'm fairly new to OpenCL-kernel programming, especially with clc++2021. 
It might be issues with the kernel code, allthough it compiles fine on Compiler-Explorer:
https://godbolt.org/z/xn4eM58nn

I'm trying to compile the following kernel file:
```
void addVec(float* a, const float*b, const int Nx)
{
    for (int i = 0; i < Nx; i++)
    {
        a[i] += b[i];
    }
}

template <int Nstage_ERK, class f_ODE>
struct impl_ERK {

    constexpr static int NX = f_ODE::NX;
    impl_ERK(const float* _A, const float* _b, const float* _c): p_A(_A), p_b(_b), p_c(_c){}
    void solve(constant float* xk, float* xk_1, float t, float dt, const float* P) 
    {
        float K[Nstage_ERK * NX];
        float xk_stage[NX];
        for (int j = 0; j < NX; j++)
        {
            xk_stage[j] = xk[j];
        }
        f_ODE::solve(t, xk_stage, K, P);

        for (int i = 1; i < Nstage_ERK; i++) {
            float* k_i = &K[i * NX];
            float c_i = p_c[i];

            float ak_sum[NX];
            for (int j = 0; j < NX; j++) {
                ak_sum[j] = xk[j];
            }
            for (int j = 0; j < i; j++) {
                ak_sum[j] += p_A[i * Nstage_ERK + j] * K[j * NX];
                xk_stage[j] = xk[j] + dt*ak_sum[j];
            }
            

            f_ODE::solve(t + c_i * dt, xk_stage, k_i,  P);

            for (int j = 0; j < NX; j++) {
                xk_1[j] += dt * p_b[i] * k_i[j];
            }
        }
    }
    private:
    const float* p_A; 
    const float* p_b;
    const float* p_c;
};


template <class f_ODE>
struct ERK4 : public impl_ERK<4,f_ODE> 
{
    ERK4(const float* _A, const float* _b, const float* _c) : impl_ERK<4,f_ODE>(_A, _b, _c){}
};


struct f_ODE_1
{
    constexpr static int NX = 3;
    constexpr static int NP = 3;
    static void solve(const float t, const float* xk, float* xdot, const float* P)
    {
        float alpha = P[0];
        float beta = P[1];
        float N_pop = P[2];

        xdot[0] = -beta*xk[0]*xk[1]/N_pop;
        xdot[1] = beta*xk[0]*xk[1]/N_pop - alpha*xk[1];
        xdot[2] = alpha*xk[1];
    }
};

// Example that uses find_min in a kernel with array of int4.
__kernel void compute(constant float* x0, global float* x1) 
{
    const float A[4*4] = {.0f,.0f,.0f,.0f,
    .5f,.0f,.0f,.0f,
    .0f,.5f,.0f,.0f,
    .0f,.0f,1.f,.0f};
    const float b[4] = {1.f/6, 1.f/3, 1.f/3, 1.f/6};
    const float c[4] = {.0f,.5f,.5f,1.f};
    const float dt = .5f;
    const float t = .0f;
    const float R0 = 1.2;
    const float alpha = .9;
    const float beta = R0*alpha;
    const float N_pop = 1e6;
    const float P[f_ODE_1::NP] = {alpha, beta, N_pop};
    float res[3];
    ERK4<f_ODE_1> integrator(A, b, c);
    integrator.solve(x0, res, t, dt, P);
}

```
with the following command:
```
clang -cl-std=clc++2021 --target spirv64 ERK.cpp 
```

output:
```
llvm-spirv: /usr/local/include/llvm/IR/Type.h:384: llvm::Type* llvm::Type::getNonOpaquePointerElementType() const: Assertion `NumContainedTys && "Attempting to get element type of opaque pointer"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /usr/local/bin/llvm-spirv /tmp/ERK-355e4b.bc -o /tmp/ERK-ad4368.o
1.      Running pass 'Adapt OCL types for SPIR-V' on module '/tmp/ERK-355e4b.bc'.
 #0 0x0000563161da86c5 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x0000563161da6324 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007fa4841eb420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007fa483c5600b raise /build/glibc-SzIz7B/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #4 0x00007fa483c35859 abort /build/glibc-SzIz7B/glibc-2.31/stdlib/abort.c:81:7
 #5 0x00007fa483c35729 get_sysdep_segment_value /build/glibc-SzIz7B/glibc-2.31/intl/loadmsgcat.c:509:8
 #6 0x00007fa483c35729 _nl_load_domain /build/glibc-SzIz7B/glibc-2.31/intl/loadmsgcat.c:970:34
 #7 0x00007fa483c46fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x000056316171bf10 llvm::Type::getNonOpaquePointerElementType() const (/usr/local/bin/llvm-spirv+0x135f10)
 #9 0x00005631617db900 llvm::Type::getPointerElementType() const (/usr/local/bin/llvm-spirv+0x1f5900)
#10 0x00005631618126c8 SPIRV::isPointerToOpaqueStructType(llvm::Type*) (/usr/local/bin/llvm-spirv+0x22c6c8)
#11 0x00005631619ced33 SPIRV::OCLTypeToSPIRVBase::adaptArgumentsByMetadata(llvm::Function*) (/usr/local/bin/llvm-spirv+0x3e8d33)
#12 0x00005631619cdac5 SPIRV::OCLTypeToSPIRVBase::runOCLTypeToSPIRV(llvm::Module&) (/usr/local/bin/llvm-spirv+0x3e7ac5)
#13 0x00005631619cd86d SPIRV::OCLTypeToSPIRVLegacy::runOnModule(llvm::Module&) (/usr/local/bin/llvm-spirv+0x3e786d)
#14 0x0000563161cc7b74 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/local/bin/llvm-spirv+0x6e1b74)
#15 0x0000563161860631 llvm::writeSpirv(llvm::Module*, SPIRV::TranslatorOpts const&, std::ostream&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&) (/usr/local/bin/llvm-spirv+0x27a631)
#16 0x00005631616fac0b convertLLVMToSPIRV(SPIRV::TranslatorOpts const&) llvm-spirv.cpp:0:0
#17 0x00005631616fe91b main (/usr/local/bin/llvm-spirv+0x11891b)
#18 0x00007fa483c37083 __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:342:3
#19 0x00005631616f77de _start (/usr/local/bin/llvm-spirv+0x1117de)
clang-15: error: unable to execute command: Aborted (core dumped)
clang-15: error: llvm-spirv command failed due to signal (use -v to see invocation)
clang version 15.0.0 (https://github.com/llvm/llvm-project.git f6366ef7f4f3cf1182fd70e0c50a9fa54374b612)
Target: spirv64
Thread model: posix
InstalledDir: /usr/local/bin
clang-15: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-15: note: diagnostic msg: /tmp/ERK-53bdca.cpp
clang-15: note: diagnostic msg: /tmp/ERK-53bdca.sh
clang-15: note: diagnostic msg: 

********************
```
[ERK-53bdca.sh.txt](https://github.com/llvm/llvm-project/files/8699431/ERK-53bdca.sh.txt)
[ERK-53bdca.cpp.txt](https://github.com/llvm/llvm-project/files/8699432/ERK-53bdca.cpp.txt)


_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to