Skip to content

Quantstack's xwidget does not work in CUDA mode #10

@SimeonEhrig

Description

@SimeonEhrig

About

https://github.com/QuantStack/xwidgets

If you try to load a xwidget header, you get the following error:

$ cling -std=c++14 -xcuda

****************** CLING ******************
* Type C++ code and press enter to run it *
*             Type .q to exit             *
*******************************************
[cling]$ #include "xproperty/xobserved.hpp"
In file included from input_line_3:1:
/home/sehrig/projects/xeus-cling-cuda-container/builds/miniconda3/include/xproperty/xobserved.hpp:103:84: error: expected '(' for function-style cast or type construction
        std::unordered_map<std::size_t, std::vector<std::function<void(derived_type&)>>> m_observers;
                                                                       ~~~~~~~~~~~~^
/home/sehrig/projects/xeus-cling-cuda-container/builds/miniconda3/include/xproperty/xobserved.hpp:103:85: error: expected expression
        std::unordered_map<std::size_t, std::vector<std::function<void(derived_type&)>>> m_observers;
                                                                                    ^
/home/sehrig/projects/xeus-cling-cuda-container/builds/miniconda3/include/xproperty/xobserved.hpp:103:101: error: expected a type
        std::unordered_map<std::size_t, std::vector<std::function<void(derived_type&)>>> m_observers;
                                                                                                    ^
/home/sehrig/projects/xeus-cling-cuda-container/builds/miniconda3/include/xproperty/xobserved.hpp:103:101: error: expected a type
/home/sehrig/projects/xeus-cling-cuda-container/builds/miniconda3/include/xproperty/xobserved.hpp:143:25: error: use of undeclared identifier 'm_observers'
        auto position = m_observers.find(offset);
                        ^
/home/sehrig/projects/xeus-cling-cuda-container/builds/miniconda3/include/xproperty/xobserved.hpp:144:25: error: use of undeclared identifier 'm_observers'
        if (position == m_observers.end())
                        ^
/home/sehrig/projects/xeus-cling-cuda-container/builds/miniconda3/include/xproperty/xobserved.hpp:146:13: error: use of undeclared identifier 'm_observers'
            m_observers[offset] = {std::move(cb)};
            ^
/home/sehrig/projects/xeus-cling-cuda-container/builds/miniconda3/include/xproperty/xobserved.hpp:158:9: error: use of undeclared identifier 'm_observers'
        m_observers.erase(P::offset());
        ^
/home/sehrig/projects/xeus-cling-cuda-container/builds/miniconda3/include/xproperty/xobserved.hpp:195:25: error: use of undeclared identifier 'm_observers'
        auto position = m_observers.find(offset);
                        ^
/home/sehrig/projects/xeus-cling-cuda-container/builds/miniconda3/include/xproperty/xobserved.hpp:196:25: error: use of undeclared identifier 'm_observers'
        if (position != m_observers.end())
                        ^
IncrementalCUDADeviceCompiler::process()
failed at compile ptx code
In file included from input_line_3:1:
/home/sehrig/projects/xeus-cling-cuda-container/builds/miniconda3/include/xproperty/xobserved.hpp:103:84: error: expected '(' for function-style cast or type construction
        std::unordered_map<std::size_t, std::vector<std::function<void(derived_type&)>>> m_observers;
                                                                       ~~~~~~~~~~~~^
/home/sehrig/projects/xeus-cling-cuda-container/builds/miniconda3/include/xproperty/xobserved.hpp:103:85: error: expected expression
        std::unordered_map<std::size_t, std::vector<std::function<void(derived_type&)>>> m_observers;
                                                                                    ^
/home/sehrig/projects/xeus-cling-cuda-container/builds/miniconda3/include/xproperty/xobserved.hpp:103:101: error: expected a type
        std::unordered_map<std::size_t, std::vector<std::function<void(derived_type&)>>> m_observers;
                                                                                                    ^
/home/sehrig/projects/xeus-cling-cuda-container/builds/miniconda3/include/xproperty/xobserved.hpp:103:101: error: expected a type
/home/sehrig/projects/xeus-cling-cuda-container/builds/miniconda3/include/xproperty/xobserved.hpp:143:25: error: use of undeclared identifier 'm_observers'
        auto position = m_observers.find(offset);
                        ^
/home/sehrig/projects/xeus-cling-cuda-container/builds/miniconda3/include/xproperty/xobserved.hpp:144:25: error: use of undeclared identifier 'm_observers'
        if (position == m_observers.end())
                        ^
/home/sehrig/projects/xeus-cling-cuda-container/builds/miniconda3/include/xproperty/xobserved.hpp:146:13: error: use of undeclared identifier 'm_observers'
            m_observers[offset] = {std::move(cb)};
            ^
/home/sehrig/projects/xeus-cling-cuda-container/builds/miniconda3/include/xproperty/xobserved.hpp:158:9: error: use of undeclared identifier 'm_observers'
        m_observers.erase(P::offset());
        ^
/home/sehrig/projects/xeus-cling-cuda-container/builds/miniconda3/include/xproperty/xobserved.hpp:195:25: error: use of undeclared identifier 'm_observers'
        auto position = m_observers.find(offset);
                        ^
/home/sehrig/projects/xeus-cling-cuda-container/builds/miniconda3/include/xproperty/xobserved.hpp:196:25: error: use of undeclared identifier 'm_observers'
        if (position != m_observers.end())
                        ^

Source of error

The parser of the device interpreter causes the problem:

lib/Interpreter/IncrementalParser.cpp::ParseInternal()

  Parser::DeclGroupPtrTy ADecl;
  while (!m_Parser->ParseTopLevelDecl(ADecl)) {
    // If we got a null return and something *was* parsed, ignore it.  This
    // is due to a top-level semicolon, an action override, or a parse error
    // skipping something.
    if (Trap.hasErrorOccurred())
      m_Consumer->getTransaction()->setIssuedDiags(Transaction::kErrors);
    if (ADecl)
      m_Consumer->HandleTopLevelDecl(ADecl.get());
  };
  // If never entered the while block, there's a chance an error occured
  if (Trap.hasErrorOccurred())
    m_Consumer->getTransaction()->setIssuedDiags(Transaction::kErrors);

The error is caused by the clang library.

Testcode for static compilation

#include <iostream>
#include <xwidgets/xslider.hpp>

// just to cause an error, if the cuda mode is not enable
__global__ void g(int *out){
  *out = 42;
}

int main(){
  std::cout << "I'm Clang " << __clang_major__ << std::endl;
  xw::slider<double> slider;
  return 0;
}

Build command

clang++ -std=c++14 xwidgets_compiler_test.cu -o xw_clang -xcuda -lxwidgets -L/usr/local/cuda/lib64 -lcudart_static -ldl -lrt -pthread

Solution

Clang 9 solves the problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions