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

[Issue]: [HIP] Report error about device/global function while device-side code has already been generated #215

Closed
aywala opened this issue Nov 27, 2024 · 1 comment

Comments

@aywala
Copy link

aywala commented Nov 27, 2024

Problem Description

#include <hip/hip_runtime.h>
#include <stdio.h>

#ifdef __HIP_DEVICE_COMPILE__
    #define HD __host__ __device__
#else
    #define HD
#endif

HD void foo(){
    printf("execute foo\n");
}

__global__ void kernel(){
    foo();
}

int main() {
    kernel<<<1,1>>>();
    hipDeviceSynchronize();
}
}

This code sample is error with hipcc. It report an error when compiling for host.
https://godbolt.org/z/dGG5zEhEc

hip_macro.cpp:19:5: error: no matching function for call to 'foo'
    foo();
    ^~~
hip_macro.cpp:10:9: note: candidate function not viable: call to __host__ function from __global__ function
HD void foo(){
#include <stdio.h>

#ifdef __CUDA_ARCH__
    #define HD __host__ __device__
#else
    #define HD
#endif

HD void foo() {
    printf("execute foo\n");
}

__global__  void kernel(){
    foo(); 
}

int main() {
    kernel<<<1,1>>>();
    cudaDeviceSynchronize();
}

This code sample is ok with nvcc.

Why does hipcc parse device function once again when compiling for host target? And send an error for device function but the device code has already been generated. That does not make sense.

Real world problem:
Some header files have something like

#ifdef __CUDA_ARCH__
#define HD __host__ __device__
#else
    #define HD
#endif

When these header files are included in cuda source file, hipcc can not handle correctly. I know __CUDACC__ will be ok, but __CUDA_ARCH__\ __HIP_DEVICE_COMPILE__ should be ok too. This is a problem caused by the design of compiler not caused by the language standard.

Operating System

Ubuntu22.04

CPU

R5 7500F

GPU

gfx906

ROCm Version

ROCm 6.1.0

ROCm Component

No response

Steps to Reproduce

No response

(Optional for Linux users) Output of /opt/rocm/bin/rocminfo --support

No response

Additional Information

No response

@aywala aywala changed the title [Issue]: [HIP] Report error about device function while device code has already been generated [Issue]: [HIP] Report error about device/global function while device-side code has already been generated Nov 27, 2024
@shiltian
Copy link

There is a reason __host__ exists, and that is exactly it. I don't think this is an issue. The code in the description doesn't conform with the programming model IMO.

@aywala aywala closed this as completed Nov 28, 2024
@aywala aywala closed this as not planned Won't fix, can't repro, duplicate, stale Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants