aboutsummaryrefslogtreecommitdiff
path: root/mlir/test/CAPI/ir.c
diff options
context:
space:
mode:
authorStella Laurenzo <stellaraccident@gmail.com>2023-09-11 14:10:03 -0700
committerGitHub <noreply@github.com>2023-09-11 14:10:03 -0700
commit7055df7b4f6abf64f672703316bb8a7e7b185652 (patch)
tree01ab08f451a24190390cc1a8260f08694a7b42f0 /mlir/test/CAPI/ir.c
parentcc2013061ee63f3fc4f9b49c6d836d99d102071b (diff)
downloadllvm-7055df7b4f6abf64f672703316bb8a7e7b185652.zip
llvm-7055df7b4f6abf64f672703316bb8a7e7b185652.tar.gz
llvm-7055df7b4f6abf64f672703316bb8a7e7b185652.tar.bz2
[mlir] Make it possible to build a DenseResourceElementsAttr from untyped memory. (#66009)
Exposes the existing `get(ShapedType, StringRef, AsmResourceBlob)` builder publicly (was protected) and adds a CAPI `mlirUnmanagedDenseBlobResourceElementsAttrGet`. While such a generic construction interface is a big help when it comes to interop, it is also necessary for creating resources that don't have a standard C type (i.e. f16, the f8s, etc). Previously reviewed/approved as part of https://reviews.llvm.org/D157064
Diffstat (limited to 'mlir/test/CAPI/ir.c')
-rw-r--r--mlir/test/CAPI/ir.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/mlir/test/CAPI/ir.c b/mlir/test/CAPI/ir.c
index c3b78fe..5d78daa 100644
--- a/mlir/test/CAPI/ir.c
+++ b/mlir/test/CAPI/ir.c
@@ -1118,7 +1118,8 @@ int printBuiltinAttributes(MlirContext ctx) {
const uint8_t *uint8RawData =
(const uint8_t *)mlirDenseElementsAttrGetRawData(uint8Elements);
- const int8_t *int8RawData = (const int8_t *)mlirDenseElementsAttrGetRawData(int8Elements);
+ const int8_t *int8RawData =
+ (const int8_t *)mlirDenseElementsAttrGetRawData(int8Elements);
const uint32_t *uint32RawData =
(const uint32_t *)mlirDenseElementsAttrGetRawData(uint32Elements);
const int32_t *int32RawData =
@@ -1127,7 +1128,8 @@ int printBuiltinAttributes(MlirContext ctx) {
(const uint64_t *)mlirDenseElementsAttrGetRawData(uint64Elements);
const int64_t *int64RawData =
(const int64_t *)mlirDenseElementsAttrGetRawData(int64Elements);
- const float *floatRawData = (const float *)mlirDenseElementsAttrGetRawData(floatElements);
+ const float *floatRawData =
+ (const float *)mlirDenseElementsAttrGetRawData(floatElements);
const double *doubleRawData =
(const double *)mlirDenseElementsAttrGetRawData(doubleElements);
const uint16_t *bf16RawData =
@@ -1268,6 +1270,10 @@ int printBuiltinAttributes(MlirContext ctx) {
MlirAttribute doublesBlob = mlirUnmanagedDenseDoubleResourceElementsAttrGet(
mlirRankedTensorTypeGet(2, shape, mlirF64TypeGet(ctx), encoding),
mlirStringRefCreateFromCString("resource_f64"), 2, doubles);
+ MlirAttribute blobBlob = mlirUnmanagedDenseBlobResourceElementsAttrGet(
+ mlirRankedTensorTypeGet(2, shape, mlirIntegerTypeGet(ctx, 64), encoding),
+ mlirStringRefCreateFromCString("resource_i64_blob"), uints64,
+ sizeof(uints64));
mlirAttributeDump(uint8Blob);
mlirAttributeDump(uint16Blob);
@@ -1279,6 +1285,7 @@ int printBuiltinAttributes(MlirContext ctx) {
mlirAttributeDump(int64Blob);
mlirAttributeDump(floatsBlob);
mlirAttributeDump(doublesBlob);
+ mlirAttributeDump(blobBlob);
// CHECK: dense_resource<resource_ui8> : tensor<1x2xui8>
// CHECK: dense_resource<resource_ui16> : tensor<1x2xui16>
// CHECK: dense_resource<resource_ui32> : tensor<1x2xui32>
@@ -1289,6 +1296,7 @@ int printBuiltinAttributes(MlirContext ctx) {
// CHECK: dense_resource<resource_i64> : tensor<1x2xi64>
// CHECK: dense_resource<resource_f32> : tensor<1x2xf32>
// CHECK: dense_resource<resource_f64> : tensor<1x2xf64>
+ // CHECK: dense_resource<resource_i64_blob> : tensor<1x2xi64>
if (mlirDenseUInt8ResourceElementsAttrGetValue(uint8Blob, 1) != 1 ||
mlirDenseUInt16ResourceElementsAttrGetValue(uint16Blob, 1) != 1 ||
@@ -1302,7 +1310,8 @@ int printBuiltinAttributes(MlirContext ctx) {
fabsf(mlirDenseFloatResourceElementsAttrGetValue(floatsBlob, 1) - 1.0f) >
1e-6 ||
fabs(mlirDenseDoubleResourceElementsAttrGetValue(doublesBlob, 1) - 1.0f) >
- 1e-6)
+ 1e-6 ||
+ mlirDenseUInt64ResourceElementsAttrGetValue(blobBlob, 1) != 1)
return 23;
MlirLocation loc = mlirLocationUnknownGet(ctx);