-
Notifications
You must be signed in to change notification settings - Fork 93
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
[Enhancement] Extension of initializing arbitrary bit integer in hcl.scalar from string #431
base: tvm
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please also pull back the latest changes in the master branch? Just want to make sure all the tests are passed before we merge it.
tvm/src/codegen/llvm/llvm_module.cc
Outdated
void InitHB(Array<LoweredFunc> funcs, std::string target) { | ||
InitializeLLVM(); | ||
CHECK(target.length() >= 11 && target.substr(0, 11) == "hammerblade"); | ||
std::ostringstream config; | ||
config << "-mtriple=riscv32-unknown-unknown -mabi=ilp32f"; | ||
tm_ = GetLLVMTargetMachine(config.str()); | ||
std::unique_ptr<CodeGenLLVM> cg = CodeGenLLVM::Create(tm_); | ||
ctx_ = std::make_shared<llvm::LLVMContext>(); | ||
std::unique_ptr<llvm::LLVMContext> ctx(new llvm::LLVMContext()); | ||
cg->Init(funcs[0]->name, tm_, ctx_.get(), false, false); | ||
for (LoweredFunc f : funcs) { | ||
cg->AddFunction(f); | ||
} | ||
cg->AddMainFunction(funcs[0]->name); | ||
module_ = cg->Finish(); | ||
module_->addModuleFlag(llvm::Module::Warning, "tvm_target", | ||
llvm::MDString::get(*ctx_, target)); | ||
target_ = target; | ||
mptr_ = module_.get(); | ||
this->SaveToFile("hb_test.ll", "ll"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for HB simulation in HCL right? I would suggest using another PR to introduce HB backend in HCL
tvm/src/codegen/llvm/llvm_module.cc
Outdated
TVM_REGISTER_API("codegen.build_hammerblade") | ||
.set_body([](TVMArgs args, TVMRetValue* rv) { | ||
std::shared_ptr<LLVMModuleNode> n = std::make_shared<LLVMModuleNode>(); | ||
n->InitHB(args[0], args[1]); | ||
*rv = runtime::Module(n); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. HB target may as well be introduced separately.
tvm/src/codegen/llvm/codegen_llvm.cc
Outdated
if (kernel_has_assert_[op->name]) { | ||
llvm::BasicBlock* assert_true_kernel = | ||
llvm::BasicBlock::Create(*ctx_, "assert_true_kernel", function_); | ||
llvm::BasicBlock* assert_false_kernel = | ||
llvm::BasicBlock::Create(*ctx_, "assert_false_kernel", function_); | ||
llvm::Value* assert_flag = | ||
builder_->CreateLoad(llvm::Type::getInt32Ty(*ctx_), assert_global_ptr_); | ||
llvm::Value* cond = builder_->CreateICmpEQ(assert_flag, ConstInt32(1)); | ||
builder_->CreateCondBr(cond, assert_true_kernel, assert_false_kernel); | ||
builder_->SetInsertPoint(assert_false_kernel); | ||
AssertFreeVars(); | ||
builder_->CreateRet(ConstInt32(1)); | ||
builder_->SetInsertPoint(assert_true_kernel); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why inserting the kernel only when there is an assertion inside? can you please explain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not modify this part, it is the same with what inside the master branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zzy82518996 can you run "git pull upstream master" to merge the latest changes in main branch? It seems that some changes are missing and the local CI/CD is not working as expected.
For fixing issues
Add feature: enable initializing the arbitrary bit integer using hcl.scalar from string
Link to the tests: tests/test_scalar.py
Detailed Description : We extend the heteroCL IR by adding the CastStr expression, and use APInt class to convert string to ConstantInt class in codegen_llvm.