Code Monkey home page Code Monkey logo

Comments (2)

bdice avatar bdice commented on June 12, 2024

I think this is a minimal reproducer: https://godbolt.org/z/oaMhrcoPv

#include <cuda/functional>

int main()
{
    auto f = cuda::proclaim_return_type<bool>([] __device__() { return false; });
    auto g = cuda::proclaim_return_type<bool>([f] __device__() { return f(); });
    return 0;
}
/opt/compiler-explorer/libs/libcudacxx/trunk/include/cuda/std/detail/libcxx/include/__functional/invoke.h(402): error: calling a __device__ function("main::[lambda() (instance 1)]::operator ()() const") from a __host__ __device__ function("__invoke") is not allowed
      { return static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...); }
               ^
          detected during:
            instantiation of "decltype((<expression>)) cuda::std::__4::__invoke(_Fp &&, _Args &&...) [with _Fp=const lambda []()->bool &, _Args=<>]" at line 126 of /opt/compiler-explorer/libs/libcudacxx/trunk/include/cuda/functional
            instantiation of "_Ret cuda::__4::__detail::__return_type_wrapper<_Ret, _DecayFn>::operator()(_As &&...) const & noexcept [with _Ret=bool, _DecayFn=lambda []()->bool, _As=<>]" at line 6 of <source>

/opt/compiler-explorer/libs/libcudacxx/trunk/include/cuda/std/detail/libcxx/include/__functional/invoke.h(402): error: calling a __device__ function("main::[lambda() (instance 1)]::operator ()() const") from a __host__ __device__ function("__invoke") is not allowed
      { return static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...); }
                                      ^
          detected during:
            instantiation of "decltype((<expression>)) cuda::std::__4::__invoke(_Fp &&, _Args &&...) [with _Fp=const lambda []()->bool &, _Args=<>]" at line 126 of /opt/compiler-explorer/libs/libcudacxx/trunk/include/cuda/functional
            instantiation of "_Ret cuda::__4::__detail::__return_type_wrapper<_Ret, _DecayFn>::operator()(_As &&...) const & noexcept [with _Ret=bool, _DecayFn=lambda []()->bool, _As=<>]" at line 6 of <source>

2 errors detected in the compilation of "<source>".
ASM generation compiler returned: 2
/opt/compiler-explorer/libs/libcudacxx/trunk/include/cuda/std/detail/libcxx/include/__functional/invoke.h(402): error: calling a __device__ function("main::[lambda() (instance 1)]::operator ()() const") from a __host__ __device__ function("__invoke") is not allowed
      { return static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...); }
               ^
          detected during:
            instantiation of "decltype((<expression>)) cuda::std::__4::__invoke(_Fp &&, _Args &&...) [with _Fp=const lambda []()->bool &, _Args=<>]" at line 126 of /opt/compiler-explorer/libs/libcudacxx/trunk/include/cuda/functional
            instantiation of "_Ret cuda::__4::__detail::__return_type_wrapper<_Ret, _DecayFn>::operator()(_As &&...) const & noexcept [with _Ret=bool, _DecayFn=lambda []()->bool, _As=<>]" at line 6 of <source>

/opt/compiler-explorer/libs/libcudacxx/trunk/include/cuda/std/detail/libcxx/include/__functional/invoke.h(402): error: calling a __device__ function("main::[lambda() (instance 1)]::operator ()() const") from a __host__ __device__ function("__invoke") is not allowed
      { return static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...); }
                                      ^
          detected during:
            instantiation of "decltype((<expression>)) cuda::std::__4::__invoke(_Fp &&, _Args &&...) [with _Fp=const lambda []()->bool &, _Args=<>]" at line 126 of /opt/compiler-explorer/libs/libcudacxx/trunk/include/cuda/functional
            instantiation of "_Ret cuda::__4::__detail::__return_type_wrapper<_Ret, _DecayFn>::operator()(_As &&...) const & noexcept [with _Ret=bool, _DecayFn=lambda []()->bool, _As=<>]" at line 6 of <source>

2 errors detected in the compilation of "<source>".
Execution build compiler returned: 2

from libcudacxx.

bdice avatar bdice commented on June 12, 2024

I'm using f in a context where it is both called by g and used as a predicate function for a thrust call by itself. The f lambda needs to have a "return type proclamation" so it can be used by thrust, but that prevents it from being captured and used in the g lambda.

If I remove the cuda::proclaim_return_type from around f and wrap it separately, the program compiles: https://godbolt.org/z/oonnWqhxq

#include <cuda/functional>

int main()
{
    auto f = [] __device__() { return false; };
    auto f_ret = cuda::proclaim_return_type<bool>(f);
    auto g = cuda::proclaim_return_type<bool>([f] __device__() { return f(); });
    return 0;
}

from libcudacxx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.