Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Documentation]: examples in "Reference" contain multiple syntax errors #3428

Open
samuelpmish opened this issue Mar 6, 2024 · 1 comment
Assignees

Comments

@samuelpmish
Copy link

Description of errors

I'm a long-time CUDA developer trying to learn more about HIP and ROCm, but the documentation is making that difficult.

The most fundamental construct in CUDA is the kernel, so I started by reading https://rocm.docs.amd.com/projects/HIP/en/latest/reference/kernel_language.html

which contains a few example snippets illustrating how to write kernels for HIP. The first is:

// Example pseudo code introducing hipLaunchKernelGGL:
__global__ MyKernel(hipLaunchParm lp, float *A, float *B, float *C, size_t N)
{
...
}

MyKernel<<<dim3(gridDim), dim3(groupDim), 0, 0>>> (a,b,c,n);
// Alternatively, kernel can be launched by
// hipLaunchKernelGGL(MyKernel, dim3(gridDim), dim3(groupDim), 0/*dynamicShared*/, 0/*stream), a, b, c, n);

Maybe I'm missing something, but this code doesn't seem to work at all.

It has a handful of problems:


The next snippet on the page:

// Example showing device function, __device__ __host__
// <- compile for both device and host
float PlusOne(float x)
{
    return x + 1.0;
}

__global__
void
MyKernel (hipLaunchParm lp, /*lp parm for execution configuration */
          const float *a, const float *b, float *c, unsigned N)
{
    unsigned gid = threadIdx.x; // <- coordinate index function
    if (gid < N) {
        c[gid] = a[gid] + PlusOne(b[gid]);
    }
}
void callMyKernel()
{
    float *a, *b, *c; // initialization not shown...
    unsigned N = 1000000;
    const unsigned blockSize = 256;

    MyKernel<<<dim3(gridDim), dim3(groupDim), 0, 0>>> (a,b,c,n);
    // Alternatively, kernel can be launched by
    // hipLaunchKernelGGL(MyKernel, dim3(N/blockSize), dim3(blockSize), 0, 0,  a,b,c,N);
}

also has a lot of errors

  • it's also not syntax highlighted
  • the PlusOne function is missing the __host__ __device__ annotations
  • gridDim, groupDim not defined
  • wrong variable names (N vs n)
  • too few arguments in the kernel launch examples

Attach any links, screenshots, or additional evidence you think will be helpful.

No response

@ppanchad-amd
Copy link

@samuelpmish Internal ticket has been created to fix the documentation. Thanks!

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

No branches or pull requests

3 participants