1 /* Copyright 2021 The TensorFlow Authors. All Rights Reserved. 2 Licensed under the Apache License, Version 2.0 (the "License"); 3 you may not use this file except in compliance with the License. 4 You may obtain a copy of the License at 5 http://www.apache.org/licenses/LICENSE-2.0 6 Unless required by applicable law or agreed to in writing, software 7 distributed under the License is distributed on an "AS IS" BASIS, 8 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 See the License for the specific language governing permissions and 10 limitations under the License. 11 ==============================================================================*/ 12 #ifndef MLIR_HLO_C_ATTRIBUTES_H 13 #define MLIR_HLO_C_ATTRIBUTES_H 14 15 #include <sys/types.h> 16 17 #include "mlir-c/IR.h" 18 #include "mlir-c/Support.h" 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 // Creates a new ScatterDimensionNumbers attribute with the given parameters. 25 // The first three pairs of arguments are interpreted as arrays. 26 MLIR_CAPI_EXPORTED MlirAttribute mlirMhloScatterDimensionNumbersGet( 27 MlirContext ctx, // 28 intptr_t nUpdateWindowDims, const int64_t *updateWindowDims, // 29 intptr_t nInsertedWindowDims, const int64_t *insertedWindowDims, // 30 intptr_t nScatteredDimsToOperandDims, // 31 const int64_t *scatteredDimsToOperandDims, // 32 int64_t indexVectorDim); 33 34 // Returns true if the given attribute is a ScatterDimenionNumbers attribute. 35 MLIR_CAPI_EXPORTED bool mlirMhloAttributeIsAScatterDimensionNumbers( 36 MlirAttribute attr); 37 38 // Returns the properties of ScatterDimensionNumbers attributes. 39 MLIR_CAPI_EXPORTED intptr_t 40 mlirMhloScatterDimensionNumbersGetUpdateWindowDimsSize(MlirAttribute attr); 41 MLIR_CAPI_EXPORTED int64_t 42 mlirMhloScatterDimensionNumbersGetUpdateWindowDimsElem(MlirAttribute attr, 43 intptr_t pos); 44 MLIR_CAPI_EXPORTED intptr_t 45 mlirMhloScatterDimensionNumbersGetInsertedWindowDimsSize(MlirAttribute attr); 46 MLIR_CAPI_EXPORTED int64_t 47 mlirMhloScatterDimensionNumbersGetInsertedWindowDimsElem(MlirAttribute attr, 48 intptr_t pos); 49 MLIR_CAPI_EXPORTED intptr_t 50 mlirMhloScatterDimensionNumbersGetScatteredDimsToOperandDimsSize( 51 MlirAttribute attr); 52 MLIR_CAPI_EXPORTED int64_t 53 mlirMhloScatterDimensionNumbersGetScatteredDimsToOperandDimsElem( 54 MlirAttribute attr, intptr_t pos); 55 MLIR_CAPI_EXPORTED int64_t 56 mlirMhloDimensionNumbersGetIndexVectorDim(MlirAttribute attr); 57 58 // Creates a new GatherDimensionNumbers attribute with the given parameters. The 59 // first three pairs of arguments are interpreted as arrays. 60 MLIR_CAPI_EXPORTED MlirAttribute mlirMhloGatherDimensionNumbersGet( 61 MlirContext ctx, intptr_t nOffsetDims, const int64_t *offsetDims, 62 intptr_t nCollapsedSliceDims, const int64_t *collapsedSliceDims, 63 intptr_t nStartIndexMap, const int64_t *startIndexMap, 64 int64_t indexVectorDim); 65 66 // Returns true if the given attribute is a GatherDimensionNumbers attribute. 67 MLIR_CAPI_EXPORTED bool mlirMhloAttributeIsAGatherDimensionNumbers( 68 MlirAttribute attr); 69 70 // Returns the properties of GatherDimensionNumbers attributes. 71 MLIR_CAPI_EXPORTED intptr_t 72 mlirMhloGatherDimensionNumbersGetOffsetDimsSize(MlirAttribute attr); 73 MLIR_CAPI_EXPORTED int64_t mlirMhloGatherDimensionNumbersGetOffsetDimsElem( 74 MlirAttribute attr, intptr_t pos); 75 MLIR_CAPI_EXPORTED intptr_t 76 mlirMhloGatherDimensionNumbersGetCollapsedSliceDimsSize(MlirAttribute attr); 77 MLIR_CAPI_EXPORTED int64_t 78 mlirMhloGatherDimensionNumbersGetCollapsedSliceDimsElem(MlirAttribute attr, 79 intptr_t pos); 80 MLIR_CAPI_EXPORTED intptr_t 81 mlirMhloGatherDimensionNumbersGetStartIndexMapSize(MlirAttribute attr); 82 MLIR_CAPI_EXPORTED int64_t mlirMhloGatherDimensionNumbersGetStartIndexMapElem( 83 MlirAttribute attr, intptr_t pos); 84 MLIR_CAPI_EXPORTED int64_t 85 mlirMhloGatherDimensionNumbersGetIndexVectorDim(MlirAttribute attr); 86 87 // Creates a new DotDimensionNumbers attribute with the given parameters. The 88 // argument pairs are interpreted as arrays with the leading argument being the 89 // number of elements and the trailing argument being the pointer to the first 90 // element of the array. 91 MLIR_CAPI_EXPORTED MlirAttribute mlirMhloDotDimensionNumbersGet( 92 MlirContext ctx, // 93 intptr_t nLhsBatchingDimensions, const int64_t *lhsBatchingDimensions, // 94 intptr_t nRhsBatchingDimensions, const int64_t *rhsBatchingDimensions, // 95 intptr_t nLhsContractingDimensions, // 96 const int64_t *lhsContractingDimensions, // 97 intptr_t nRhsContractingDimensions, // 98 const int64_t *rhsContractingDimensions); 99 100 // Returns true of the given attribute is a DotDimensionNumbers attribute. 101 MLIR_CAPI_EXPORTED bool mlirMhloAttributeIsADotDimensionNumbers( 102 MlirAttribute attr); 103 104 // Returns the properties of DotDimensionNumbers attributes. 105 MLIR_CAPI_EXPORTED intptr_t 106 mlirMhloDotDimensionNumbersGetLhsBatchingDimensionsSize(MlirAttribute attr); 107 MLIR_CAPI_EXPORTED int64_t 108 mlirMhloDotDimensionNumbersGetLhsBatchingDimensionsElem(MlirAttribute attr, 109 intptr_t pos); 110 MLIR_CAPI_EXPORTED intptr_t 111 mlirMhloDotDimensionNumbersGetRhsBatchingDimensionsSize(MlirAttribute attr); 112 MLIR_CAPI_EXPORTED int64_t 113 mlirMhloDotDimensionNumbersGetRhsBatchingDimensionsElem(MlirAttribute attr, 114 intptr_t pos); 115 MLIR_CAPI_EXPORTED intptr_t 116 mlirMhloDotDimensionNumbersGetLhsContractingDimensionsSize(MlirAttribute attr); 117 MLIR_CAPI_EXPORTED int64_t 118 mlirMhloDotDimensionNumbersGetLhsContractingDimensionsElem(MlirAttribute attr, 119 intptr_t pos); 120 MLIR_CAPI_EXPORTED intptr_t 121 mlirMhloDotDimensionNumbersGetRhsContractingDimensionsSize(MlirAttribute attr); 122 MLIR_CAPI_EXPORTED int64_t 123 mlirMhloDotDimensionNumbersGetRhsContractingDimensionsElem(MlirAttribute attr, 124 intptr_t pos); 125 126 // Creates a new ConvDimensionNumbers attribute with the given parameters. The 127 // pairs of consecutive intptr_t / int64_t* arguments are interpeted as sized 128 // arrays. 129 MLIR_CAPI_EXPORTED MlirAttribute mlirMhloConvDimensionNumbersGet( 130 MlirContext ctx, int64_t inputBatchDimension, int64_t inputFeatureDimension, 131 intptr_t nInputSpatialDimensions, const int64_t *inputSpatialDimensions, 132 int64_t kernelInputFeatureDimension, int64_t kernelOutputFeatureDimension, 133 intptr_t nKernelSpatialDimensions, const int64_t *kernelSpatialDimensions, 134 int64_t outputBatchDimension, int64_t outputFeatureDimension, 135 intptr_t nOutputSpatialDimensions, const int64_t *outputSpatialDimensions); 136 137 // Returns true of the given attribute is a ConvDimensionNumbers attribute. 138 MLIR_CAPI_EXPORTED bool mlirMhloAttributeIsAConvDimensionNumbers( 139 MlirAttribute attr); 140 141 // Returns the properties of ConvDimensionNumbers attributes. 142 MLIR_CAPI_EXPORTED int64_t 143 mlirMhloConvDimensionNumbersGetInputBatchDimension(MlirAttribute attr); 144 MLIR_CAPI_EXPORTED int64_t 145 mlirMhloConvDimensionNumbersGetInputFeatureDimension(MlirAttribute attr); 146 147 MLIR_CAPI_EXPORTED intptr_t 148 mlirMhloConvDimensionNumbersGetInputSpatialDimensionsSize(MlirAttribute attr); 149 MLIR_CAPI_EXPORTED int64_t 150 mlirMhloConvDimensionNumbersGetInputSpatialDimensionsElem(MlirAttribute attr, 151 intptr_t pos); 152 MLIR_CAPI_EXPORTED int64_t 153 mlirMhloConvDimensionNumbersGetKernelInputFeatureDimension(MlirAttribute attr); 154 MLIR_CAPI_EXPORTED int64_t 155 mlirMhloConvDimensionNumbersGetKernelOutputFeatureDimension(MlirAttribute attr); 156 MLIR_CAPI_EXPORTED intptr_t 157 mlirMhloConvDimensionNumbersGetKernelSpatialDimensionsSize(MlirAttribute attr); 158 MLIR_CAPI_EXPORTED int64_t 159 mlirMhloConvDimensionNumbersGetKernelSpatialDimensionsElem(MlirAttribute attr, 160 intptr_t pos); 161 MLIR_CAPI_EXPORTED int64_t 162 mlirMhloConvDimensionNumbersGetOutputBatchDimension(MlirAttribute attr); 163 MLIR_CAPI_EXPORTED int64_t 164 mlirMhloConvDimensionNumbersGetOutputFeatureDimension(MlirAttribute attr); 165 MLIR_CAPI_EXPORTED intptr_t 166 mlirMhloConvDimensionNumbersGetOutputSpatialDimensionsSize(MlirAttribute attr); 167 MLIR_CAPI_EXPORTED int64_t 168 mlirMhloConvDimensionNumbersGetOutputSpatialDimensionsElem(MlirAttribute attr, 169 intptr_t pos); 170 171 // 172 // ComparisonDirectionAttr. 173 // 174 // Creates a new ComparisonDirection attribute with the given 175 // 'direction' string parameter. 176 MLIR_CAPI_EXPORTED MlirAttribute 177 mlirMhloComparisonDirectionAttrGet(MlirContext ctx, MlirStringRef direction); 178 179 // Returns true if the given attribute is a ComparisonDirection attribute. 180 MLIR_CAPI_EXPORTED bool mlirMhloAttributeIsAComparisonDirectionAttr( 181 MlirAttribute attr); 182 183 // Returns the direction string associated with ComparisonDirection attribute. 184 MLIR_CAPI_EXPORTED MlirStringRef 185 mlirMhloComparisonDirectionAttrGetDirection(MlirAttribute attr); 186 187 // 188 // ComparisonTypeAttr. 189 // 190 // Creates a new ComparisonType attribute with the given 'type' string 191 // parameter. 192 MLIR_CAPI_EXPORTED MlirAttribute 193 mlirMhloComparisonTypeAttrGet(MlirContext ctx, MlirStringRef type); 194 195 // Returns true if the given attribute is a ComparisonType attribute. 196 MLIR_CAPI_EXPORTED bool mlirMhloAttributeIsAComparisonTypeAttr( 197 MlirAttribute attr); 198 199 // Returns the type string associated with ComparisonType attribute. 200 MLIR_CAPI_EXPORTED MlirStringRef 201 mlirMhloComparisonTypeAttrGetType(MlirAttribute attr); 202 203 // 204 // DomainKindAttr. 205 // 206 // Creates a new DomainKind attribute with the given 'kind' string 207 // parameter. 208 MLIR_CAPI_EXPORTED MlirAttribute mlirMhloDomainKindAttrGet(MlirContext ctx, 209 MlirStringRef kind); 210 211 // Returns true if the given attribute is a DomainKind attribute. 212 MLIR_CAPI_EXPORTED bool mlirMhloAttributeIsADomainKindAttr(MlirAttribute attr); 213 214 // Returns the type string associated with DomainKind attribute. 215 MLIR_CAPI_EXPORTED MlirStringRef 216 mlirMhloDomainKindAttrGetType(MlirAttribute attr); 217 218 // 219 // PrecisionAttr. 220 // 221 // Creates a new Precision attribute with the given 'type' string 222 // parameter. 223 MLIR_CAPI_EXPORTED MlirAttribute mlirMhloPrecisionAttrGet(MlirContext ctx, 224 MlirStringRef type); 225 226 // Returns true if the given attribute is a Precision attribute. 227 MLIR_CAPI_EXPORTED bool mlirMhloAttributeIsAPrecisionAttr(MlirAttribute attr); 228 229 // Returns the type string associated with Precision attribute. 230 MLIR_CAPI_EXPORTED MlirStringRef 231 mlirMhloPrecisionAttrGetPrecision(MlirAttribute attr); 232 233 // 234 // FftTypeAttr. 235 // 236 // Creates a new FftType attribute with the given 'type' string parameter. 237 MLIR_CAPI_EXPORTED MlirAttribute mlirMhloFftTypeAttrGet(MlirContext ctx, 238 MlirStringRef type); 239 240 // Returns true if the given attribute is a FftType attribute. 241 MLIR_CAPI_EXPORTED bool mlirMhloAttributeIsAFftTypeAttr(MlirAttribute attr); 242 243 // Returns the type string associated with FftType attribute. 244 MLIR_CAPI_EXPORTED MlirStringRef 245 mlirMhloFftTypeAttrGetFftType(MlirAttribute attr); 246 247 // 248 // DequantizeModeAttr. 249 // 250 // Creates a new DequantizeMode attribute with the given 'mode' string 251 // parameter. 252 MLIR_CAPI_EXPORTED MlirAttribute 253 mlirMhloDequantizeModeAttrGet(MlirContext ctx, MlirStringRef mode); 254 255 // Returns true if the given attribute is a DequantizeMode attribute. 256 MLIR_CAPI_EXPORTED bool mlirMhloAttributeIsADequantizeModeAttr( 257 MlirAttribute attr); 258 259 // Returns the mode string associated with DequantizeMode attribute. 260 MLIR_CAPI_EXPORTED MlirStringRef 261 mlirMhloDequantizeModeAttrGetDequantizeMode(MlirAttribute attr); 262 263 // 264 // TransposeAttr. 265 // 266 // Creates a new Transpose attribute with the given 'type' string parameter. 267 MLIR_CAPI_EXPORTED MlirAttribute mlirMhloTransposeAttrGet(MlirContext ctx, 268 MlirStringRef type); 269 270 // Returns true if the given attribute is a Transpose attribute. 271 MLIR_CAPI_EXPORTED bool mlirMhloAttributeIsATransposeAttr(MlirAttribute attr); 272 273 // Returns the type string associated with Transpose attribute. 274 MLIR_CAPI_EXPORTED MlirStringRef 275 mlirMhloTransposeAttrGetTranspose(MlirAttribute attr); 276 277 // 278 // FusionKindAttr. 279 // 280 // Creates a new FusionKind attribute with the given 'kind' string parameter. 281 MLIR_CAPI_EXPORTED MlirAttribute mlirMhloFusionKindAttrGet(MlirContext ctx, 282 MlirStringRef kind); 283 284 // Returns true if the given attribute is a FusionKind attribute. 285 MLIR_CAPI_EXPORTED bool mlirMhloAttributeIsAFusionKindAttr(MlirAttribute attr); 286 287 // Returns the fusion-kind string associated with FusionKind attribute. 288 MLIR_CAPI_EXPORTED MlirStringRef 289 mlirMhloFusionKindAttrGetFusionKind(MlirAttribute attr); 290 291 // 292 // RngDistributionAttr. 293 // 294 // Creates a new RngDistribution attribute with the given 'distribution' string 295 // parameter. 296 MLIR_CAPI_EXPORTED MlirAttribute 297 mlirMhloRngDistributionAttrGet(MlirContext ctx, MlirStringRef distribution); 298 299 // Returns true if the given attribute is a RngDistribution attribute. 300 MLIR_CAPI_EXPORTED bool mlirMhloAttributeIsARngDistributionAttr( 301 MlirAttribute attr); 302 303 // Returns the rng-distribution string associated with RngDistribution 304 // attribute. 305 MLIR_CAPI_EXPORTED MlirStringRef 306 mlirMhloRngDistributionAttrGetRngDistribution(MlirAttribute attr); 307 308 // 309 // RngAlgorithmAttr. 310 // 311 // Creates a new RngAlgorithm attribute with the given 'algorithm' string 312 // parameter. 313 MLIR_CAPI_EXPORTED MlirAttribute 314 mlirMhloRngAlgorithmAttrGet(MlirContext ctx, MlirStringRef algorithm); 315 316 // Returns true if the given attribute is a RngAlgorithm attribute. 317 MLIR_CAPI_EXPORTED bool mlirMhloAttributeIsARngAlgorithmAttr( 318 MlirAttribute attr); 319 320 // Returns the rng-algorithm string associated with RngAlgorithm attribute. 321 MLIR_CAPI_EXPORTED MlirStringRef 322 mlirMhloRngAlgorithmAttrGetRngAlgorithm(MlirAttribute attr); 323 324 // 325 // ChannelHandle 326 // 327 // Creates a new ChannelHandle attribute with the given 'handle' int64_t 328 // parameter and the given 'type' int64_t parameter. 329 MLIR_CAPI_EXPORTED MlirAttribute mlirMhloChannelHandleGet(MlirContext ctx, 330 int64_t handle, 331 int64_t type); 332 333 // Returns true if the given attribute is a ChannelHandle attribute. 334 MLIR_CAPI_EXPORTED bool mlirMhloAttributeIsChannelHandle(MlirAttribute attr); 335 336 // Returns the handle integer associated with the ChannelHandle attribute. 337 MLIR_CAPI_EXPORTED int64_t mlirMhloChannelHandleGetHandle(MlirAttribute attr); 338 339 // Returns the type integer associated with the ChannelHandle attribute. 340 MLIR_CAPI_EXPORTED int64_t mlirMhloChannelHandleGetType(MlirAttribute attr); 341 342 // 343 // TypeExtensions 344 // 345 // Creates a new TypeExtensions attribute with the given 'bounds' which 346 // is interpreted as an array. 347 MLIR_CAPI_EXPORTED MlirAttribute mlirMhloTypeExtensionsGet( 348 MlirContext ctx, intptr_t nBounds, const int64_t *bounds); 349 350 // Returns true if the given attribute is a TypeExtensions attribute. 351 MLIR_CAPI_EXPORTED bool mlirMhloAttributeIsTypeExtensions(MlirAttribute attr); 352 353 // Returns the size and the elements of the bounds associated with the 354 // TypeExtensions attributes. 355 MLIR_CAPI_EXPORTED intptr_t 356 mlirMhloTypeExtensionsGetBoundsSize(MlirAttribute attr); 357 MLIR_CAPI_EXPORTED int64_t 358 mlirMhloTypeExtensionsGetBoundsElem(MlirAttribute attr, intptr_t pos); 359 360 #ifdef __cplusplus 361 } 362 #endif 363 364 #endif // MLIR_HLO_C_ATTRIBUTES_H 365