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

[CI][Windows] Workaround for error in Findzstd.cmake #17283

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ jobs:
- name: Test
shell: cmd /C call {0}
run: >-
python -m pytest -v tests/python/all-platform-minimal-test
python -m pytest -v -s tests/python/all-platform-minimal-test

# Disabled due to https://github.com/apache/tvm/issues/13950
# Windows-Static-Runtime:
Expand Down
9 changes: 9 additions & 0 deletions cmake/utils/FindLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ macro(find_llvm use_llvm)
endif()

if(${LLVM_CONFIG} MATCHES ${IS_TRUE_PATTERN})
# This is a workaround for an upstream LLVM issue [0], in which
# the `CMAKE_INSTALL_LIBDIR` variable is used before definition.
# While there is an LLVM PR to resolve this fix [1], as of
# 2024-08-19 it has not yet been merged to LLVM.
#
# [0] https://github.com/llvm/llvm-project/issues/83802
# [1] https://github.com/llvm/llvm-project/pull/83807
include(GNUInstallDirs)

find_package(LLVM ${llvm_version_required} REQUIRED CONFIG)
llvm_map_components_to_libnames(LLVM_LIBS "all")
if (NOT LLVM_LIBS)
Expand Down
15 changes: 14 additions & 1 deletion src/target/llvm/codegen_llvm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ void CodeGenLLVM::InitTarget() {
// reside in a separate section (ELF).
llvm::Triple::ArchType arch_type = tm->getTargetTriple().getArch();
if (arch_type == llvm::Triple::x86 || arch_type == llvm::Triple::x86_64) {
LOG(DEBUG) << "Inspecting availability of SSE2 on architecture " << arch_type << " ("
<< std::string(tm->getTargetTriple().getArchName()) << ")";
// Detect if SSE2 is enabled. This determines whether float16 ABI is used.
std::stringstream os;
const char fname[] = "test_sse2";
Expand All @@ -217,12 +219,23 @@ void CodeGenLLVM::InitTarget() {
auto* test_sse2 = mod->getFunction(fname);
ICHECK(test_sse2 != nullptr) << "Module creation error";
use_float16_abi = tm->getSubtargetImpl(*test_sse2)->checkFeatures("+sse2");

LOG(DEBUG) << "SSE2 is available on target: " << (use_float16_abi ? "true" : "false");
} else {
LOG(DEBUG) << "Inspection for availability of SSE2 skipped for architecture " << arch_type
<< " (" << std::string(tm->getTargetTriple().getArchName()) << ")";
}
#endif // TVM_LLVM_VERSION >= 150

LOG(DEBUG) << "Using LLVM version " << TVM_LLVM_VERSION
<< ", emitting Float16 builtins with ABI: "
<< (use_float16_abi ? "float16" : "uint16");

// Call this function only with LLVM >= 6.0. The code it emits uses "dso_local"
// which was introduced in LLVM 6.
EmitFloat16ConversionBuiltins(use_float16_abi);
LOG(DEBUG) << "Commenting out the EmitFloat16ConversionBuiltins, "
<< "to see if there's an incompatibility in Windows CI";
// EmitFloat16ConversionBuiltins(use_float16_abi);
#endif // TVM_LLVM_VERSION >= 60
}

Expand Down
32 changes: 31 additions & 1 deletion src/target/llvm/llvm_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,38 @@ PackedFunc LLVMModuleNode::GetFunction(const String& name, const ObjectPtr<Objec
GetGlobalAddr(runtime::symbol::tvm_module_main, *llvm_target));
ICHECK(entry_name != nullptr) << "Symbol " << runtime::symbol::tvm_module_main
<< " is not presented";

LOG(DEBUG) << "PackedFunc for '" << name << "' uses default entry point, "
<< "defined in module to be '" << entry_name << "'";

faddr = reinterpret_cast<TVMBackendPackedCFunc>(GetFunctionAddr(entry_name, *llvm_target));
} else {
faddr = reinterpret_cast<TVMBackendPackedCFunc>(GetFunctionAddr(name, *llvm_target));
}
if (faddr == nullptr) return PackedFunc();
return WrapPackedFunc(faddr, sptr_to_self);

return PackedFunc([faddr, sptr_to_self, name](TVMArgs args, TVMRetValue* rv) {
TVMValue ret_value;
int ret_type_code = kTVMNullptr;
auto arg_values = const_cast<TVMValue*>(args.values);
auto arg_type_codes = const_cast<int*>(args.type_codes);

LOG(DEBUG) << "About to call LLVM function " << name << ", located at address " << faddr;

int ret =
(*faddr)(arg_values, arg_type_codes, args.num_args, &ret_value, &ret_type_code, nullptr);
// NOTE: It is important to keep the original error message.
// Using the `TVMThrowLastError()` function will also preserve the
// full stack trace for debugging in pdb.
if (ret != 0) {
TVMThrowLastError();
}
if (ret_type_code != kTVMNullptr) {
*rv = TVMRetValue::MoveFromCHost(ret_value, ret_type_code);
}
});

// return WrapPackedFunc(faddr, sptr_to_self);
}

namespace {
Expand Down Expand Up @@ -595,8 +621,12 @@ void* LLVMModuleNode::GetFunctionAddr(const std::string& name,
// first verifies if GV exists.
if (module_->getFunction(name) != nullptr) {
if (jit_engine_ == "mcjit") {
LOG(DEBUG) << "Loading function " << name << " through mcjit (llvm::ExecutionEngine)";
ICHECK(mcjit_ee_);
return reinterpret_cast<void*>(mcjit_ee_->getFunctionAddress(name));
} else if (jit_engine_ == "orcjit") {
LOG(DEBUG) << "Loading function " << name << " through orjit (llvm::orc::LLJIT)";
ICHECK(orcjit_ee_);
#if TVM_LLVM_VERSION >= 150
auto addr = llvm::cantFail(orcjit_ee_->lookup(name)).getValue();
#else
Expand Down
Loading
Loading