zhouronghua wrote:

> > Ignore whether -fdepfile-entry works or not. Even if it does, there are the 
> > following issues:
> 
> I don't understand how any of these points are related. This seems to be a 
> preexisting pattern, so can you explain why it doesn't work here?
> 
> https://github.com/llvm/llvm-project/blob/c35a726ca9795928e419044e6349edf6b73b6cd0/clang/lib/Driver/ToolChains/Darwin.cpp#L3399

give one example:
cat example.cu
// example.cu
#include <stdio.h>

// 假设我们有两个自定义头文件,针对不同的架构
#ifdef __CUDA_ARCH__
  #if __CUDA_ARCH__ >= 800
    #include "sm_80_features.h"
  #elif __CUDA_ARCH__ >= 700
    #include "sm_70_features.h"
  #else
    #include "sm_common.h"
  #endif
#endif

#include "sm_host.h"

// 简单的内核,仅用于演示
__global__ void hello_kernel() {
  #ifdef __CUDA_ARCH__
    printf("Hello from GPU! Architecture: %d\n", __CUDA_ARCH__);
  #endif
}

int main() {
  hello_kernel<<<1, 1>>>();
  cudaDeviceSynchronize();
  return 0;
}

touch to make empty headers:
touch sm_70_features.h  sm_80_features.h  sm_common.h  sm_host.h

if we compile with:
clang++-14 -M -MT example.o example.cu   --cuda-gpu-arch=sm_75   
-I/usr/local/cuda/include -MF example.d

we get no header file dependency for kernel headers:
cat example.d | grep sm
  /usr/local/cuda/include/sm_20_atomic_functions.hpp \
  /usr/local/cuda/include/sm_20_intrinsics.hpp \
  /usr/local/cuda/include/sm_32_atomic_functions.hpp \
  /usr/local/cuda/include/sm_60_atomic_functions.hpp \
  /usr/local/cuda/include/sm_61_intrinsics.hpp \
  /usr/local/cuda/include/crt/sm_70_rt.hpp \
  /usr/include/x86_64-linux-gnu/bits/stdio_lim.h sm_70_features.h \
  sm_host.h

only sm_host.h show in example.d!!

when this patch is enabled:
    if we compile sm70, only sm_70_features.h will show in example.d. 
    if we compile sm80, only sm_80_features.h will show in example.d. 
    if we compile sm70 and sm80, sm_70_features.h and sm_80_features.h will 
show in example.d. 

https://github.com/llvm/llvm-project/pull/176072
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to