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

[HIPIFY] clang_cuda_runtime_wrapper.h:41:10: fatal error: 'cmath' file not found #983

Closed
GowriShankarEAAS opened this issue Aug 9, 2023 · 7 comments
Assignees
Labels
clang clang compiler related issue or change CUDA CUDA-related question Further information is requested

Comments

@GowriShankarEAAS
Copy link

GowriShankarEAAS commented Aug 9, 2023

Hi,

i am getting following error. Could you please suggest me what i am missing

error:

warning: CUDA version is newer than the latest partially supported version 11.8 [-Wunknown-cuda-version]
In file included from :1:
/opt/rocm-5.6.0/bin/../include/hipify/__clang_cuda_runtime_wrapper.h:41:10: fatal error: 'cmath' file not found
#include
^~~~~~~
#0 0x00000000023c3016 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/rocm-5.6.0/bin/hipify-clang+0x23c3016)
#1 0x00000000023c0914 SignalHandler(int) Signals.cpp:0:0
#2 0x00007f646e607520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#3 0x0000000000a12510 (anonymous namespace)::PPCallbackProxy::InclusionDirective(clang::SourceLocation, clang::Token const&, llvm::StringRef, bool, clang::CharSourceRange, clang::CustomizableOptionalclang::FileEntryRef, llvm::StringRef, llvm::StringRef, clang::Module const*, clang ::SrcMgr::CharacteristicKind) HipifyAction.cpp:0:0
#4 0x00000000019b74f1 clang::PPChainedCallbacks::InclusionDirective(clang::SourceLocation, clang::Token const&, llvm::StringRef, bool, clang: :CharSourceRange, clang::CustomizableOptionalclang::FileEntryRef, llvm::StringRef, llvm::StringRef, clang::Module const*, clang::SrcMgr::Cha racteristicKind) PPCallbacks.cpp:0:0
#5 0x00000000019c8016 clang::Preprocessor::HandleHeaderIncludeOrImport(clang::SourceLocation, clang::Token&, clang::Token&, clang::SourceLoca tion, clang::detail::SearchDirIteratorImpl, clang::FileEntry const*) (/opt/rocm-5.6.0/bin/hipify-clang+0x19c8016)
#6 0x00000000019c9881 clang::Preprocessor::HandleIncludeDirective(clang::SourceLocation, clang::Token&, clang::detail::SearchDirIteratorImpl< true>, clang::FileEntry const*) (/opt/rocm-5.6.0/bin/hipify-clang+0x19c9881)
#7 0x00000000019ca6b8 clang::Preprocessor::HandleDirective(clang::Token&) (/opt/rocm-5.6.0/bin/hipify-clang+0x19ca6b8)
#8 0x0000000001984a6d clang::Lexer::LexTokenInternal(clang::Token&, bool) (/opt/rocm-5.6.0/bin/hipify-clang+0x1984a6d)
#9 0x0000000001a03f37 clang::Preprocessor::Lex(clang::Token&) (/opt/rocm-5.6.0/bin/hipify-clang+0x1a03f37)
#10 0x0000000000bea1af clang::Parser::ConsumeBrace() Parser.cpp:0:0
#11 0x0000000000bf69f2 clang::BalancedDelimiterTracker::consumeClose() Parser.cpp:0:0
#12 0x0000000000c792d6 clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation) (/opt/rocm-5.6.0 /bin/hipify-clang+0xc792d6)
#13 0x0000000000c5e635 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::Pars edAttributes&, clang::SourceLocation*) (/opt/rocm-5.6.0/bin/hipify-clang+0xc5e635)
#14 0x0000000000bf77e7 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/ opt/rocm-5.6.0/bin/hipify-clang+0xbf77e7)
#15 0x0000000000bf90a6 clang::Parser::ParseTopLevelDecl(clang::OpaquePtrclang::DeclGroupRef&, clang::Sema::ModuleImportState&) (/opt/rocm-5. 6.0/bin/hipify-clang+0xbf90a6)
#16 0x0000000000be9bca clang::ParseAST(clang::Sema&, bool, bool) (/opt/rocm-5.6.0/bin/hipify-clang+0xbe9bca)
#17 0x0000000000a12343 HipifyAction::ExecuteAction() (/opt/rocm-5.6.0/bin/hipify-clang+0xa12343)
#18 0x0000000000a7e259 clang::FrontendAction::Execute() (/opt/rocm-5.6.0/bin/hipify-clang+0xa7e259)
#19 0x0000000000a928b1 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/rocm-5.6.0/bin/hipify-clang+0xa928b1)
#20 0x0000000000be9334 clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptrclang::CompilerInvocation, clang::FileManager*, s td::shared_ptrclang::PCHContainerOperations, clang::DiagnosticConsumer*) (/opt/rocm-5.6.0/bin/hipify-clang+0xbe9334)
#21 0x0000000000be21f5 clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, std::shared_ptr<clang::Compiler Invocation>, std::shared_ptrclang::PCHContainerOperations) (/opt/rocm-5.6.0/bin/hipify-clang+0xbe21f5)
#22 0x0000000000be5588 clang::tooling::ToolInvocation::run() (/opt/rocm-5.6.0/bin/hipify-clang+0xbe5588)
#23 0x0000000000be77a0 clang::tooling::ClangTool::run(clang::tooling::ToolAction*) (/opt/rocm-5.6.0/bin/hipify-clang+0xbe77a0)
#24 0x0000000000bdf8c7 clang::tooling::RefactoringTool::runAndSave(clang::tooling::FrontendActionFactory*) (/opt/rocm-5.6.0/bin/hipify-clang+0 xbdf8c7)
#25 0x0000000000a26ebf main (/opt/rocm-5.6.0/bin/hipify-clang+0xa26ebf)
#26 0x00007f646e5eed90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#27 0x00007f646e5eee40 call_init ./csu/../csu/libc-start.c:128:20
#28 0x00007f646e5eee40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#29 0x00000000009c7265 _start (/opt/rocm-5.6.0/bin/hipify-clang+0x9c7265)
Segmentation fault (core dumped)

