Skip to content

Calling Standard Library functions from __device__ code #547

@taketwo

Description

@taketwo

This is similar to #546.

After including the "gtx/io.hpp" header into NVCC-compiled code I got another handful of warnings. For example:

home/sergey/third-party/glm/src/glm/gtx/io.inl(99): warning: calling a __host__ function from a __host__ __device__ function is not allowed
          detected during:
            instantiation of "const FTy &glm::io::get_facet<FTy,CTy,CTr>(std::basic_ios<CTy, CTr> &) [with FTy=glm::io::format_punct<char>, CTy=char, CTr=std::char_traits<char>]"

The offending code fragment is:

template <typename FTy, typename CTy, typename CTr>
GLM_FUNC_QUALIFIER FTy const& get_facet(std::basic_ios<CTy, CTr>& ios)
{
    if(!std::has_facet<FTy>(ios.getloc()))
        ios.imbue(std::locale(ios.getloc(), new FTy));
    return std::use_facet<FTy>(ios.getloc());
}

Indeed, functions from the Standard Library are __host__ only. And anyway, I guess functions from the IO module are not supposed to be run on the GPU. Should we remove the GLM_FUNC_QUALIFIER from them?

EDIT Actually, the functions still need to be inlined, so rather replace GLM_FUNC_QUALIFIER with GLM_INLINE.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions