Better error when calling recursive function on device

Aperta
#1,886 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
cpp
Ambito
compilers

Direzione di ricerca

Riproduci l’esempio ricorsivo di heapify con l’OpenMP JIT target e ispeziona i frame di LLVMToHostTranslator e SubCfgFormationPass mostrati nel backtrace. Conferma che il codice device ricorsivo produca una diagnostica invece di un segmentation fault; aggiungi o esegui un test di regressione mirato se viene identificata la posizione di test pertinente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement

Describe the motivation for the feature request
SYCL does not allow recursive functions. Could this be reported during the JIT compilation? In the case of the openMP device with the JIT compiler, I only got a segfault. See context for example.

Describe the solution you'd like
It would be great to have something more verbose here. In the best case, this should fail during (JIT) compilation with a clear error message.

Additional context

I had some recursive heapify implementation

template <typename T, std::size_t N>
void heapify_max(std::array<T, N>& arr, std::size_t i, std::size_t heap_size) {
    std::size_t largest = i;
    std::size_t left = 2 * i + 1;
    std::size_t right = 2 * i + 2;

    if (left < heap_size && arr[left] > arr[largest]) {
        largest = left;
    }
    if (right < heap_size && arr[right] > arr[largest]) {
        largest = right;
    }
    if (largest != i) {
        sycl_swap(arr[i], arr[largest]);
        heapify_max(arr, largest, heap_size);
    }
}

called within some heap instance I initialize within the kernel. This compiles/works just fine with the omp.accelerated target. With the JIT, I get:

Writing '/tmp/cfg_Z18__acpp_sscp_kernelIN7hipsycl4glue15__sscp_dispatch18basic_parallel_forIZZ27global_queue_selector_logicPN4YAML4NodeEENK3$_0clERNS0_4sy-8ab2c2.dot'... [workstation-cbyrohl:1310718:0:1310776] Caught signal 11 (Segmentation fault: address not mapped to object at address 0x28)
==== backtrace (tid:1310776) ====
 0  /lib/x86_64-linux-gnu/libucs.so.0(ucs_handle_error+0x2bc) [0x7f2440cf564c]
 1  /lib/x86_64-linux-gnu/libucs.so.0(+0x3182f) [0x7f2440cf582f]
 2  /lib/x86_64-linux-gnu/libucs.so.0(+0x319fa) [0x7f2440cf59fa]
 3  /lib/x86_64-linux-gnu/libc.so.6(+0x3fdf0) [0x7f2441249df0]
 4  /usr/lib/llvm-19/lib/libLLVM.so.19.1(_ZNK4llvm21BranchProbabilityInfo18getEdgeProbabilityEPKNS_10BasicBlockES3_+0x26) [0x7f2430d832c6]
 5  /usr/lib/llvm-19/lib/libLLVM.so.19.1(+0x238dc3e) [0x7f2430d8dc3e]
 6  /usr/lib/llvm-19/lib/libLLVM.so.19.1(+0x238d3b1) [0x7f2430d8d3b1]
 7  /usr/lib/llvm-19/lib/libLLVM.so.19.1(+0x238c98b) [0x7f2430d8c98b]
 8  /usr/lib/llvm-19/lib/libLLVM.so.19.1(+0x238bce5) [0x7f2430d8bce5]
 9  /usr/lib/llvm-19/lib/libLLVM.so.19.1(_ZN4llvm10WriteGraphIPNS_11DOTFuncInfoEEERNS_11raw_ostreamES4_RKT_bRKNS_5TwineE+0x7a) [0x7f2430d8bc1a]