@emankov emankov self-assigned this Aug 9, 2023
@emankov emankov changed the title clang_cuda_runtime_wrapper.h:41:10: fatal error: 'cmath' file not found [HIPIFY] clang_cuda_runtime_wrapper.h:41:10: fatal error: 'cmath' file not found Aug 9, 2023
@emankov
Copy link
Collaborator

emankov commented Aug 9, 2023

Could you share your source snippet and the command line of the hipify-clang invocation, please?

@emankov emankov added the failure failure label Aug 9, 2023
@GowriShankarEAAS
Copy link
Author

GowriShankarEAAS commented Aug 9, 2023

The command i am execting ==> hipify-clang /darknet/src/avgpool_layer_kernels.cu --cuda-path=/usr/local/cuda-12.2 -I /usr/local/cuda-12.2/samples/common/inc -I/darknet/include/

avgpool_layer_kernels.cu is

_#include "gpu.hpp"

#include "avgpool_layer.h"
#include "dark_cuda.h"

global void forward_avgpool_layer_kernel(int n, int w, int h, int c, float *input, float output)
{
int id = (blockIdx.x + blockIdx.y
gridDim.x) * blockDim.x + threadIdx.x;
if(id >= n) return;

int k = id % c;
id /= c;
int b = id;

int i;
int out_index = (k + c*b);
output[out_index] = 0;
for(i = 0; i < w*h; ++i){
    int in_index = i + h*w*(k + b*c);
    output[out_index] += input[in_index];
}
output[out_index] /= w*h;

}

global void backward_avgpool_layer_kernel(int n, int w, int h, int c, float *in_delta, float out_delta)
{
int id = (blockIdx.x + blockIdx.y
gridDim.x) * blockDim.x + threadIdx.x;
if(id >= n) return;

int k = id % c;
id /= c;
int b = id;

int i;
int out_index = (k + c*b);
for(i = 0; i < w*h; ++i){
    int in_index = i + h*w*(k + b*c);
    in_delta[in_index] += out_delta[out_index] / (w*h);
}

}

extern "C" void forward_avgpool_layer_gpu(avgpool_layer layer, network_state state)
{
size_t n = layer.c*layer.batch;

forward_avgpool_layer_kernel<<<cuda_gridsize(n), BLOCK, 0, get_cuda_stream() >>>(n, layer.w, layer.h, layer.c, state.input, layer.output_gpu);
CHECK_CUDA(cudaPeekAtLastError());

}

extern "C" void backward_avgpool_layer_gpu(avgpool_layer layer, network_state state)
{
size_t n = layer.c*layer.batch;

backward_avgpool_layer_kernel<<<cuda_gridsize(n), BLOCK, 0, get_cuda_stream() >>>(n, layer.w, layer.h, layer.c, state.delta, layer.delta_gpu);
CHECK_CUDA(cudaPeekAtLastError());

} "_

