Skip to content

Commit

Permalink
[bug] Fix error with windows-clang compilation for cuda_runtime.cu (t…
Browse files Browse the repository at this point in the history
  • Loading branch information
jim19930609 authored and quadpixels committed May 13, 2023
1 parent 8bbef1e commit ed21306
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 19 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def setup_clang(as_compiler=True) -> None:
if u.system == 'Linux':
pass
elif (u.system, u.machine) == ('Windows', 'AMD64'):
out = get_cache_home() / 'clang-15'
url = 'https://github.com/python3kgae/taichi_assets/releases/download/llvm15_vs2022_clang/clang-15.0.0-win.zip'
download_dep(url, out)
out = get_cache_home() / 'clang-15-v2'
url = 'https://github.com/taichi-dev/taichi_assets/releases/download/llvm15/clang-15.0.0-win-complete.zip'
download_dep(url, out, force=True)
clang = str(out / 'bin' / 'clang++.exe').replace('\\', '\\\\')
os.environ['TAICHI_CMAKE_ARGS'] += f' -DCLANG_EXECUTABLE={clang}'

Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ endif()
macro(check_clang_version)
execute_process(COMMAND ${CLANG_EXECUTABLE} --version OUTPUT_VARIABLE CLANG_VERSION_OUTPUT)
string(REGEX MATCH "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION "${CLANG_VERSION_OUTPUT}")

message("${CLANG_EXECUTABLE} --version: ${CLANG_VERSION}")

set(CLANG_VERSION_MAJOR "${CMAKE_MATCH_1}")
Expand Down
5 changes: 1 addition & 4 deletions taichi/codegen/cuda/codegen_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ class TaskCodeGenCUDA : public TaskCodeGenLLVM {
old_val = Load(old_val_ptr)
*/

// Allocate old_val_ptr to store the result of atomic_add
auto char_type = llvm::Type::getInt8Ty(*tlctx->get_this_thread_context());
auto half_type = llvm::Type::getHalfTy(*tlctx->get_this_thread_context());
Expand Down Expand Up @@ -335,12 +334,10 @@ class TaskCodeGenCUDA : public TaskCodeGenLLVM {
builder->CreateStore(value1, value_ptr1);
llvm::Value *value_half2_ptr =
builder->CreateBitCast(value_ptr, ptr_type);

// Defined in taichi/runtime/llvm/runtime_module/cuda_runtime.cu
call("half2_atomic_add", dest_half2_ptr, old_val_ptr, value_half2_ptr);

llvm_val[atomic_stmt] = builder->CreateLoad(
old_val->getType()->getPointerElementType(), old_val);
llvm_val[atomic_stmt] = builder->CreateLoad(half_type, old_val);
return;
}

Expand Down
16 changes: 6 additions & 10 deletions taichi/runtime/llvm/runtime_module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,11 @@ foreach(arch IN LISTS HOST_ARCH CUDA_ARCH DX12_ARCH AMDGPU_ARCH)
compile_llvm_runtime(${arch})
endforeach()

if(NOT WIN32)
# clang++ on Windows reports an internal error of "<built-in>:1:10: fatal error: '__clang_cuda_runtime_wrapper.h' file not found" when compiling for CUDA targets
# so we can't use hand-writen cuda libraries util this issue get resolved
if(CUDA_ARCH)
find_package(CUDAToolkit)
if(${CUDAToolkit_FOUND})
if(${CUDAToolkit_VERSION_MAJOR} GREATER_EQUAL 8)
compile_custom_cuda_library(${CUDAToolkit_TARGET_DIR})
endif()
endif()
if(CUDA_ARCH)
find_package(CUDAToolkit)
if(${CUDAToolkit_FOUND})
if(${CUDAToolkit_VERSION_MAJOR} GREATER_EQUAL 8)
compile_custom_cuda_library(${CUDAToolkit_TARGET_DIR})
endif()
endif()
endif()
2 changes: 0 additions & 2 deletions taichi/runtime/llvm/runtime_module/cuda_runtime.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#pragma once

#include <cuda_fp16.h>

/*
Expand Down

0 comments on commit ed21306

Please sign in to comment.