10  /usr/lib/llvm-19/lib/libLLVM.so.19.1(_ZN4llvm10WriteGraphIPNS_11DOTFuncInfoEEENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKT_RKNS_5TwineEbSE_S8_+0x3da) [0x7f2430d8ef7a]
11  /usr/lib/llvm-19/lib/libLLVM.so.19.1(_ZN4llvm9ViewGraphIPNS_11DOTFuncInfoEEEvRKT_RKNS_5TwineEbS8_NS_12GraphProgram4NameE+0x4b) [0x7f2430d8b3fb]
12  /usr/lib/llvm-19/lib/libLLVM.so.19.1(_ZNK4llvm8Function7viewCFGEbPKNS_18BlockFrequencyInfoEPKNS_21BranchProbabilityInfoE+0xf8) [0x7f2430d8b388]
13  /home/cbyrohl/bin/../lib/hipSYCL/llvm-to-backend/libllvm-to-host.so(+0x56200) [0x7f243ebce200]
14  /home/cbyrohl/bin/../lib/hipSYCL/llvm-to-backend/libllvm-to-host.so(_ZN7hipsycl8compiler19SubCfgFormationPass3runERN4llvm8FunctionERNS2_15AnalysisManagerIS3_JEEE+0x239) [0x7f243ebd67c9]
15  /home/cbyrohl/bin/../lib/hipSYCL/llvm-to-backend/libllvm-to-host.so(_ZN4llvm6detail9PassModelINS_8FunctionEN7hipsycl8compiler19SubCfgFormationPassENS_15AnalysisManagerIS2_JEEEJEE3runERS2_RS7_+0xd) [0x7f243ebc1b1d]
16  /usr/lib/llvm-19/lib/libLLVM.so.19.1(_ZN4llvm11PassManagerINS_8FunctionENS_15AnalysisManagerIS1_JEEEJEE3runERS1_RS3_+0x169) [0x7f242fa3d989]
17  /home/cbyrohl/bin/../lib/hipSYCL/llvm-to-backend/libllvm-to-host.so(_ZN4llvm6detail9PassModelINS_8FunctionENS_11PassManagerIS2_NS_15AnalysisManagerIS2_JEEEJEEES5_JEE3runERS2_RS5_+0xd) [0x7f243eb9f0fd]
18  /usr/lib/llvm-19/lib/libLLVM.so.19.1(_ZN4llvm27ModuleToFunctionPassAdaptor3runERNS_6ModuleERNS_15AnalysisManagerIS1_JEEE+0x134) [0x7f242fa41614]
19  /home/cbyrohl/bin/../lib/hipSYCL/llvm-to-backend/libllvm-to-host.so(_ZN4llvm6detail9PassModelINS_6ModuleENS_27ModuleToFunctionPassAdaptorENS_15AnalysisManagerIS2_JEEEJEE3runERS2_RS5_+0xd) [0x7f243eb9f12d]
20  /usr/lib/llvm-19/lib/libLLVM.so.19.1(_ZN4llvm11PassManagerINS_6ModuleENS_15AnalysisManagerIS1_JEEEJEE3runERS1_RS3_+0x1e9) [0x7f242fa3c769]
21  /home/cbyrohl/bin/../lib/hipSYCL/llvm-to-backend/libllvm-to-host.so(_ZN7hipsycl8compiler20LLVMToHostTranslator15toBackendFlavorERN4llvm6ModuleERNS0_11PassHandlerE+0xc20) [0x7f243eb9aea0]
22  /home/cbyrohl/bin/../lib/hipSYCL/llvm-to-backend/libllvm-to-backend.so(+0x1a86b) [0x7f243fdb986b]
23  /home/cbyrohl/bin/../lib/hipSYCL/llvm-to-backend/libllvm-to-backend.so(_ZN7hipsycl8compiler23LLVMToBackendTranslator9prepareIRERN4llvm6ModuleE+0xa8) [0x7f243fdbafd8]
24  /home/cbyrohl/bin/../lib/hipSYCL/llvm-to-backend/libllvm-to-backend.so(_ZN7hipsycl8compiler23LLVMToBackendTranslator18fullTransformationERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS7_+0x29b) [0x7f243fdbb75b]
25  /home/cbyrohl/bin/../lib/hipSYCL/librt-backend-omp.so(+0x156ed) [0x7f243fcb46ed]
26  /home/cbyrohl/bin/../lib/hipSYCL/librt-backend-omp.so(_ZN7hipsycl2rt9omp_queue35submit_sscp_kernel_from_code_objectEmSt17basic_string_viewIcSt11char_traitsIcEEPKNS0_15hcf_kernel_infoERKNS0_12static_arrayILi3EEESC_jPPvPmmRKNS0_20kernel_configurationE+0x3098) [0x7f243fcb9868]
27  /home/cbyrohl/bin/../lib/hipSYCL/librt-backend-omp.so(_ZN7hipsycl2rt28omp_sscp_code_object_invoker13submit_kernelERKNS0_16kernel_operationEmRKNS0_12static_arrayILi3EEES8_jPPvPmmSt17basic_string_viewIcSt11char_traitsIcEEPKNS0_15hcf_kernel_infoERKNS0_20kernel_configurationE+0x40) [0x7f243fcae1c0]
28  /home/cbyrohl/repos/thor/cmake-build-debug-acpp/src/thor(+0xd7684) [0x56263cee0684]
29  /home/cbyrohl/bin/../lib/hipSYCL/librt-backend-omp.so(+0x14e3e) [0x7f243fcb3e3e]
30  /home/cbyrohl/bin/../lib/hipSYCL/librt-backend-omp.so(+0x1e174) [0x7f243fcbd174]
31  /home/cbyrohl/bin/../lib/libacpp-rt.so(_ZN7hipsycl2rt13worker_thread4workEv+0x1bb) [0x7f2442b32e8b]
32  /lib/x86_64-linux-gnu/libstdc++.so.6(+0xe1224) [0x7f24414e1224]
33  /lib/x86_64-linux-gnu/libc.so.6(+0x92b7b) [0x7f244129cb7b]
34  /lib/x86_64-linux-gnu/libc.so.6(+0x1107b8) [0x7f244131a7b8]
=================================

Process finished with exit code 139 (interrupted by signal 11:SIGSEGV)

Replacing with a non-recursive version fixes the issue:

template <typename T, std::size_t N>
void heapify_max(std::array<T, N>& arr, std::size_t i, std::size_t heap_size) {
    while (true) {
        std::size_t largest = i;
        std::size_t left = 2 * i + 1;
        std::size_t right = 2 * i + 2;

        if (left < heap_size && arr[left] > arr[largest])
            largest = left;
        if (right < heap_size && arr[right] > arr[largest])
            largest = right;

        if (largest != i) {
            sycl_swap(arr[i], arr[largest]);
            i = largest;
        } else {
            break;
        }
    }

}

Lingua principale
C++
Stelle
2k
Fork
236
Merge medio
5g 12h
PR unite (30g)
9

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di AdaptiveCpp/AdaptiveCpp

Tutte le issue di AdaptiveCpp/AdaptiveCpp

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.