@emankov
Copy link
Collaborator

emankov commented Aug 10, 2023

The latest CUDA partially supported by clang in ROCm 5.6.0 is 12.1.0, but better to use CUDA 11.8 with ROCm 5.6. CUDA 12.2.x is partially supported by the trunk clang. You may build hipify-clang against trunk LLVM/clang and then use it against CUDA 12.2.x sources or wait for CUDA 12.2.x support in the next ROCm releases.

@emankov emankov added clang clang compiler related issue or change CUDA CUDA-related labels Aug 10, 2023
@GowriShankarEAAS
Copy link
Author

Sure. will try with CUDA 11.8.
Thank you

@GowriShankarEAAS
Copy link
Author

getting following error:

$ hipify-clang /darknet/src/avgpool_layer_kernels.cu --cuda-path=/usr/local/cuda-11 -I /usr/local/cuda-11/samples/common/include -I /usr/lib/llvm-16/lib/clang/16/include/cuda_wrappers -I /usr/include/c++/11 -I /usr/include/x86_64-linux-gnu/c++/11 -I /darknet/include/ -o avgpool_layer_kernels.cpp

warning: CUDA version 11.8 is only partially supported [-Wunknown-cuda-version]
/tmp/avgpool_layer_kernels.cu-b605ca.hip:46:36: error: use of undeclared identifier 'cuda_gridsize'
forward_avgpool_layer_kernel<<<cuda_gridsize(n), BLOCK, 0, get_cuda_stream() >>>(n, layer.w, layer.h, layer.c, state.input, layer.output_gpu);
^
/tmp/avgpool_layer_kernels.cu-b605ca.hip:46:64: error: use of undeclared identifier 'get_cuda_stream'
forward_avgpool_layer_kernel<<<cuda_gridsize(n), BLOCK, 0, get_cuda_stream() >>>(n, layer.w, layer.h, layer.c, state.input, layer.output_gpu);
^
/tmp/avgpool_layer_kernels.cu-b605ca.hip:46:54: error: use of undeclared identifier 'BLOCK'
forward_avgpool_layer_kernel<<<cuda_gridsize(n), BLOCK, 0, get_cuda_stream() >>>(n, layer.w, layer.h, layer.c, state.input, layer.output_gpu);
^
/tmp/avgpool_layer_kernels.cu-b605ca.hip:47:5: error: use of undeclared identifier 'CHECK_CUDA'
CHECK_CUDA(cudaPeekAtLastError());
^
/tmp/avgpool_layer_kernels.cu-b605ca.hip:54:37: error: use of undeclared identifier 'cuda_gridsize'
backward_avgpool_layer_kernel<<<cuda_gridsize(n), BLOCK, 0, get_cuda_stream() >>>(n, layer.w, layer.h, layer.c, state.delta, layer.delta_gpu);
^
/tmp/avgpool_layer_kernels.cu-b605ca.hip:54:65: error: use of undeclared identifier 'get_cuda_stream'
backward_avgpool_layer_kernel<<<cuda_gridsize(n), BLOCK, 0, get_cuda_stream() >>>(n, layer.w, layer.h, layer.c, state.delta, layer.delta_gpu);
^
/tmp/avgpool_layer_kernels.cu-b605ca.hip:54:55: error: use of undeclared identifier 'BLOCK'
backward_avgpool_layer_kernel<<<cuda_gridsize(n), BLOCK, 0, get_cuda_stream() >>>(n, layer.w, layer.h, layer.c, state.delta, layer.delta_gpu);
^
/tmp/avgpool_layer_kernels.cu-b605ca.hip:55:5: error: use of undeclared identifier 'CHECK_CUDA'
CHECK_CUDA(cudaPeekAtLastError());
^
8 errors generated when compiling for host.
Error while processing /tmp/avgpool_layer_kernels.cu-b605ca.hip.

@emankov
Copy link
Collaborator

emankov commented Aug 11, 2023

You need to add the -I option to the folder(s), where the undeclared identifiers are declared (cuda_gridsize, get_cuda_stream, etc.).

@emankov emankov added question Further information is requested and removed failure failure labels Sep 5, 2023
@emankov
Copy link
Collaborator

emankov commented Sep 5, 2023

Closing as answered.

@emankov emankov closed this as completed Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang clang compiler related issue or change CUDA CUDA-related question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants