MLIR  19.0.0git
GPU.cpp
Go to the documentation of this file.
1 //===- GPU.cpp - C Interface for GPU dialect ------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "mlir-c/Dialect/GPU.h"
10 #include "mlir/CAPI/Registration.h"
12 #include "llvm/Support/Casting.h"
13 
14 using namespace mlir;
15 
16 MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(GPU, gpu, gpu::GPUDialect)
17 
18 //===---------------------------------------------------------------------===//
19 // ObjectAttr
20 //===---------------------------------------------------------------------===//
21 
22 bool mlirAttributeIsAGPUObjectAttr(MlirAttribute attr) {
23  return llvm::isa<gpu::ObjectAttr>(unwrap(attr));
24 }
25 
26 MlirAttribute mlirGPUObjectAttrGet(MlirContext mlirCtx, MlirAttribute target,
27  uint32_t format, MlirStringRef objectStrRef,
28  MlirAttribute mlirObjectProps) {
29  MLIRContext *ctx = unwrap(mlirCtx);
30  llvm::StringRef object = unwrap(objectStrRef);
31  DictionaryAttr objectProps;
32  if (mlirObjectProps.ptr != nullptr)
33  objectProps = llvm::cast<DictionaryAttr>(unwrap(mlirObjectProps));
34  return wrap(gpu::ObjectAttr::get(ctx, unwrap(target),
35  static_cast<gpu::CompilationTarget>(format),
36  StringAttr::get(ctx, object), objectProps));
37 }
38 
39 MlirAttribute mlirGPUObjectAttrGetTarget(MlirAttribute mlirObjectAttr) {
40  gpu::ObjectAttr objectAttr =
41  llvm::cast<gpu::ObjectAttr>(unwrap(mlirObjectAttr));
42  return wrap(objectAttr.getTarget());
43 }
44 
45 uint32_t mlirGPUObjectAttrGetFormat(MlirAttribute mlirObjectAttr) {
46  gpu::ObjectAttr objectAttr =
47  llvm::cast<gpu::ObjectAttr>(unwrap(mlirObjectAttr));
48  return static_cast<uint32_t>(objectAttr.getFormat());
49 }
50 
51 MlirStringRef mlirGPUObjectAttrGetObject(MlirAttribute mlirObjectAttr) {
52  gpu::ObjectAttr objectAttr =
53  llvm::cast<gpu::ObjectAttr>(unwrap(mlirObjectAttr));
54  llvm::StringRef object = objectAttr.getObject();
55  return mlirStringRefCreate(object.data(), object.size());
56 }
57 
58 bool mlirGPUObjectAttrHasProperties(MlirAttribute mlirObjectAttr) {
59  gpu::ObjectAttr objectAttr =
60  llvm::cast<gpu::ObjectAttr>(unwrap(mlirObjectAttr));
61  return objectAttr.getProperties() != nullptr;
62 }
63 
64 MlirAttribute mlirGPUObjectAttrGetProperties(MlirAttribute mlirObjectAttr) {
65  gpu::ObjectAttr objectAttr =
66  llvm::cast<gpu::ObjectAttr>(unwrap(mlirObjectAttr));
67  return wrap(objectAttr.getProperties());
68 }
MlirAttribute mlirGPUObjectAttrGetProperties(MlirAttribute mlirObjectAttr)
Definition: GPU.cpp:64
MlirAttribute mlirGPUObjectAttrGetTarget(MlirAttribute mlirObjectAttr)
Definition: GPU.cpp:39
bool mlirAttributeIsAGPUObjectAttr(MlirAttribute attr)
Definition: GPU.cpp:22
MlirAttribute mlirGPUObjectAttrGet(MlirContext mlirCtx, MlirAttribute target, uint32_t format, MlirStringRef objectStrRef, MlirAttribute mlirObjectProps)
Definition: GPU.cpp:26
uint32_t mlirGPUObjectAttrGetFormat(MlirAttribute mlirObjectAttr)
Definition: GPU.cpp:45
bool mlirGPUObjectAttrHasProperties(MlirAttribute mlirObjectAttr)
Definition: GPU.cpp:58
MlirStringRef mlirGPUObjectAttrGetObject(MlirAttribute mlirObjectAttr)
Definition: GPU.cpp:51
#define MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Name, Namespace, ClassName)
Definition: Registration.h:36
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:60
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
Definition: Diagnostics.h:19
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
Definition: Diagnostics.h:24
static MlirStringRef mlirStringRefCreate(const char *str, size_t length)
Constructs a string reference from the pointer and length.
Definition: Support.h:82
Include the generated interface declarations.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition: Support.h:73