Skip to content

Issue Report: Launch Constructor Ambiguity and Compilation Problems #71

Description

@AnamicX

Problem Description

When using the MUDA library, ambiguity issues were found in the Launch constructor, along with related compilation and static assertion problems.

Test Code:

void case1() {
  muda::DeviceBuffer<float> buffer(17);
  muda::Launch(16)
      .apply(buffer.size(), [buf = buffer.viewer()] __device__(
                                int idx) mutable { buf(idx) = idx; })
      .wait();
  std::vector<float> out;
  buffer.copy_to(out);
  printVector(out);
}

void case2() {
  muda::DeviceBuffer<float> buffer(17);
  muda::Launch(dim3(16))
      .apply(dim3(buffer.size()), [buf = buffer.viewer()] __device__(
                                      int idx) mutable { buf(idx) = idx; })
      .wait();
  std::vector<float> out;
  buffer.copy_to(out);
  printVector(out);
}

Observed Behavior:

  • case1() throws error: m_grid_dim.x == 0 failed. grid_dim should be \dim3{0}
  • case2() outputs all zeros, neither executing normally nor throwing an error

Problem Details

  1. Launch Constructor Ambiguity

muda::Launch(16) matches the third constructor:

MUDA_HOST Launch(dim3 blockDim, size_t sharedMemSize = 0, cudaStream_t stream = nullptr) MUDA_NOEXCEPT
    : LaunchBase(stream),
      m_grid_dim(0),  // grid_dim is set to 0
      m_block_dim(blockDim),
      m_shared_mem_size(sharedMemSize)
{
}

The check for m_grid_dim in the apply function fails because a valid grid dimension is expected

  1. Static Assertion Problem

In generic_kernel_with_range, when detecting callable objects that accept int or unsigned int parameters, a static assertion should trigger to recommend using ParallelFor(), but the current implementation has issues:

else if constexpr(std::is_invocable_v<F, int>
                  || std::is_invocable_v<F, unsigned int>)
{
    static_assert("You should use `ParallelFor()` instead of `Launch()` for better semantics");
}
  1. C++20 Syntax Compilation Problem with xmake
    Error Message:
muda\src\muda\buffer\details/buffer_3d_view.inl(115): error: expected an expression
      return cudaPitchedPtr{.ptr   = remove_const(m_data),
                            ^

Cause: The code uses C++20 designated initialization syntax, but the project is configured for C++17 in xmake.lua.

Environment Information:

Compiler: CUDA 13
Version: 2025.10.9

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions