tqchen commented on a change in pull request #5601:
URL: https://github.com/apache/incubator-tvm/pull/5601#discussion_r427706238



##########
File path: include/tvm/runtime/c_runtime_api.h
##########
@@ -114,6 +114,7 @@ typedef enum {
   kTVMNNVMLast = 20U,
   // The following section of code is used for non-reserved types.
   kTVMExtReserveEnd = 64U,
+  kTVMBFloat = 65U,

Review comment:
       We do not want BFloat to be passed as PackedFunc argument, most 
packedfunc argument should always be passed as double

##########
File path: include/tvm/runtime/data_type.h
##########
@@ -297,6 +302,8 @@ inline const char* TypeCode2Str(int type_code) {
       return "Object";
     case kTVMObjectRValueRefArg:
       return "ObjectRValueRefArg";
+    case kTVMBFloat:
+      return "bf";

Review comment:
       bfloat

##########
File path: src/target/llvm/codegen_llvm.cc
##########
@@ -555,12 +558,48 @@ void CodeGenLLVM::CreateSerialFor(llvm::Value* begin, 
llvm::Value* end, llvm::Va
   builder_->SetInsertPoint(for_end);
 }
 
+static llvm::Value* GetInt32VectorOrScalar(
+    llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter>* 
builder, uint32_t v,
+    int lanes) {
+  if (lanes == 1) {
+    return builder->getInt32(v);
+  } else {
+    std::vector<llvm::Constant*> consts;
+    for (int i = 0; i < lanes; i++) {
+      consts.emplace_back(builder->getInt32(v));
+    }
+    return llvm::ConstantVector::get(consts);
+  }
+}
+
 // cast operatpr
 llvm::Value* CodeGenLLVM::CreateCast(DataType from, DataType to, llvm::Value* 
value) {
   llvm::Type* target = DTypeToLLVMType(to);
   if (value->getType() == target) return value;
   if (to.is_handle()) {
     return builder_->CreateBitCast(value, target);
+  } else if (to.is_float() && from.is_bfloat()) {
+    CHECK_EQ(from.bits(), 16);

Review comment:
       If LLVM does not support bfloat, then perhaps we should do the 
legalization as a TIR=>TIR pass as opposed to do it in LLVM

##########
File path: include/tvm/runtime/data_type.h
##########
@@ -81,6 +82,10 @@ class DataType {
   bool is_float() const { return code() == DataType::kFloat; }
   /*! \return whether type is a float16 type. */
   bool is_float16() const { return is_float() && bits() == 16; }
+  /*! \return whether type is a bfloat type. */
+  bool is_bfloat() const { return code() == DataType::kBFloat; }

Review comment:
       given that only bfloat16 is defined, is_bf16 is a good enough function




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to