muda icon indicating copy to clipboard operation
muda copied to clipboard

Question from intellisense

Open Da1sypetals opened this issue 6 months ago • 5 comments

These days I tried to setup project using muda in clion using the toolchain in docker. However, Clion intellisense refuse to work. I found that this is because static code analysis in conditional compilation (if constexpr) choose the last branch:

// namespace muda::details
template <typename F, typename UserTag>
    MUDA_GLOBAL void parallel_for_kernel(ParallelForCallable<F> f)
    {
        if constexpr(std::is_invocable_v<F, int>)
        {
            auto tid = blockIdx.x * blockDim.x + threadIdx.x;
            auto i   = tid;
            if(i < f.count)
            {
                f.callable(i);
            }
        }
        else if constexpr(std::is_invocable_v<F, ParallelForDetails>)
        {
            ParallelForDetails details{ParallelForType::DynamicBlocks,
                                       static_cast<int>(blockIdx.x * blockDim.x
                                                        + threadIdx.x),
                                       f.count};
            if(details.i() < details.total_num())
            {
                f.callable(details);
            }
        }
        else
        {
            static_assert(always_false_v<F>, "f must be void (int) or void (ParallelForDetails)");
        }
    }

which results in a failure assertion and thus an error. But the code compiles just fine with the same toolchain setup in Clion.

In theory, the functions implemented in type_traits are host functions, which are not supported to be called in device function. I also search the documentation page related to type traits (https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#extended-lambda-type-traits) and did not find this behavior documented.

My questions:

  1. Is this behavior documented elsewhere?
  2. Is this most probably a problem of CLion itself? I also wonder what editor/IDE you to develop with Muda. (Clion just gives hundreds of errors even if my code compiles, and I am pretty sure my toolchain is correct since I can compile and debug&run with Clion GUI)

Thanks a lot in advance.

Da1sypetals avatar Aug 02 '24 15:08 Da1sypetals