Skip to content

[Offload] Kernel launch fails with "too many resources" when parameter type is changed from size_t to int #143323

@leandrolcampos

Description

@leandrolcampos
Contributor

I observed something weird. When I try to launch the following kernel

#include <gpuintrin.h>
#include <math.h>
#include <stdlib.h>

extern "C" __gpu_kernel void applyLogf(const float *In, float *Out,
                                       size_t NumElements) {
  int Index = __gpu_num_threads(__GPU_X_DIM) * __gpu_block_id(__GPU_X_DIM) +
              __gpu_thread_id(__GPU_X_DIM);

  if (Index < NumElements) {
    Out[Index] = logf(In[Index]);
  }
}

with these arguments

    // ...
    struct {
      void *InBuffer;
      void *OutBuffer;
      size_t NumElements;
    } Args{InBuffer, OutBuffer, NumElements};

    OL_CHECK(olLaunchKernel(nullptr, GPUDevice.Handle, Kernel, &Args,
                            sizeof(Args), &LaunchArgs, nullptr));
    // ...

everything works fine. But if I try to change the type of NumElements to int, here

#include <gpuintrin.h>
#include <math.h>

extern "C" __gpu_kernel void applyLogf(const float *In, float *Out,
                                       int NumElements) {
  int Index = __gpu_num_threads(__GPU_X_DIM) * __gpu_block_id(__GPU_X_DIM) +
              __gpu_thread_id(__GPU_X_DIM);

  if (Index < NumElements) {
    Out[Index] = logf(In[Index]);
  }
}

and here

    // ...
    struct {
      void *InBuffer;
      void *OutBuffer;
      int NumElements;
    } Args{InBuffer, OutBuffer, static_cast<int>(NumElements)};

    OL_CHECK(olLaunchKernel(nullptr, GPUDevice.Handle, Kernel, &Args,
                            sizeof(Args), &LaunchArgs, nullptr));
    // ...

I get the following error:

OL_CHECK FAILED: (olLaunchKernel(nullptr, GPUDevice.Handle, Kernel, &Args, sizeof(Args), &LaunchArgs, nullptr)) != OL_SUCCESS
  Error Code: 1
  Details: error in cuLaunchKernel for 'applyLogf': too many resources requested for launch
  Location: /home/leandro/offload-samples/samples/math_test/Tester.hpp:151
  Function: check

Environment:

  • LLVM version: Custom build from git
    • LLVM Project Commit Hash: 1e4841881ef89aeee77cbf081de42af376bfa3fb
  • Operating System: Ubuntu 24.04.2 LTS (WSL2)

Activity

llvmbot

llvmbot commented on Jun 8, 2025

@llvmbot
Member

@llvm/issue-subscribers-offload

Author: Leandro Lacerda (leandrolcampos)

I observed something weird. When I try to launch the following kernel
#include &lt;gpuintrin.h&gt;
#include &lt;math.h&gt;
#include &lt;stdlib.h&gt;

extern "C" __gpu_kernel void applyLogf(const float *In, float *Out,
                                       size_t NumElements) {
  int Index = __gpu_num_threads(__GPU_X_DIM) * __gpu_block_id(__GPU_X_DIM) +
              __gpu_thread_id(__GPU_X_DIM);

  if (Index &lt; NumElements) {
    Out[Index] = logf(In[Index]);
  }
}

with these arguments

    // ...
    struct {
      void *InBuffer;
      void *OutBuffer;
      size_t NumElements;
    } Args{InBuffer, OutBuffer, NumElements};

    OL_CHECK(olLaunchKernel(nullptr, GPUDevice.Handle, Kernel, &amp;Args,
                            sizeof(Args), &amp;LaunchArgs, nullptr));
    // ...

everything works fine. But if I try to change the type of NumElements to int, here

#include &lt;gpuintrin.h&gt;
#include &lt;math.h&gt;

extern "C" __gpu_kernel void applyLogf(const float *In, float *Out,
                                       int NumElements) {
  int Index = __gpu_num_threads(__GPU_X_DIM) * __gpu_block_id(__GPU_X_DIM) +
              __gpu_thread_id(__GPU_X_DIM);

  if (Index &lt; NumElements) {
    Out[Index] = logf(In[Index]);
  }
}

and here

    // ...
    struct {
      void *InBuffer;
      void *OutBuffer;
      int NumElements;
    } Args{InBuffer, OutBuffer, static_cast&lt;int&gt;(NumElements)};

    OL_CHECK(olLaunchKernel(nullptr, GPUDevice.Handle, Kernel, &amp;Args,
                            sizeof(Args), &amp;LaunchArgs, nullptr));
    // ...

I get the following error:

OL_CHECK FAILED: (olLaunchKernel(nullptr, GPUDevice.Handle, Kernel, &amp;Args, sizeof(Args), &amp;LaunchArgs, nullptr)) != OL_SUCCESS
  Error Code: 1
  Details: error in cuLaunchKernel for 'applyLogf': too many resources requested for launch
  Location: /home/leandro/offload-samples/samples/math_test/Tester.hpp:151
  Function: check

Environment:

  • LLVM version: Custom build from git
    • LLVM Project Commit Hash: 1e4841881ef89aeee77cbf081de42af376bfa3fb
  • Operating System: Ubuntu 24.04.2 LTS (WSL2)
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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @EugeneZelenko@leandrolcampos@llvmbot

        Issue actions

          [Offload] Kernel launch fails with "too many resources" when parameter type is changed from `size_t` to `int` · Issue #143323 · llvm/llvm-project