oneapi-src / oneapi-src/SYCLomatic

Migration of cudaGetErrorString incorrect when used in macro

Open
#1,950 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
LLVM
Stars
291
Forks
99
Avg merge
5d 5h
Merged PRs (30d)
1

Description

Describe the bug

The CUDA function "cudaGetErrorString", which converts a CUDA error code onto a user-readable error string, is incorrectly translated by syclomatic when used as parameter on a macro. Syclomatic translates the name of the function with a string, but the expectation is to keep the function name at that point so that it can be used in nested macros.

To reproduce

The code below:

#include <cstdio>
#include <cuda_runtime.h>

#define CHECK_CUDA_FUNCTION(errNo, errFunc) \
        errFunc(errNo)

#define CHECK_CUDA(errNo) \
        CHECK_CUDA_FUNCTION(errNo, cudaGetErrorString)


int main() {
        printf("%s \n", CHECK_CUDA(cudaSuccess));
};

is incorrectly converted to

#include <sycl/sycl.hpp>
#include <dpct/dpct.hpp>
#include <cstdio>

#define CHECK_CUDA_FUNCTION(errNo, errFunc) \
        errFunc(errNo)

#define CHECK_CUDA(errNo) CHECK_CUDA_FUNCTION(errNo, "<Placeholder string>")

int main() {
        /*
        DPCT1009:0: SYCL uses exceptions to report errors and does not use the
        error codes. The call was replaced by a placeholder string. You need to
        rewrite this code.
        */
        printf("%s \n", CHECK_CUDA(0));
};
Environment

No response

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided C++ macro example through syclomatic and compare the converted CHECK_CUDA macro with the expected behavior. Trace the translation path for cudaGetErrorString when it is passed as a macro argument. Done means the function name remains usable in the nested macro instead of being replaced by a placeholder string.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.