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"
11#include "mlir/Dialect/GPU/IR/GPUDialect.h"
12#include "llvm/Support/Casting.h"
13
14using namespace mlir;
15
16MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(GPU, gpu, gpu::GPUDialect)
17
18//===-------------------------------------------------------------------===//
19// AsyncTokenType
20//===-------------------------------------------------------------------===//
21
22bool mlirTypeIsAGPUAsyncTokenType(MlirType type) {
23 return isa<gpu::AsyncTokenType>(Val: unwrap(c: type));
24}
25
26MlirType mlirGPUAsyncTokenTypeGet(MlirContext ctx) {
27 return wrap(cpp: gpu::AsyncTokenType::get(ctx: unwrap(c: ctx)));
28}
29
30//===---------------------------------------------------------------------===//
31// ObjectAttr
32//===---------------------------------------------------------------------===//
33
34bool mlirAttributeIsAGPUObjectAttr(MlirAttribute attr) {
35 return llvm::isa<gpu::ObjectAttr>(unwrap(attr));
36}
37
38MlirAttribute mlirGPUObjectAttrGet(MlirContext mlirCtx, MlirAttribute target,
39 uint32_t format, MlirStringRef objectStrRef,
40 MlirAttribute mlirObjectProps) {
41 MLIRContext *ctx = unwrap(c: mlirCtx);
42 llvm::StringRef object = unwrap(ref: objectStrRef);
43 DictionaryAttr objectProps;
44 if (mlirObjectProps.ptr != nullptr)
45 objectProps = llvm::cast<DictionaryAttr>(unwrap(c: mlirObjectProps));
46 return wrap(gpu::ObjectAttr::get(
47 ctx, unwrap(target), static_cast<gpu::CompilationTarget>(format),
48 StringAttr::get(ctx, object), objectProps, nullptr));
49}
50
51MlirAttribute mlirGPUObjectAttrGetWithKernels(MlirContext mlirCtx,
52 MlirAttribute target,
53 uint32_t format,
54 MlirStringRef objectStrRef,
55 MlirAttribute mlirObjectProps,
56 MlirAttribute mlirKernelsAttr) {
57 MLIRContext *ctx = unwrap(c: mlirCtx);
58 llvm::StringRef object = unwrap(ref: objectStrRef);
59 DictionaryAttr objectProps;
60 if (mlirObjectProps.ptr != nullptr)
61 objectProps = llvm::cast<DictionaryAttr>(unwrap(c: mlirObjectProps));
62 gpu::KernelTableAttr kernels;
63 if (mlirKernelsAttr.ptr != nullptr)
64 kernels = llvm::cast<gpu::KernelTableAttr>(unwrap(mlirKernelsAttr));
65 return wrap(gpu::ObjectAttr::get(
66 ctx, unwrap(target), static_cast<gpu::CompilationTarget>(format),
67 StringAttr::get(ctx, object), objectProps, kernels));
68}
69
70MlirAttribute mlirGPUObjectAttrGetTarget(MlirAttribute mlirObjectAttr) {
71 gpu::ObjectAttr objectAttr =
72 llvm::cast<gpu::ObjectAttr>(unwrap(mlirObjectAttr));
73 return wrap(objectAttr.getTarget());
74}
75
76uint32_t mlirGPUObjectAttrGetFormat(MlirAttribute mlirObjectAttr) {
77 gpu::ObjectAttr objectAttr =
78 llvm::cast<gpu::ObjectAttr>(unwrap(mlirObjectAttr));
79 return static_cast<uint32_t>(objectAttr.getFormat());
80}
81
82MlirStringRef mlirGPUObjectAttrGetObject(MlirAttribute mlirObjectAttr) {
83 gpu::ObjectAttr objectAttr =
84 llvm::cast<gpu::ObjectAttr>(unwrap(mlirObjectAttr));
85 llvm::StringRef object = objectAttr.getObject();
86 return mlirStringRefCreate(str: object.data(), length: object.size());
87}
88
89bool mlirGPUObjectAttrHasProperties(MlirAttribute mlirObjectAttr) {
90 gpu::ObjectAttr objectAttr =
91 llvm::cast<gpu::ObjectAttr>(unwrap(mlirObjectAttr));
92 return objectAttr.getProperties() != nullptr;
93}
94
95MlirAttribute mlirGPUObjectAttrGetProperties(MlirAttribute mlirObjectAttr) {
96 gpu::ObjectAttr objectAttr =
97 llvm::cast<gpu::ObjectAttr>(unwrap(mlirObjectAttr));
98 return wrap(objectAttr.getProperties());
99}
100
101bool mlirGPUObjectAttrHasKernels(MlirAttribute mlirObjectAttr) {
102 gpu::ObjectAttr objectAttr =
103 llvm::cast<gpu::ObjectAttr>(unwrap(mlirObjectAttr));
104 return objectAttr.getKernels() != nullptr;
105}
106
107MlirAttribute mlirGPUObjectAttrGetKernels(MlirAttribute mlirObjectAttr) {
108 gpu::ObjectAttr objectAttr =
109 llvm::cast<gpu::ObjectAttr>(unwrap(mlirObjectAttr));
110 return wrap(objectAttr.getKernels());
111}
112

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of mlir/lib/CAPI/Dialect/GPU.cpp