-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mlir][python] Add basic python support for GPU dialect and passes
Differential Revision: https://reviews.llvm.org/D101449
- Loading branch information
1 parent
e7db840
commit b87219f
Showing
11 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//===-- mlir-c/Dialect/GPU.h - C API for GPU dialect -------------*- C -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM | ||
// Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===---------------------------------------------------------------------===// | ||
|
||
#ifndef MLIR_C_DIALECT_GPU_H | ||
#define MLIR_C_DIALECT_GPU_H | ||
|
||
#include "mlir-c/Registration.h" | ||
#include "mlir-c/Support.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(GPU, gpu); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#include "mlir/Dialect/GPU/Passes.capi.h.inc" | ||
|
||
#endif // MLIR_C_DIALECT_GPU_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//===-- GPUOps.td - Entry point GPU_dialect bindings ------*- tablegen -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===---------------------------------------------------------------------===// | ||
|
||
#ifndef PYTHON_BINDINGS_GPU_OPS | ||
#define PYTHON_BINDINGS_GPU_OPS | ||
|
||
include "mlir/Bindings/Python/Attributes.td" | ||
include "mlir/Dialect/GPU/GPUOps.td" | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//===- GPUPasses.cpp - Pybind module for the GPU passes ------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===---------------------------------------------------------------------===// | ||
|
||
#include "mlir-c/Dialect/GPU.h" | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
// ----------------------------------------------------------------------------- | ||
// Module initialization. | ||
// ----------------------------------------------------------------------------- | ||
|
||
PYBIND11_MODULE(_mlirGPUPasses, m) { | ||
m.doc() = "MLIR GPU Dialect Passes"; | ||
|
||
// Register all GPU passes on load. | ||
mlirRegisterGPUPasses(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
from .._gpu_ops_gen import * |
6 changes: 6 additions & 0 deletions
6
mlir/lib/Bindings/Python/mlir/dialects/gpu/passes/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
from ...._cext_loader import _load_extension | ||
_cextGPUPasses = _load_extension("_mlirGPUPasses") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//===- GPUc.cpp - C Interface for GPU dialect ----------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "mlir-c/Dialect/GPU.h" | ||
#include "mlir/CAPI/Registration.h" | ||
#include "mlir/Dialect/GPU/GPUDialect.h" | ||
|
||
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(GPU, gpu, mlir::gpu::GPUDialect) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//===- GPUPasses.cpp - C API for GPU Dialect Passes ----------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "mlir/CAPI/Pass.h" | ||
#include "mlir/Dialect/GPU/Passes.h" | ||
#include "mlir/Pass/Pass.h" | ||
|
||
// Must include the declarations as they carry important visibility attributes. | ||
#include "mlir/Dialect/GPU/Passes.capi.h.inc" | ||
|
||
using namespace mlir; | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include "mlir/Dialect/GPU/Passes.capi.cpp.inc" | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# RUN: %PYTHON %s | FileCheck %s | ||
|
||
from mlir.ir import * | ||
import mlir.dialects.gpu | ||
import mlir.dialects.gpu.passes | ||
from mlir.passmanager import * | ||
|
||
def run(f): | ||
print("\nTEST:", f.__name__) | ||
f() | ||
|
||
def testGPUPass(): | ||
with Context() as context: | ||
PassManager.parse('gpu-kernel-outlining') | ||
print('SUCCESS') | ||
|
||
# CHECK-LABEL: testGPUPass | ||
# CHECK: SUCCESS | ||
run(testGPUPass) |