[Beignet] [Patch v2 08/10] gbe: add vec_type_hint's type into functionAttributes.

Yang, Rong R rong.r.yang at intel.com
Tue Dec 1 22:39:01 PST 2015


Build error in LLVM3.5, because of mdconst::extract.

> -----Original Message-----
> From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of
> xionghu.luo at intel.com
> Sent: Thursday, November 26, 2015 14:00
> To: beignet at lists.freedesktop.org
> Cc: Luo, Xionghu
> Subject: [Beignet] [Patch v2 08/10] gbe: add vec_type_hint's type into
> functionAttributes.
> 
> From: Luo Xionghu <xionghu.luo at intel.com>
> 
> for SPIR kernel, user may call clGetKernelInfo with CL_KERNEL_ATTRIBUTES
> to query the functionAttributes.
> 
> v2: remove debug code.
> 
> Signed-off-by: Luo Xionghu <xionghu.luo at intel.com>
> ---
>  backend/src/ir/type.cpp               |  6 ++--
>  backend/src/llvm/llvm_gen_backend.cpp | 64
> +++++++++++++++++++++++++++++++++++
>  2 files changed, 67 insertions(+), 3 deletions(-)
> 
> diff --git a/backend/src/ir/type.cpp b/backend/src/ir/type.cpp index
> 450ba61..682757b 100644
> --- a/backend/src/ir/type.cpp
> +++ b/backend/src/ir/type.cpp
> @@ -32,11 +32,11 @@ namespace ir {
>        case TYPE_S8: return out << "int8";
>        case TYPE_U8: return out << "uint8";
>        case TYPE_S16: return out << "int16";
> -      case TYPE_U16: return out << "uin16";
> +      case TYPE_U16: return out << "uint16";
>        case TYPE_S32: return out << "int32";
> -      case TYPE_U32: return out << "uin32";
> +      case TYPE_U32: return out << "uint32";
>        case TYPE_S64: return out << "int64";
> -      case TYPE_U64: return out << "uin64";
> +      case TYPE_U64: return out << "uint64";
>        case TYPE_HALF: return out << "half";
>        case TYPE_FLOAT: return out << "float";
>        case TYPE_DOUBLE: return out << "double"; diff --git
> a/backend/src/llvm/llvm_gen_backend.cpp
> b/backend/src/llvm/llvm_gen_backend.cpp
> index d1f48ab..fc1a0e0 100644
> --- a/backend/src/llvm/llvm_gen_backend.cpp
> +++ b/backend/src/llvm/llvm_gen_backend.cpp
> @@ -111,6 +111,46 @@ namespace gbe
>             type->isPointerTy();
>    }
> 
> +  static std::string getTypeName(ir::Context &ctx, const Type *type,
> + int sign)  {
> +    GBE_ASSERT(isScalarType(type));
> +    if (type->isFloatTy() == true)
> +      return "float";
> +    if (type->isHalfTy() == true)
> +      return "half";
> +    if (type->isDoubleTy() == true)
> +      return "double";
> +
> +    GBE_ASSERT(type->isIntegerTy() == true);
> +    if(sign) {
> +      if (type == Type::getInt1Ty(type->getContext()))
> +        return "char";
> +      if (type == Type::getInt8Ty(type->getContext()))
> +        return "char";
> +      if (type == Type::getInt16Ty(type->getContext()))
> +        return "short";
> +      if (type == Type::getInt32Ty(type->getContext()))
> +        return "int";
> +      if (type == Type::getInt64Ty(type->getContext()))
> +        return "long";
> +    }
> +    else
> +    {
> +      if (type == Type::getInt1Ty(type->getContext()))
> +        return "uchar";
> +      if (type == Type::getInt8Ty(type->getContext()))
> +        return "uchar";
> +      if (type == Type::getInt16Ty(type->getContext()))
> +        return "ushort";
> +      if (type == Type::getInt32Ty(type->getContext()))
> +        return "uint";
> +      if (type == Type::getInt64Ty(type->getContext()))
> +        return "ulong";
> +    }
> +    GBE_ASSERTM(false, "Unsupported type.");
> +    return "";
> +  }
> +
>    /*! LLVM IR Type to Gen IR type translation */
>    static ir::Type getType(ir::Context &ctx, const Type *type)
>    {
> @@ -1944,6 +1984,30 @@ namespace gbe
>        } else if (attrName->getString() == "vec_type_hint") {
>          GBE_ASSERT(attrNode->getNumOperands() == 3);
>          functionAttributes += attrName->getString();
> +        auto *Op1 = cast<ValueAsMetadata>(attrNode->getOperand(1));
> +        ConstantInt *sign = mdconst::extract<ConstantInt>(attrNode-
> >getOperand(2));
> +        size_t signValue = sign->getZExtValue();
> +        Value *V = Op1->getValue();
> +        Type* vtype = V->getType();
> +        Type* stype = vtype;
> +        uint32_t elemNum = 0;
> +        if(vtype->isVectorTy()) {
> +          VectorType *vectorType = cast<VectorType>(vtype);
> +          stype = vectorType->getElementType();
> +          elemNum = vectorType->getNumElements();
> +        }
> +
> +        std::string typeName = getTypeName(ctx, stype, signValue);
> +
> +        std::stringstream param;
> +        char buffer[100];
> +        param <<"(";
> +        param << typeName;
> +        if(vtype->isVectorTy())
> +          param << elemNum;
> +        param <<")";
> +        param >> buffer;
> +        functionAttributes += buffer;
>          functionAttributes += " ";
>        } else if (attrName->getString() == "work_group_size_hint") {
>          GBE_ASSERT(attrNode->getNumOperands() == 4);
> --
> 1.9.1
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list