[FRONTEND] Fix libdevice (#776)

Fix two problems in libdevice and external dispatch:

1. Use static triton types (e.g., tl.int32) instead of creating new
types. Otherwise, `tl.int32` and `tl.dtype('int32')` are not the same
thing.

2. The name of an extern inst should be empty but not the symbol name of
the inst. TTIR generator will assign names automatically. Otherwise, we
have the same variable name when there are multiple same extern insts.

Before the PR:

```bash
  __nv_exp = extern_elementwise f64<1024> %11;
  __nv_exp = extern_elementwise f64<1024> %11;
```

After the PR:

```bash
  %12 = extern_elementwise f64<1024> %11;
  %13 = extern_elementwise f64<1024> %11;
```
This commit is contained in:
Keren Zhou
2022-10-13 17:18:16 -07:00
committed by GitHub
parent ddae106c0e
commit db3aa1d1fb
5 changed files with 349 additions and 344 deletions

View File

@@ -3531,7 +3531,7 @@ void generator::visit_extern_elementwise_inst(ir::extern_elementwise_inst *i) {
FunctionType *FT =
FunctionType::get(ret_type, std::move(operand_types), false);
Function *F = llvm::cast<llvm::Function>(
mod_->getOrInsertFunction(i->get_name(), FT).getCallee());
mod_->getOrInsertFunction(i->get_symbol_name(), FT).getCallee());
for (auto idx : idxs_.at(i)) {
std::vector<llvm::Value *> args;
for (size_t j = 0; j < i->get_num_operands(); j++) {

View File

@@ -1007,11 +1007,11 @@ globaltimer_inst* globaltimer_inst::create(context &ctx, const std::string &name
extern_elementwise_inst::extern_elementwise_inst(
context &ctx, const std::vector<value *> &args, type *ret_ty,
const std::string &lib_name, const std::string &lib_path,
const std::string &symbol_name, instruction *next)
: instruction(ret_ty, INST_EXTERN_ELEMENTWISE, args.size(), symbol_name,
next),
const std::string &symbol_name, const std::string &name, instruction *next)
: instruction(ret_ty, INST_EXTERN_ELEMENTWISE, args.size(), name, next),
lib_name_(lib_name),
lib_path_(lib_path) {
lib_path_(lib_path),
symbol_name_(symbol_name) {
for (size_t i = 0; i < args.size(); i++) {
set_operand(i, args[i]);
}
@@ -1020,9 +1020,10 @@ extern_elementwise_inst::extern_elementwise_inst(
extern_elementwise_inst *extern_elementwise_inst::create(
context &ctx, const std::vector<value *> &args, type *ret_ty,
const std::string &lib_name, const std::string &lib_path,
const std::string &symbol_name, instruction *next) {
const std::string &symbol_name, const std::string &name,
instruction *next) {
return new extern_elementwise_inst(ctx, args, ret_ty, lib_name, lib_path,
symbol_name, next);
symbol_name, name, next);
}
// clock