[llvm] [libcxx] [flang] [clang] [lldb] [clang-tools-extra] [mlir] [lld] [openmp] [compiler-rt] [libc] [MLIR] Enabling Intel GPU Integration. (PR #65539)

2023-12-15 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 closed https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [lldb] [libcxx] [llvm] [clang-tools-extra] [lld] [libc] [mlir] [openmp] [flang] [clang] [MLIR] Enabling Intel GPU Integration. (PR #65539)

2023-12-15 Thread Sang Ik Lee via cfe-commits

silee2 wrote:

Closing as all sub-components has been merged.

https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [llvm] [lldb] [openmp] [lld] [libc] [flang] [mlir] [libcxx] [clang] [compiler-rt] [MLIR] Enable GPU Dialect to SYCL runtime integration (PR #71430)

2023-12-05 Thread Sang Ik Lee via cfe-commits


@@ -61,6 +63,7 @@ registerAllGPUToLLVMIRTranslations(DialectRegistry ) 
{
   registerLLVMDialectTranslation(registry);
   registerNVVMDialectTranslation(registry);
   registerROCDLDialectTranslation(registry);
+  registerSPIRVDialectTranslation(registry);

silee2 wrote:

@fabianmcg Added test.
Any other request? The PR has been open for a while and blocking other work 
that depends on it. Would be great if you can approve soon.

https://github.com/llvm/llvm-project/pull/71430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lld] [llvm] [lldb] [libc] [clang] [openmp] [clang-tools-extra] [flang] [compiler-rt] [libcxx] [mlir] [MLIR] Enable GPU Dialect to SYCL runtime integration (PR #71430)

2023-12-05 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 updated 
https://github.com/llvm/llvm-project/pull/71430

>From c76403cf8629b8f7d8a5b7a3ee5da2881713a7f8 Mon Sep 17 00:00:00 2001
From: "Lee, Sang Ik" 
Date: Mon, 6 Nov 2023 18:47:23 +
Subject: [PATCH 1/6] [MLIR] Enable GPU Dialect to SYCL runtime integration

GPU Dialect lowering to SYCL runtime is driven by spirv.target_env
attached to gpu.module. As a result of this, spirv.target_env remains
as an input to LLVMIR Translation.
A SPIRVToLLVMIRTranslation without any actual translation is added to
avoid an unregistered error in mlir-cpu-runner.
SelectObjectAttr.cpp is updated to
1) Pass binary size argument to getModuleLoadFn
2) Pass parameter count to getKernelLaunchFn
This change does not impact CUDA and ROCM usage since both
mlir_cuda_runtime and mlir_rocm_runtime are already updated to
accept and ignore the extra arguments.
---
 mlir/include/mlir/Target/LLVMIR/Dialect/All.h |  3 ++
 .../Dialect/SPIRV/SPIRVToLLVMIRTranslation.h  | 31 +++
 mlir/lib/Target/LLVMIR/CMakeLists.txt |  1 +
 mlir/lib/Target/LLVMIR/Dialect/CMakeLists.txt |  1 +
 .../LLVMIR/Dialect/GPU/SelectObjectAttr.cpp   | 50 +
 .../LLVMIR/Dialect/SPIRV/CMakeLists.txt   | 13 +
 .../SPIRV/SPIRVToLLVMIRTranslation.cpp| 31 +++
 mlir/test/CMakeLists.txt  |  4 ++
 .../Integration/GPU/SYCL/gpu-to-spirv.mlir| 54 +++
 mlir/test/Integration/GPU/SYCL/lit.local.cfg  |  2 +
 mlir/test/Target/LLVMIR/gpu.mlir  |  9 ++--
 mlir/test/lit.cfg.py  |  3 ++
 mlir/test/lit.site.cfg.py.in  |  1 +
 13 files changed, 188 insertions(+), 15 deletions(-)
 create mode 100644 
mlir/include/mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h
 create mode 100644 mlir/lib/Target/LLVMIR/Dialect/SPIRV/CMakeLists.txt
 create mode 100644 
mlir/lib/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.cpp
 create mode 100644 mlir/test/Integration/GPU/SYCL/gpu-to-spirv.mlir
 create mode 100644 mlir/test/Integration/GPU/SYCL/lit.local.cfg

diff --git a/mlir/include/mlir/Target/LLVMIR/Dialect/All.h 
b/mlir/include/mlir/Target/LLVMIR/Dialect/All.h
index 0563b9bf3d475..5dfc15afb7593 100644
--- a/mlir/include/mlir/Target/LLVMIR/Dialect/All.h
+++ b/mlir/include/mlir/Target/LLVMIR/Dialect/All.h
@@ -26,6 +26,7 @@
 #include "mlir/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.h"
 #include "mlir/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.h"
 #include "mlir/Target/LLVMIR/Dialect/ROCDL/ROCDLToLLVMIRTranslation.h"
+#include "mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h"
 #include "mlir/Target/LLVMIR/Dialect/X86Vector/X86VectorToLLVMIRTranslation.h"
 
 namespace mlir {
@@ -45,6 +46,7 @@ static inline void 
registerAllToLLVMIRTranslations(DialectRegistry ) {
   registerOpenACCDialectTranslation(registry);
   registerOpenMPDialectTranslation(registry);
   registerROCDLDialectTranslation(registry);
+  registerSPIRVDialectTranslation(registry);
   registerX86VectorDialectTranslation(registry);
 
   // Extension required for translating GPU offloading Ops.
@@ -61,6 +63,7 @@ registerAllGPUToLLVMIRTranslations(DialectRegistry ) 
{
   registerLLVMDialectTranslation(registry);
   registerNVVMDialectTranslation(registry);
   registerROCDLDialectTranslation(registry);
+  registerSPIRVDialectTranslation(registry);
 
   // Extension required for translating GPU offloading Ops.
   gpu::registerOffloadingLLVMTranslationInterfaceExternalModels(registry);
diff --git 
a/mlir/include/mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h 
b/mlir/include/mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h
new file mode 100644
index 0..e9580a10b4ca7
--- /dev/null
+++ b/mlir/include/mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h
@@ -0,0 +1,31 @@
+//===- SPIRVToLLVMIRTranslation.h - SPIRV to LLVM IR *- 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
+//
+//===--===//
+//
+// This provides registration calls for SPIRV dialect to LLVM IR translation.
+//
+//===--===//
+
+#ifndef MLIR_TARGET_LLVMIR_DIALECT_SPIRV_SPIRVTOLLVMIRTRANSLATION_H
+#define MLIR_TARGET_LLVMIR_DIALECT_SPIRV_SPIRVTOLLVMIRTRANSLATION_H
+
+namespace mlir {
+
+class DialectRegistry;
+class MLIRContext;
+
+/// Register the SPIRV dialect and the translation from it to the LLVM IR in 
the
+/// given registry;
+void registerSPIRVDialectTranslation(DialectRegistry );
+
+/// Register the SPIRV dialect and the translation from it in the registry
+/// associated with the given context.
+void registerSPIRVDialectTranslation(MLIRContext );
+
+} // namespace mlir
+
+#endif // 

[libcxx] [lld] [clang] [flang] [clang-tools-extra] [llvm] [libc] [compiler-rt] [mlir] [openmp] [lldb] [MLIR] Enable GPU Dialect to SYCL runtime integration (PR #71430)

2023-12-05 Thread Sang Ik Lee via cfe-commits

silee2 wrote:

@fabianmcg Can you approve and merge? @joker-eph is not responding and this PR 
has been open for a long time.
It is blocking other future PRs that depend on this one.
If SPIR-V dialect registration needs to change that can be done in another PR.

https://github.com/llvm/llvm-project/pull/71430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lld] [lldb] [openmp] [libcxx] [mlir] [compiler-rt] [flang] [llvm] [clang-tools-extra] [libc] [clang] [MLIR] Enable GPU Dialect to SYCL runtime integration (PR #71430)

2023-11-28 Thread Sang Ik Lee via cfe-commits


@@ -0,0 +1,31 @@
+//===- SPIRVToLLVMIRTranslation.cpp - Translate SPIRV to LLVM IR 
--===//
+//
+// 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
+//
+//===--===//
+//
+// This file implements a translation between the MLIR SPIRV dialect and
+// LLVM IR.
+//
+//===--===//
+
+#include "mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
+#include "mlir/IR/BuiltinAttributes.h"
+#include "mlir/IR/Operation.h"
+#include "mlir/Target/LLVMIR/ModuleTranslation.h"
+
+using namespace mlir;
+using namespace mlir::LLVM;
+
+void mlir::registerSPIRVDialectTranslation(DialectRegistry ) {
+  registry.insert();

silee2 wrote:

@joker-eph 

https://github.com/llvm/llvm-project/pull/71430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lld] [lldb] [openmp] [libcxx] [mlir] [compiler-rt] [flang] [llvm] [clang-tools-extra] [libc] [clang] [MLIR] Enable GPU Dialect to SYCL runtime integration (PR #71430)

2023-11-28 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 updated 
https://github.com/llvm/llvm-project/pull/71430

>From c76403cf8629b8f7d8a5b7a3ee5da2881713a7f8 Mon Sep 17 00:00:00 2001
From: "Lee, Sang Ik" 
Date: Mon, 6 Nov 2023 18:47:23 +
Subject: [PATCH 1/5] [MLIR] Enable GPU Dialect to SYCL runtime integration

GPU Dialect lowering to SYCL runtime is driven by spirv.target_env
attached to gpu.module. As a result of this, spirv.target_env remains
as an input to LLVMIR Translation.
A SPIRVToLLVMIRTranslation without any actual translation is added to
avoid an unregistered error in mlir-cpu-runner.
SelectObjectAttr.cpp is updated to
1) Pass binary size argument to getModuleLoadFn
2) Pass parameter count to getKernelLaunchFn
This change does not impact CUDA and ROCM usage since both
mlir_cuda_runtime and mlir_rocm_runtime are already updated to
accept and ignore the extra arguments.
---
 mlir/include/mlir/Target/LLVMIR/Dialect/All.h |  3 ++
 .../Dialect/SPIRV/SPIRVToLLVMIRTranslation.h  | 31 +++
 mlir/lib/Target/LLVMIR/CMakeLists.txt |  1 +
 mlir/lib/Target/LLVMIR/Dialect/CMakeLists.txt |  1 +
 .../LLVMIR/Dialect/GPU/SelectObjectAttr.cpp   | 50 +
 .../LLVMIR/Dialect/SPIRV/CMakeLists.txt   | 13 +
 .../SPIRV/SPIRVToLLVMIRTranslation.cpp| 31 +++
 mlir/test/CMakeLists.txt  |  4 ++
 .../Integration/GPU/SYCL/gpu-to-spirv.mlir| 54 +++
 mlir/test/Integration/GPU/SYCL/lit.local.cfg  |  2 +
 mlir/test/Target/LLVMIR/gpu.mlir  |  9 ++--
 mlir/test/lit.cfg.py  |  3 ++
 mlir/test/lit.site.cfg.py.in  |  1 +
 13 files changed, 188 insertions(+), 15 deletions(-)
 create mode 100644 
mlir/include/mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h
 create mode 100644 mlir/lib/Target/LLVMIR/Dialect/SPIRV/CMakeLists.txt
 create mode 100644 
mlir/lib/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.cpp
 create mode 100644 mlir/test/Integration/GPU/SYCL/gpu-to-spirv.mlir
 create mode 100644 mlir/test/Integration/GPU/SYCL/lit.local.cfg

diff --git a/mlir/include/mlir/Target/LLVMIR/Dialect/All.h 
b/mlir/include/mlir/Target/LLVMIR/Dialect/All.h
index 0563b9bf3d475a4..5dfc15afb75931a 100644
--- a/mlir/include/mlir/Target/LLVMIR/Dialect/All.h
+++ b/mlir/include/mlir/Target/LLVMIR/Dialect/All.h
@@ -26,6 +26,7 @@
 #include "mlir/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.h"
 #include "mlir/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.h"
 #include "mlir/Target/LLVMIR/Dialect/ROCDL/ROCDLToLLVMIRTranslation.h"
+#include "mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h"
 #include "mlir/Target/LLVMIR/Dialect/X86Vector/X86VectorToLLVMIRTranslation.h"
 
 namespace mlir {
@@ -45,6 +46,7 @@ static inline void 
registerAllToLLVMIRTranslations(DialectRegistry ) {
   registerOpenACCDialectTranslation(registry);
   registerOpenMPDialectTranslation(registry);
   registerROCDLDialectTranslation(registry);
+  registerSPIRVDialectTranslation(registry);
   registerX86VectorDialectTranslation(registry);
 
   // Extension required for translating GPU offloading Ops.
@@ -61,6 +63,7 @@ registerAllGPUToLLVMIRTranslations(DialectRegistry ) 
{
   registerLLVMDialectTranslation(registry);
   registerNVVMDialectTranslation(registry);
   registerROCDLDialectTranslation(registry);
+  registerSPIRVDialectTranslation(registry);
 
   // Extension required for translating GPU offloading Ops.
   gpu::registerOffloadingLLVMTranslationInterfaceExternalModels(registry);
diff --git 
a/mlir/include/mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h 
b/mlir/include/mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h
new file mode 100644
index 000..e9580a10b4ca780
--- /dev/null
+++ b/mlir/include/mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h
@@ -0,0 +1,31 @@
+//===- SPIRVToLLVMIRTranslation.h - SPIRV to LLVM IR *- 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
+//
+//===--===//
+//
+// This provides registration calls for SPIRV dialect to LLVM IR translation.
+//
+//===--===//
+
+#ifndef MLIR_TARGET_LLVMIR_DIALECT_SPIRV_SPIRVTOLLVMIRTRANSLATION_H
+#define MLIR_TARGET_LLVMIR_DIALECT_SPIRV_SPIRVTOLLVMIRTRANSLATION_H
+
+namespace mlir {
+
+class DialectRegistry;
+class MLIRContext;
+
+/// Register the SPIRV dialect and the translation from it to the LLVM IR in 
the
+/// given registry;
+void registerSPIRVDialectTranslation(DialectRegistry );
+
+/// Register the SPIRV dialect and the translation from it in the registry
+/// associated with the given context.
+void registerSPIRVDialectTranslation(MLIRContext );
+
+} // namespace mlir
+
+#endif // 

[libc] [clang] [llvm] [lld] [flang] [clang-tools-extra] [openmp] [lldb] [compiler-rt] [libcxx] [mlir] [MLIR] Enable GPU Dialect to SYCL runtime integration (PR #71430)

2023-11-27 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 updated 
https://github.com/llvm/llvm-project/pull/71430

>From c76403cf8629b8f7d8a5b7a3ee5da2881713a7f8 Mon Sep 17 00:00:00 2001
From: "Lee, Sang Ik" 
Date: Mon, 6 Nov 2023 18:47:23 +
Subject: [PATCH 1/5] [MLIR] Enable GPU Dialect to SYCL runtime integration

GPU Dialect lowering to SYCL runtime is driven by spirv.target_env
attached to gpu.module. As a result of this, spirv.target_env remains
as an input to LLVMIR Translation.
A SPIRVToLLVMIRTranslation without any actual translation is added to
avoid an unregistered error in mlir-cpu-runner.
SelectObjectAttr.cpp is updated to
1) Pass binary size argument to getModuleLoadFn
2) Pass parameter count to getKernelLaunchFn
This change does not impact CUDA and ROCM usage since both
mlir_cuda_runtime and mlir_rocm_runtime are already updated to
accept and ignore the extra arguments.
---
 mlir/include/mlir/Target/LLVMIR/Dialect/All.h |  3 ++
 .../Dialect/SPIRV/SPIRVToLLVMIRTranslation.h  | 31 +++
 mlir/lib/Target/LLVMIR/CMakeLists.txt |  1 +
 mlir/lib/Target/LLVMIR/Dialect/CMakeLists.txt |  1 +
 .../LLVMIR/Dialect/GPU/SelectObjectAttr.cpp   | 50 +
 .../LLVMIR/Dialect/SPIRV/CMakeLists.txt   | 13 +
 .../SPIRV/SPIRVToLLVMIRTranslation.cpp| 31 +++
 mlir/test/CMakeLists.txt  |  4 ++
 .../Integration/GPU/SYCL/gpu-to-spirv.mlir| 54 +++
 mlir/test/Integration/GPU/SYCL/lit.local.cfg  |  2 +
 mlir/test/Target/LLVMIR/gpu.mlir  |  9 ++--
 mlir/test/lit.cfg.py  |  3 ++
 mlir/test/lit.site.cfg.py.in  |  1 +
 13 files changed, 188 insertions(+), 15 deletions(-)
 create mode 100644 
mlir/include/mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h
 create mode 100644 mlir/lib/Target/LLVMIR/Dialect/SPIRV/CMakeLists.txt
 create mode 100644 
mlir/lib/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.cpp
 create mode 100644 mlir/test/Integration/GPU/SYCL/gpu-to-spirv.mlir
 create mode 100644 mlir/test/Integration/GPU/SYCL/lit.local.cfg

diff --git a/mlir/include/mlir/Target/LLVMIR/Dialect/All.h 
b/mlir/include/mlir/Target/LLVMIR/Dialect/All.h
index 0563b9bf3d475a4..5dfc15afb75931a 100644
--- a/mlir/include/mlir/Target/LLVMIR/Dialect/All.h
+++ b/mlir/include/mlir/Target/LLVMIR/Dialect/All.h
@@ -26,6 +26,7 @@
 #include "mlir/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.h"
 #include "mlir/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.h"
 #include "mlir/Target/LLVMIR/Dialect/ROCDL/ROCDLToLLVMIRTranslation.h"
+#include "mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h"
 #include "mlir/Target/LLVMIR/Dialect/X86Vector/X86VectorToLLVMIRTranslation.h"
 
 namespace mlir {
@@ -45,6 +46,7 @@ static inline void 
registerAllToLLVMIRTranslations(DialectRegistry ) {
   registerOpenACCDialectTranslation(registry);
   registerOpenMPDialectTranslation(registry);
   registerROCDLDialectTranslation(registry);
+  registerSPIRVDialectTranslation(registry);
   registerX86VectorDialectTranslation(registry);
 
   // Extension required for translating GPU offloading Ops.
@@ -61,6 +63,7 @@ registerAllGPUToLLVMIRTranslations(DialectRegistry ) 
{
   registerLLVMDialectTranslation(registry);
   registerNVVMDialectTranslation(registry);
   registerROCDLDialectTranslation(registry);
+  registerSPIRVDialectTranslation(registry);
 
   // Extension required for translating GPU offloading Ops.
   gpu::registerOffloadingLLVMTranslationInterfaceExternalModels(registry);
diff --git 
a/mlir/include/mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h 
b/mlir/include/mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h
new file mode 100644
index 000..e9580a10b4ca780
--- /dev/null
+++ b/mlir/include/mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h
@@ -0,0 +1,31 @@
+//===- SPIRVToLLVMIRTranslation.h - SPIRV to LLVM IR *- 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
+//
+//===--===//
+//
+// This provides registration calls for SPIRV dialect to LLVM IR translation.
+//
+//===--===//
+
+#ifndef MLIR_TARGET_LLVMIR_DIALECT_SPIRV_SPIRVTOLLVMIRTRANSLATION_H
+#define MLIR_TARGET_LLVMIR_DIALECT_SPIRV_SPIRVTOLLVMIRTRANSLATION_H
+
+namespace mlir {
+
+class DialectRegistry;
+class MLIRContext;
+
+/// Register the SPIRV dialect and the translation from it to the LLVM IR in 
the
+/// given registry;
+void registerSPIRVDialectTranslation(DialectRegistry );
+
+/// Register the SPIRV dialect and the translation from it in the registry
+/// associated with the given context.
+void registerSPIRVDialectTranslation(MLIRContext );
+
+} // namespace mlir
+
+#endif // 

[compiler-rt] [mlir] [clang-tools-extra] [flang] [clang] [libc] [llvm] [libcxx] [lldb] [lld] [MLIR] Enable GPU Dialect to SYCL runtime integration (PR #71430)

2023-11-17 Thread Sang Ik Lee via cfe-commits


@@ -0,0 +1,31 @@
+//===- SPIRVToLLVMIRTranslation.cpp - Translate SPIRV to LLVM IR 
--===//
+//
+// 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
+//
+//===--===//
+//
+// This file implements a translation between the MLIR SPIRV dialect and
+// LLVM IR.
+//
+//===--===//
+
+#include "mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
+#include "mlir/IR/BuiltinAttributes.h"
+#include "mlir/IR/Operation.h"
+#include "mlir/Target/LLVMIR/ModuleTranslation.h"
+
+using namespace mlir;
+using namespace mlir::LLVM;
+
+void mlir::registerSPIRVDialectTranslation(DialectRegistry ) {
+  registry.insert();

silee2 wrote:

There is no translation but dialect registration is still required as 
spirv.target_env is attached and appears in input.
Other option is to register SPIR-V dialect directly here: 
mlir/include/mlir/Target/LLVMIR/Dialect/All.h
@joker-eph Any thoughts? Or better option?





https://github.com/llvm/llvm-project/pull/71430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lldb] [clang] [mlir] [compiler-rt] [libc] [flang] [llvm] [lld] [libcxx] [clang-tools-extra] [MLIR] Enable GPU Dialect to SYCL runtime integration (PR #71430)

2023-11-16 Thread Sang Ik Lee via cfe-commits

silee2 wrote:

@antiagainst @kuhar Any comments?

https://github.com/llvm/llvm-project/pull/71430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lldb] [llvm] [clang-tools-extra] [libcxx] [clang] [mlir] [compiler-rt] [lld] [libc] [flang] [MLIR] Enable GPU Dialect to SYCL runtime integration (PR #71430)

2023-11-15 Thread Sang Ik Lee via cfe-commits


@@ -61,6 +63,7 @@ registerAllGPUToLLVMIRTranslations(DialectRegistry ) 
{
   registerLLVMDialectTranslation(registry);
   registerNVVMDialectTranslation(registry);
   registerROCDLDialectTranslation(registry);
+  registerSPIRVDialectTranslation(registry);

silee2 wrote:

@joker-eph Any thoughts on library vs inlining the call?

https://github.com/llvm/llvm-project/pull/71430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[mlir] [lldb] [llvm] [clang] [flang] [libc] [compiler-rt] [libcxx] [clang-tools-extra] [lld] [MLIR] Enable GPU Dialect to SYCL runtime integration (PR #71430)

2023-11-14 Thread Sang Ik Lee via cfe-commits


@@ -0,0 +1,56 @@
+// RUN: mlir-opt %s 
-pass-pipeline='builtin.module(spirv-attach-target{ver=v1.0 
caps=Addresses,Int64,Kernel},convert-gpu-to-spirv{use-64bit-index=true},gpu.module(spirv.module(spirv-lower-abi-attrs,spirv-update-vce)),func.func(llvm-request-c-wrappers),convert-scf-to-cf,convert-cf-to-llvm,convert-arith-to-llvm,convert-math-to-llvm,convert-func-to-llvm,gpu-to-llvm{use-bare-pointers-for-kernels=true},gpu-module-to-binary,expand-strided-metadata,lower-affine,finalize-memref-to-llvm,reconcile-unrealized-casts)'
 \
+// RUN: | mlir-cpu-runner \
+// RUN:   --shared-libs=%mlir_sycl_runtime \
+// RUN:   --shared-libs=%mlir_runner_utils \
+// RUN:   --entry-point-result=void \
+// RUN: | FileCheck %s
+
+module @add attributes {gpu.container_module} {
+  memref.global "private" constant @__constant_2x2x2xf32_0 : memref<2x2x2xf32> 
= dense<[[[1.1, 2.2], [3.3, 4.4]], [[5.5, 6.6], [7.7, 8.8 ]]]>
+  memref.global "private" constant @__constant_2x2x2xf32 : memref<2x2x2xf32> = 
dense<[[[1.2, 2.3], [4.5, 5.8]], [[7.2, 8.3], [10.5, 11.8]]]>
+  func.func @main() {
+%0 = memref.get_global @__constant_2x2x2xf32 : memref<2x2x2xf32>
+%1 = memref.get_global @__constant_2x2x2xf32_0 : memref<2x2x2xf32>
+%2 = call @test(%0, %1) : (memref<2x2x2xf32>, memref<2x2x2xf32>) -> 
memref<2x2x2xf32>
+%cast = memref.cast %2 : memref<2x2x2xf32> to memref<*xf32>
+call @printMemrefF32(%cast) : (memref<*xf32>) -> ()
+return
+  }
+  func.func private @printMemrefF32(memref<*xf32>)
+  func.func @test(%arg0: memref<2x2x2xf32>, %arg1: memref<2x2x2xf32>) -> 
memref<2x2x2xf32> {

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/71430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[mlir] [compiler-rt] [flang] [clang] [clang-tools-extra] [lld] [libc] [libcxx] [llvm] [lldb] [MLIR] Enable GPU Dialect to SYCL runtime integration (PR #71430)

2023-11-14 Thread Sang Ik Lee via cfe-commits


@@ -377,10 +379,17 @@ 
llvm::LaunchKernel::createKernelLaunch(mlir::gpu::LaunchFuncOp op,
   if (!binary)
 return op.emitError() << "Couldn't find the binary: " << binaryIdentifier;
 
+  auto binaryVar = dyn_cast(binary);
+  llvm::Constant *binaryInit = binaryVar->getInitializer();
+  auto binaryDataSeq = dyn_cast(binaryInit);

silee2 wrote:

Added pointer checks.

https://github.com/llvm/llvm-project/pull/71430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[mlir] [compiler-rt] [flang] [clang] [clang-tools-extra] [lld] [libc] [libcxx] [llvm] [lldb] [MLIR] Enable GPU Dialect to SYCL runtime integration (PR #71430)

2023-11-14 Thread Sang Ik Lee via cfe-commits


@@ -4,6 +4,7 @@
 module attributes {gpu.container_module} {
   // CHECK: [[ARGS_TY:%.*]] = type { i32, i32 }
   // CHECK: @kernel_module_bin_cst = internal constant [4 x i8] c"BLOB", align 
8
+  // CHECK:  @kernel_module_bin_size_cst = internal constant i64 4, align 8

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/71430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[mlir] [lldb] [llvm] [clang] [flang] [libc] [compiler-rt] [libcxx] [clang-tools-extra] [lld] [MLIR] Enable GPU Dialect to SYCL runtime integration (PR #71430)

2023-11-14 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 updated 
https://github.com/llvm/llvm-project/pull/71430

>From c76403cf8629b8f7d8a5b7a3ee5da2881713a7f8 Mon Sep 17 00:00:00 2001
From: "Lee, Sang Ik" 
Date: Mon, 6 Nov 2023 18:47:23 +
Subject: [PATCH 1/5] [MLIR] Enable GPU Dialect to SYCL runtime integration

GPU Dialect lowering to SYCL runtime is driven by spirv.target_env
attached to gpu.module. As a result of this, spirv.target_env remains
as an input to LLVMIR Translation.
A SPIRVToLLVMIRTranslation without any actual translation is added to
avoid an unregistered error in mlir-cpu-runner.
SelectObjectAttr.cpp is updated to
1) Pass binary size argument to getModuleLoadFn
2) Pass parameter count to getKernelLaunchFn
This change does not impact CUDA and ROCM usage since both
mlir_cuda_runtime and mlir_rocm_runtime are already updated to
accept and ignore the extra arguments.
---
 mlir/include/mlir/Target/LLVMIR/Dialect/All.h |  3 ++
 .../Dialect/SPIRV/SPIRVToLLVMIRTranslation.h  | 31 +++
 mlir/lib/Target/LLVMIR/CMakeLists.txt |  1 +
 mlir/lib/Target/LLVMIR/Dialect/CMakeLists.txt |  1 +
 .../LLVMIR/Dialect/GPU/SelectObjectAttr.cpp   | 50 +
 .../LLVMIR/Dialect/SPIRV/CMakeLists.txt   | 13 +
 .../SPIRV/SPIRVToLLVMIRTranslation.cpp| 31 +++
 mlir/test/CMakeLists.txt  |  4 ++
 .../Integration/GPU/SYCL/gpu-to-spirv.mlir| 54 +++
 mlir/test/Integration/GPU/SYCL/lit.local.cfg  |  2 +
 mlir/test/Target/LLVMIR/gpu.mlir  |  9 ++--
 mlir/test/lit.cfg.py  |  3 ++
 mlir/test/lit.site.cfg.py.in  |  1 +
 13 files changed, 188 insertions(+), 15 deletions(-)
 create mode 100644 
mlir/include/mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h
 create mode 100644 mlir/lib/Target/LLVMIR/Dialect/SPIRV/CMakeLists.txt
 create mode 100644 
mlir/lib/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.cpp
 create mode 100644 mlir/test/Integration/GPU/SYCL/gpu-to-spirv.mlir
 create mode 100644 mlir/test/Integration/GPU/SYCL/lit.local.cfg

diff --git a/mlir/include/mlir/Target/LLVMIR/Dialect/All.h 
b/mlir/include/mlir/Target/LLVMIR/Dialect/All.h
index 0563b9bf3d475a4..5dfc15afb75931a 100644
--- a/mlir/include/mlir/Target/LLVMIR/Dialect/All.h
+++ b/mlir/include/mlir/Target/LLVMIR/Dialect/All.h
@@ -26,6 +26,7 @@
 #include "mlir/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.h"
 #include "mlir/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.h"
 #include "mlir/Target/LLVMIR/Dialect/ROCDL/ROCDLToLLVMIRTranslation.h"
+#include "mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h"
 #include "mlir/Target/LLVMIR/Dialect/X86Vector/X86VectorToLLVMIRTranslation.h"
 
 namespace mlir {
@@ -45,6 +46,7 @@ static inline void 
registerAllToLLVMIRTranslations(DialectRegistry ) {
   registerOpenACCDialectTranslation(registry);
   registerOpenMPDialectTranslation(registry);
   registerROCDLDialectTranslation(registry);
+  registerSPIRVDialectTranslation(registry);
   registerX86VectorDialectTranslation(registry);
 
   // Extension required for translating GPU offloading Ops.
@@ -61,6 +63,7 @@ registerAllGPUToLLVMIRTranslations(DialectRegistry ) 
{
   registerLLVMDialectTranslation(registry);
   registerNVVMDialectTranslation(registry);
   registerROCDLDialectTranslation(registry);
+  registerSPIRVDialectTranslation(registry);
 
   // Extension required for translating GPU offloading Ops.
   gpu::registerOffloadingLLVMTranslationInterfaceExternalModels(registry);
diff --git 
a/mlir/include/mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h 
b/mlir/include/mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h
new file mode 100644
index 000..e9580a10b4ca780
--- /dev/null
+++ b/mlir/include/mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h
@@ -0,0 +1,31 @@
+//===- SPIRVToLLVMIRTranslation.h - SPIRV to LLVM IR *- 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
+//
+//===--===//
+//
+// This provides registration calls for SPIRV dialect to LLVM IR translation.
+//
+//===--===//
+
+#ifndef MLIR_TARGET_LLVMIR_DIALECT_SPIRV_SPIRVTOLLVMIRTRANSLATION_H
+#define MLIR_TARGET_LLVMIR_DIALECT_SPIRV_SPIRVTOLLVMIRTRANSLATION_H
+
+namespace mlir {
+
+class DialectRegistry;
+class MLIRContext;
+
+/// Register the SPIRV dialect and the translation from it to the LLVM IR in 
the
+/// given registry;
+void registerSPIRVDialectTranslation(DialectRegistry );
+
+/// Register the SPIRV dialect and the translation from it in the registry
+/// associated with the given context.
+void registerSPIRVDialectTranslation(MLIRContext );
+
+} // namespace mlir
+
+#endif // 

[llvm] [clang-tools-extra] [mlir] [clang] [MLIR] Enable GPU Dialect to SYCL runtime integration (PR #71430)

2023-11-13 Thread Sang Ik Lee via cfe-commits


@@ -0,0 +1,31 @@
+//===- SPIRVToLLVMIRTranslation.h - SPIRV to LLVM IR *- 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
+//
+//===--===//
+//
+// This provides registration calls for SPIRV dialect to LLVM IR translation.
+//
+//===--===//
+
+#ifndef MLIR_TARGET_LLVMIR_DIALECT_SPIRV_SPIRVTOLLVMIRTRANSLATION_H
+#define MLIR_TARGET_LLVMIR_DIALECT_SPIRV_SPIRVTOLLVMIRTRANSLATION_H
+
+namespace mlir {
+
+class DialectRegistry;
+class MLIRContext;
+
+/// Register the SPIRV dialect and the translation from it to the LLVM IR in 
the

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/71430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang-tools-extra] [mlir] [clang] [MLIR] Enable GPU Dialect to SYCL runtime integration (PR #71430)

2023-11-13 Thread Sang Ik Lee via cfe-commits


@@ -0,0 +1,54 @@
+// RUN: mlir-opt %s 
-pass-pipeline='builtin.module(spirv-attach-target{ver=v1.0 
caps=Addresses,Int64,Kernel},convert-gpu-to-spirv{use-64bit-index=true},gpu.module(spirv.module(spirv-lower-abi-attrs,spirv-update-vce)),func.func(llvm-request-c-wrappers),convert-scf-to-cf,convert-cf-to-llvm,convert-arith-to-llvm,convert-math-to-llvm,convert-func-to-llvm,gpu-to-llvm{use-bare-pointers-for-kernels=true},gpu-module-to-binary,expand-strided-metadata,lower-affine,finalize-memref-to-llvm,reconcile-unrealized-casts)'
 \

silee2 wrote:

Added two more tests.

https://github.com/llvm/llvm-project/pull/71430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang-tools-extra] [mlir] [clang] [MLIR] Enable GPU Dialect to SYCL runtime integration (PR #71430)

2023-11-13 Thread Sang Ik Lee via cfe-commits


@@ -0,0 +1,31 @@
+//===- SPIRVToLLVMIRTranslation.cpp - Translate SPIRV to LLVM IR 
--===//
+//
+// 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
+//
+//===--===//
+//
+// This file implements a translation between the MLIR SPIRV dialect and

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/71430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang-tools-extra] [mlir] [clang] [MLIR] Enable GPU Dialect to SYCL runtime integration (PR #71430)

2023-11-13 Thread Sang Ik Lee via cfe-commits


@@ -377,10 +394,21 @@ 
llvm::LaunchKernel::createKernelLaunch(mlir::gpu::LaunchFuncOp op,
   if (!binary)
 return op.emitError() << "Couldn't find the binary: " << binaryIdentifier;
 
+  llvm::Constant *paramsCount =
+  llvm::ConstantInt::get(i64Ty, op.getNumKernelOperands());
+
+  std::string binarySizeIdentifier = getBinarySizeIdentifier(moduleName);
+  Value *binarySizeVar = module.getGlobalVariable(binarySizeIdentifier, true);

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/71430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [llvm] [mlir] [MLIR] Enable GPU Dialect to SYCL runtime integration (PR #71430)

2023-11-13 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 updated 
https://github.com/llvm/llvm-project/pull/71430

>From c76403cf8629b8f7d8a5b7a3ee5da2881713a7f8 Mon Sep 17 00:00:00 2001
From: "Lee, Sang Ik" 
Date: Mon, 6 Nov 2023 18:47:23 +
Subject: [PATCH 1/4] [MLIR] Enable GPU Dialect to SYCL runtime integration

GPU Dialect lowering to SYCL runtime is driven by spirv.target_env
attached to gpu.module. As a result of this, spirv.target_env remains
as an input to LLVMIR Translation.
A SPIRVToLLVMIRTranslation without any actual translation is added to
avoid an unregistered error in mlir-cpu-runner.
SelectObjectAttr.cpp is updated to
1) Pass binary size argument to getModuleLoadFn
2) Pass parameter count to getKernelLaunchFn
This change does not impact CUDA and ROCM usage since both
mlir_cuda_runtime and mlir_rocm_runtime are already updated to
accept and ignore the extra arguments.
---
 mlir/include/mlir/Target/LLVMIR/Dialect/All.h |  3 ++
 .../Dialect/SPIRV/SPIRVToLLVMIRTranslation.h  | 31 +++
 mlir/lib/Target/LLVMIR/CMakeLists.txt |  1 +
 mlir/lib/Target/LLVMIR/Dialect/CMakeLists.txt |  1 +
 .../LLVMIR/Dialect/GPU/SelectObjectAttr.cpp   | 50 +
 .../LLVMIR/Dialect/SPIRV/CMakeLists.txt   | 13 +
 .../SPIRV/SPIRVToLLVMIRTranslation.cpp| 31 +++
 mlir/test/CMakeLists.txt  |  4 ++
 .../Integration/GPU/SYCL/gpu-to-spirv.mlir| 54 +++
 mlir/test/Integration/GPU/SYCL/lit.local.cfg  |  2 +
 mlir/test/Target/LLVMIR/gpu.mlir  |  9 ++--
 mlir/test/lit.cfg.py  |  3 ++
 mlir/test/lit.site.cfg.py.in  |  1 +
 13 files changed, 188 insertions(+), 15 deletions(-)
 create mode 100644 
mlir/include/mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h
 create mode 100644 mlir/lib/Target/LLVMIR/Dialect/SPIRV/CMakeLists.txt
 create mode 100644 
mlir/lib/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.cpp
 create mode 100644 mlir/test/Integration/GPU/SYCL/gpu-to-spirv.mlir
 create mode 100644 mlir/test/Integration/GPU/SYCL/lit.local.cfg

diff --git a/mlir/include/mlir/Target/LLVMIR/Dialect/All.h 
b/mlir/include/mlir/Target/LLVMIR/Dialect/All.h
index 0563b9bf3d475a4..5dfc15afb75931a 100644
--- a/mlir/include/mlir/Target/LLVMIR/Dialect/All.h
+++ b/mlir/include/mlir/Target/LLVMIR/Dialect/All.h
@@ -26,6 +26,7 @@
 #include "mlir/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.h"
 #include "mlir/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.h"
 #include "mlir/Target/LLVMIR/Dialect/ROCDL/ROCDLToLLVMIRTranslation.h"
+#include "mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h"
 #include "mlir/Target/LLVMIR/Dialect/X86Vector/X86VectorToLLVMIRTranslation.h"
 
 namespace mlir {
@@ -45,6 +46,7 @@ static inline void 
registerAllToLLVMIRTranslations(DialectRegistry ) {
   registerOpenACCDialectTranslation(registry);
   registerOpenMPDialectTranslation(registry);
   registerROCDLDialectTranslation(registry);
+  registerSPIRVDialectTranslation(registry);
   registerX86VectorDialectTranslation(registry);
 
   // Extension required for translating GPU offloading Ops.
@@ -61,6 +63,7 @@ registerAllGPUToLLVMIRTranslations(DialectRegistry ) 
{
   registerLLVMDialectTranslation(registry);
   registerNVVMDialectTranslation(registry);
   registerROCDLDialectTranslation(registry);
+  registerSPIRVDialectTranslation(registry);
 
   // Extension required for translating GPU offloading Ops.
   gpu::registerOffloadingLLVMTranslationInterfaceExternalModels(registry);
diff --git 
a/mlir/include/mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h 
b/mlir/include/mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h
new file mode 100644
index 000..e9580a10b4ca780
--- /dev/null
+++ b/mlir/include/mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h
@@ -0,0 +1,31 @@
+//===- SPIRVToLLVMIRTranslation.h - SPIRV to LLVM IR *- 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
+//
+//===--===//
+//
+// This provides registration calls for SPIRV dialect to LLVM IR translation.
+//
+//===--===//
+
+#ifndef MLIR_TARGET_LLVMIR_DIALECT_SPIRV_SPIRVTOLLVMIRTRANSLATION_H
+#define MLIR_TARGET_LLVMIR_DIALECT_SPIRV_SPIRVTOLLVMIRTRANSLATION_H
+
+namespace mlir {
+
+class DialectRegistry;
+class MLIRContext;
+
+/// Register the SPIRV dialect and the translation from it to the LLVM IR in 
the
+/// given registry;
+void registerSPIRVDialectTranslation(DialectRegistry );
+
+/// Register the SPIRV dialect and the translation from it in the registry
+/// associated with the given context.
+void registerSPIRVDialectTranslation(MLIRContext );
+
+} // namespace mlir
+
+#endif // 

[clang] [clang-tools-extra] [llvm] [flang] [mlir] [lldb] [compiler-rt] [libcxx] [mlir] Prepare convert-gpu-to-spirv for OpenCL support (PR #69941)

2023-11-05 Thread Sang Ik Lee via cfe-commits

silee2 wrote:

@antiagainst @joker-eph Can someone merge this PR?

https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc] [compiler-rt] [llvm] [flang] [clang] [libcxx] [mlir] [MLIR] SPIRV Target Attribute (PR #69949)

2023-11-03 Thread Sang Ik Lee via cfe-commits

silee2 wrote:

@antiagainst I'm waiting for your approval.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-30 Thread Sang Ik Lee via cfe-commits

silee2 wrote:

@antiagainst Thanks for the detailed review and helpful comments! Updated the 
PR accordingly.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-30 Thread Sang Ik Lee via cfe-commits

silee2 wrote:

@antiagainst Thanks for the detailed review and helpful comments! Updated the 
PR accordingly.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-30 Thread Sang Ik Lee via cfe-commits


@@ -188,4 +188,46 @@ def GpuROCDLAttachTarget: Pass<"rocdl-attach-target", ""> {
   ];
 }
 
+def GpuSPIRVAttachTarget: Pass<"spirv-attach-target", ""> {
+  let summary = "Attaches an SPIRV target attribute to a GPU Module.";
+  let description = [{
+This pass searches for all GPU Modules in the immediate regions and 
attaches
+an SPIRV target if the module matches the name specified by the `module` 
argument.
+
+Example:
+```
+// File: in1.mlir:
+gpu.module @nvvm_module_1 {...}
+gpu.module @spirv_module_1 {...}
+// mlir-opt --spirv-attach-target="module=spirv.* ver=v1.0 caps=Kernel" 
in1.mlir
+gpu.module @nvvm_module_1 {...}
+gpu.module @spirv_module_1 [#spirv.target, resource_limits = <>>] {...}
+```
+  }];
+  let options = [
+Option<"moduleMatcher", "module", "std::string",
+   /*default=*/ [{""}],
+   "Regex used to identify the modules to attach the target to.">,
+Option<"spirvVersion", "ver", "std::string",
+   /*default=*/ "\"v1.0\"",
+   "SPIRV Addressing Model.">,

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-30 Thread Sang Ik Lee via cfe-commits


@@ -188,4 +188,46 @@ def GpuROCDLAttachTarget: Pass<"rocdl-attach-target", ""> {
   ];
 }
 
+def GpuSPIRVAttachTarget: Pass<"spirv-attach-target", ""> {
+  let summary = "Attaches an SPIRV target attribute to a GPU Module.";
+  let description = [{
+This pass searches for all GPU Modules in the immediate regions and 
attaches
+an SPIRV target if the module matches the name specified by the `module` 
argument.
+
+Example:
+```
+// File: in1.mlir:
+gpu.module @nvvm_module_1 {...}
+gpu.module @spirv_module_1 {...}
+// mlir-opt --spirv-attach-target="module=spirv.* ver=v1.0 caps=Kernel" 
in1.mlir
+gpu.module @nvvm_module_1 {...}
+gpu.module @spirv_module_1 [#spirv.target, resource_limits = <>>] {...}
+```
+  }];
+  let options = [
+Option<"moduleMatcher", "module", "std::string",
+   /*default=*/ [{""}],
+   "Regex used to identify the modules to attach the target to.">,
+Option<"spirvVersion", "ver", "std::string",
+   /*default=*/ "\"v1.0\"",
+   "SPIRV Addressing Model.">,

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-30 Thread Sang Ik Lee via cfe-commits


@@ -188,4 +188,46 @@ def GpuROCDLAttachTarget: Pass<"rocdl-attach-target", ""> {
   ];
 }
 
+def GpuSPIRVAttachTarget: Pass<"spirv-attach-target", ""> {
+  let summary = "Attaches an SPIRV target attribute to a GPU Module.";
+  let description = [{
+This pass searches for all GPU Modules in the immediate regions and 
attaches
+an SPIRV target if the module matches the name specified by the `module` 
argument.
+
+Example:
+```
+// File: in1.mlir:
+gpu.module @nvvm_module_1 {...}
+gpu.module @spirv_module_1 {...}
+// mlir-opt --spirv-attach-target="module=spirv.* ver=v1.0 caps=Kernel" 
in1.mlir

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-30 Thread Sang Ik Lee via cfe-commits


@@ -188,4 +188,46 @@ def GpuROCDLAttachTarget: Pass<"rocdl-attach-target", ""> {
   ];
 }
 
+def GpuSPIRVAttachTarget: Pass<"spirv-attach-target", ""> {
+  let summary = "Attaches an SPIRV target attribute to a GPU Module.";
+  let description = [{
+This pass searches for all GPU Modules in the immediate regions and 
attaches
+an SPIRV target if the module matches the name specified by the `module` 
argument.
+
+Example:
+```
+// File: in1.mlir:
+gpu.module @nvvm_module_1 {...}
+gpu.module @spirv_module_1 {...}
+// mlir-opt --spirv-attach-target="module=spirv.* ver=v1.0 caps=Kernel" 
in1.mlir

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-30 Thread Sang Ik Lee via cfe-commits


@@ -0,0 +1,7 @@
+// RUN: mlir-opt %s --spirv-attach-target='module=spirv.* ver=v1.0 
caps=Kernel' | FileCheck %s
+
+module attributes {gpu.container_module} {
+// CHECK: @spirv_module_1 [#spirv.target, 
resource_limits = <>>]
+gpu.module @spirv_module_1 {

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-30 Thread Sang Ik Lee via cfe-commits


@@ -0,0 +1,7 @@
+// RUN: mlir-opt %s --spirv-attach-target='module=spirv.* ver=v1.0 
caps=Kernel' | FileCheck %s
+
+module attributes {gpu.container_module} {
+// CHECK: @spirv_module_1 [#spirv.target, 
resource_limits = <>>]
+gpu.module @spirv_module_1 {

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-30 Thread Sang Ik Lee via cfe-commits


@@ -0,0 +1,94 @@
+//===- SPIRVAttachTarget.cpp - Attach an SPIRV target 
-===//
+//
+// 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
+//
+//===--===//
+//
+// This file implements the `GpuSPIRVAttachTarget` pass, attaching
+// `#spirv.target` attributes to GPU modules.
+//
+//===--===//
+
+#include "mlir/Dialect/GPU/Transforms/Passes.h"
+
+#include "mlir/Dialect/GPU/IR/GPUDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
+#include "mlir/Dialect/SPIRV/IR/TargetAndABI.h"
+#include "mlir/IR/Builders.h"
+#include "mlir/Pass/Pass.h"
+#include "mlir/Target/SPIRV/Target.h"
+#include "llvm/Support/Regex.h"
+
+namespace mlir {
+#define GEN_PASS_DEF_GPUSPIRVATTACHTARGET
+#include "mlir/Dialect/GPU/Transforms/Passes.h.inc"
+} // namespace mlir
+
+using namespace mlir;
+using namespace mlir::spirv;
+
+namespace {
+struct SPIRVAttachTarget
+: public impl::GpuSPIRVAttachTargetBase {
+  using Base::Base;
+
+  void runOnOperation() override;
+
+  void getDependentDialects(DialectRegistry ) const override {
+registry.insert();
+  }
+};
+} // namespace
+
+void SPIRVAttachTarget::runOnOperation() {
+  OpBuilder builder(());
+  if (!symbolizeVersion(spirvVersion))
+return signalPassFailure();
+  if (!symbolizeClientAPI(clientApi))
+return signalPassFailure();
+  if (!symbolizeVendor(deviceVendor))
+return signalPassFailure();
+  if (!symbolizeDeviceType(deviceType))
+return signalPassFailure();
+
+  Version version = symbolizeVersion(spirvVersion).value();
+  SmallVector capabilities;
+  SmallVector extensions;
+  for (auto cap : spirvCapabilities) {
+if (symbolizeCapability(cap))
+  capabilities.push_back(symbolizeCapability(cap).value());
+  }
+  ArrayRef caps(capabilities);
+  for (auto ext : spirvExtensions) {
+if (symbolizeCapability(ext))
+  extensions.push_back(symbolizeExtension(ext).value());
+  }
+  ArrayRef exts(extensions);
+  VerCapExtAttr vce = VerCapExtAttr::get(version, caps, exts, ());
+  auto target = builder.getAttr(
+  vce, getDefaultResourceLimits(()),
+  symbolizeClientAPI(clientApi).value(),

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-30 Thread Sang Ik Lee via cfe-commits


@@ -0,0 +1,94 @@
+//===- SPIRVAttachTarget.cpp - Attach an SPIRV target 
-===//
+//
+// 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
+//
+//===--===//
+//
+// This file implements the `GpuSPIRVAttachTarget` pass, attaching
+// `#spirv.target` attributes to GPU modules.
+//
+//===--===//
+
+#include "mlir/Dialect/GPU/Transforms/Passes.h"
+
+#include "mlir/Dialect/GPU/IR/GPUDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
+#include "mlir/Dialect/SPIRV/IR/TargetAndABI.h"
+#include "mlir/IR/Builders.h"
+#include "mlir/Pass/Pass.h"
+#include "mlir/Target/SPIRV/Target.h"
+#include "llvm/Support/Regex.h"
+
+namespace mlir {
+#define GEN_PASS_DEF_GPUSPIRVATTACHTARGET
+#include "mlir/Dialect/GPU/Transforms/Passes.h.inc"
+} // namespace mlir
+
+using namespace mlir;
+using namespace mlir::spirv;
+
+namespace {
+struct SPIRVAttachTarget
+: public impl::GpuSPIRVAttachTargetBase {
+  using Base::Base;
+
+  void runOnOperation() override;
+
+  void getDependentDialects(DialectRegistry ) const override {
+registry.insert();
+  }
+};
+} // namespace
+
+void SPIRVAttachTarget::runOnOperation() {
+  OpBuilder builder(());
+  if (!symbolizeVersion(spirvVersion))
+return signalPassFailure();
+  if (!symbolizeClientAPI(clientApi))
+return signalPassFailure();
+  if (!symbolizeVendor(deviceVendor))
+return signalPassFailure();
+  if (!symbolizeDeviceType(deviceType))
+return signalPassFailure();
+
+  Version version = symbolizeVersion(spirvVersion).value();
+  SmallVector capabilities;
+  SmallVector extensions;
+  for (auto cap : spirvCapabilities) {
+if (symbolizeCapability(cap))
+  capabilities.push_back(symbolizeCapability(cap).value());
+  }
+  ArrayRef caps(capabilities);
+  for (auto ext : spirvExtensions) {
+if (symbolizeCapability(ext))
+  extensions.push_back(symbolizeExtension(ext).value());
+  }
+  ArrayRef exts(extensions);
+  VerCapExtAttr vce = VerCapExtAttr::get(version, caps, exts, ());
+  auto target = builder.getAttr(
+  vce, getDefaultResourceLimits(()),
+  symbolizeClientAPI(clientApi).value(),

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-30 Thread Sang Ik Lee via cfe-commits


@@ -0,0 +1,94 @@
+//===- SPIRVAttachTarget.cpp - Attach an SPIRV target 
-===//
+//
+// 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
+//
+//===--===//
+//
+// This file implements the `GpuSPIRVAttachTarget` pass, attaching
+// `#spirv.target` attributes to GPU modules.
+//
+//===--===//
+
+#include "mlir/Dialect/GPU/Transforms/Passes.h"
+
+#include "mlir/Dialect/GPU/IR/GPUDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
+#include "mlir/Dialect/SPIRV/IR/TargetAndABI.h"
+#include "mlir/IR/Builders.h"
+#include "mlir/Pass/Pass.h"
+#include "mlir/Target/SPIRV/Target.h"
+#include "llvm/Support/Regex.h"
+
+namespace mlir {
+#define GEN_PASS_DEF_GPUSPIRVATTACHTARGET
+#include "mlir/Dialect/GPU/Transforms/Passes.h.inc"
+} // namespace mlir
+
+using namespace mlir;
+using namespace mlir::spirv;
+
+namespace {
+struct SPIRVAttachTarget
+: public impl::GpuSPIRVAttachTargetBase {
+  using Base::Base;
+
+  void runOnOperation() override;
+
+  void getDependentDialects(DialectRegistry ) const override {
+registry.insert();
+  }
+};
+} // namespace
+
+void SPIRVAttachTarget::runOnOperation() {
+  OpBuilder builder(());
+  if (!symbolizeVersion(spirvVersion))
+return signalPassFailure();
+  if (!symbolizeClientAPI(clientApi))
+return signalPassFailure();
+  if (!symbolizeVendor(deviceVendor))
+return signalPassFailure();
+  if (!symbolizeDeviceType(deviceType))
+return signalPassFailure();
+
+  Version version = symbolizeVersion(spirvVersion).value();
+  SmallVector capabilities;
+  SmallVector extensions;
+  for (auto cap : spirvCapabilities) {
+if (symbolizeCapability(cap))
+  capabilities.push_back(symbolizeCapability(cap).value());
+  }
+  ArrayRef caps(capabilities);
+  for (auto ext : spirvExtensions) {
+if (symbolizeCapability(ext))
+  extensions.push_back(symbolizeExtension(ext).value());
+  }
+  ArrayRef exts(extensions);
+  VerCapExtAttr vce = VerCapExtAttr::get(version, caps, exts, ());
+  auto target = builder.getAttr(
+  vce, getDefaultResourceLimits(()),
+  symbolizeClientAPI(clientApi).value(),
+  symbolizeVendor(deviceVendor).value(),
+  symbolizeDeviceType(deviceType).value(), deviceId);
+  llvm::Regex matcher(moduleMatcher);
+  for (Region  : getOperation()->getRegions())

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-30 Thread Sang Ik Lee via cfe-commits


@@ -0,0 +1,94 @@
+//===- SPIRVAttachTarget.cpp - Attach an SPIRV target 
-===//
+//
+// 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
+//
+//===--===//
+//
+// This file implements the `GpuSPIRVAttachTarget` pass, attaching
+// `#spirv.target` attributes to GPU modules.
+//
+//===--===//
+
+#include "mlir/Dialect/GPU/Transforms/Passes.h"
+
+#include "mlir/Dialect/GPU/IR/GPUDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
+#include "mlir/Dialect/SPIRV/IR/TargetAndABI.h"
+#include "mlir/IR/Builders.h"
+#include "mlir/Pass/Pass.h"
+#include "mlir/Target/SPIRV/Target.h"
+#include "llvm/Support/Regex.h"
+
+namespace mlir {
+#define GEN_PASS_DEF_GPUSPIRVATTACHTARGET
+#include "mlir/Dialect/GPU/Transforms/Passes.h.inc"
+} // namespace mlir
+
+using namespace mlir;
+using namespace mlir::spirv;
+
+namespace {
+struct SPIRVAttachTarget
+: public impl::GpuSPIRVAttachTargetBase {
+  using Base::Base;
+
+  void runOnOperation() override;
+
+  void getDependentDialects(DialectRegistry ) const override {
+registry.insert();
+  }
+};
+} // namespace
+
+void SPIRVAttachTarget::runOnOperation() {
+  OpBuilder builder(());
+  if (!symbolizeVersion(spirvVersion))
+return signalPassFailure();
+  if (!symbolizeClientAPI(clientApi))
+return signalPassFailure();
+  if (!symbolizeVendor(deviceVendor))
+return signalPassFailure();
+  if (!symbolizeDeviceType(deviceType))
+return signalPassFailure();
+
+  Version version = symbolizeVersion(spirvVersion).value();
+  SmallVector capabilities;
+  SmallVector extensions;
+  for (auto cap : spirvCapabilities) {
+if (symbolizeCapability(cap))
+  capabilities.push_back(symbolizeCapability(cap).value());
+  }
+  ArrayRef caps(capabilities);
+  for (auto ext : spirvExtensions) {
+if (symbolizeCapability(ext))
+  extensions.push_back(symbolizeExtension(ext).value());
+  }
+  ArrayRef exts(extensions);
+  VerCapExtAttr vce = VerCapExtAttr::get(version, caps, exts, ());
+  auto target = builder.getAttr(
+  vce, getDefaultResourceLimits(()),
+  symbolizeClientAPI(clientApi).value(),
+  symbolizeVendor(deviceVendor).value(),
+  symbolizeDeviceType(deviceType).value(), deviceId);
+  llvm::Regex matcher(moduleMatcher);
+  for (Region  : getOperation()->getRegions())

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-30 Thread Sang Ik Lee via cfe-commits


@@ -0,0 +1,94 @@
+//===- SPIRVAttachTarget.cpp - Attach an SPIRV target 
-===//
+//
+// 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
+//
+//===--===//
+//
+// This file implements the `GpuSPIRVAttachTarget` pass, attaching
+// `#spirv.target` attributes to GPU modules.
+//
+//===--===//
+
+#include "mlir/Dialect/GPU/Transforms/Passes.h"
+
+#include "mlir/Dialect/GPU/IR/GPUDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
+#include "mlir/Dialect/SPIRV/IR/TargetAndABI.h"
+#include "mlir/IR/Builders.h"
+#include "mlir/Pass/Pass.h"
+#include "mlir/Target/SPIRV/Target.h"
+#include "llvm/Support/Regex.h"
+
+namespace mlir {
+#define GEN_PASS_DEF_GPUSPIRVATTACHTARGET
+#include "mlir/Dialect/GPU/Transforms/Passes.h.inc"
+} // namespace mlir
+
+using namespace mlir;
+using namespace mlir::spirv;
+
+namespace {
+struct SPIRVAttachTarget
+: public impl::GpuSPIRVAttachTargetBase {
+  using Base::Base;
+
+  void runOnOperation() override;
+
+  void getDependentDialects(DialectRegistry ) const override {
+registry.insert();
+  }
+};
+} // namespace
+
+void SPIRVAttachTarget::runOnOperation() {
+  OpBuilder builder(());
+  if (!symbolizeVersion(spirvVersion))
+return signalPassFailure();
+  if (!symbolizeClientAPI(clientApi))
+return signalPassFailure();
+  if (!symbolizeVendor(deviceVendor))
+return signalPassFailure();
+  if (!symbolizeDeviceType(deviceType))
+return signalPassFailure();
+
+  Version version = symbolizeVersion(spirvVersion).value();

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-30 Thread Sang Ik Lee via cfe-commits


@@ -0,0 +1,94 @@
+//===- SPIRVAttachTarget.cpp - Attach an SPIRV target 
-===//
+//
+// 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
+//
+//===--===//
+//
+// This file implements the `GpuSPIRVAttachTarget` pass, attaching
+// `#spirv.target` attributes to GPU modules.
+//
+//===--===//
+
+#include "mlir/Dialect/GPU/Transforms/Passes.h"
+
+#include "mlir/Dialect/GPU/IR/GPUDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
+#include "mlir/Dialect/SPIRV/IR/TargetAndABI.h"
+#include "mlir/IR/Builders.h"
+#include "mlir/Pass/Pass.h"
+#include "mlir/Target/SPIRV/Target.h"
+#include "llvm/Support/Regex.h"
+
+namespace mlir {
+#define GEN_PASS_DEF_GPUSPIRVATTACHTARGET
+#include "mlir/Dialect/GPU/Transforms/Passes.h.inc"
+} // namespace mlir
+
+using namespace mlir;
+using namespace mlir::spirv;
+
+namespace {
+struct SPIRVAttachTarget
+: public impl::GpuSPIRVAttachTargetBase {
+  using Base::Base;
+
+  void runOnOperation() override;
+
+  void getDependentDialects(DialectRegistry ) const override {
+registry.insert();
+  }
+};
+} // namespace
+
+void SPIRVAttachTarget::runOnOperation() {
+  OpBuilder builder(());
+  if (!symbolizeVersion(spirvVersion))
+return signalPassFailure();
+  if (!symbolizeClientAPI(clientApi))
+return signalPassFailure();
+  if (!symbolizeVendor(deviceVendor))
+return signalPassFailure();
+  if (!symbolizeDeviceType(deviceType))
+return signalPassFailure();
+
+  Version version = symbolizeVersion(spirvVersion).value();

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-30 Thread Sang Ik Lee via cfe-commits


@@ -0,0 +1,94 @@
+//===- SPIRVAttachTarget.cpp - Attach an SPIRV target 
-===//
+//
+// 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
+//
+//===--===//
+//
+// This file implements the `GpuSPIRVAttachTarget` pass, attaching

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-30 Thread Sang Ik Lee via cfe-commits


@@ -0,0 +1,94 @@
+//===- SPIRVAttachTarget.cpp - Attach an SPIRV target 
-===//
+//
+// 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
+//
+//===--===//
+//
+// This file implements the `GpuSPIRVAttachTarget` pass, attaching

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-30 Thread Sang Ik Lee via cfe-commits


@@ -166,4 +166,35 @@ def SPIRV_ResourceLimitsAttr : 
SPIRV_Attr<"ResourceLimits", "resource_limits"> {
   let assemblyFormat = "`<` struct(params) `>`";
 }
 
+//===--===//
+// SPIRV target attribute.

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-30 Thread Sang Ik Lee via cfe-commits


@@ -166,4 +166,35 @@ def SPIRV_ResourceLimitsAttr : 
SPIRV_Attr<"ResourceLimits", "resource_limits"> {
   let assemblyFormat = "`<` struct(params) `>`";
 }
 
+//===--===//
+// SPIRV target attribute.

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-30 Thread Sang Ik Lee via cfe-commits


@@ -0,0 +1,30 @@
+//===- Target.h - MLIR SPIRV target registration *- C++ 
-*-===//

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-30 Thread Sang Ik Lee via cfe-commits


@@ -166,4 +166,35 @@ def SPIRV_ResourceLimitsAttr : 
SPIRV_Attr<"ResourceLimits", "resource_limits"> {
   let assemblyFormat = "`<` struct(params) `>`";
 }
 
+//===--===//
+// SPIRV target attribute.
+//===--===//
+
+def SPIRV_TargetAttr : SPIRV_Attr<"SPIRVTarget", "target"> {

silee2 wrote:

Updated the PR to use spirv::TargetEnvAttr.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-30 Thread Sang Ik Lee via cfe-commits


@@ -0,0 +1,30 @@
+//===- Target.h - MLIR SPIRV target registration *- C++ 
-*-===//

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-30 Thread Sang Ik Lee via cfe-commits


@@ -166,4 +166,35 @@ def SPIRV_ResourceLimitsAttr : 
SPIRV_Attr<"ResourceLimits", "resource_limits"> {
   let assemblyFormat = "`<` struct(params) `>`";
 }
 
+//===--===//
+// SPIRV target attribute.
+//===--===//
+
+def SPIRV_TargetAttr : SPIRV_Attr<"SPIRVTarget", "target"> {

silee2 wrote:

Updated the PR to use spirv::TargetEnvAttr.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-30 Thread Sang Ik Lee via cfe-commits


@@ -188,4 +188,46 @@ def GpuROCDLAttachTarget: Pass<"rocdl-attach-target", ""> {
   ];
 }
 
+def GpuSPIRVAttachTarget: Pass<"spirv-attach-target", ""> {
+  let summary = "Attaches an SPIRV target attribute to a GPU Module.";

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-30 Thread Sang Ik Lee via cfe-commits


@@ -188,4 +188,46 @@ def GpuROCDLAttachTarget: Pass<"rocdl-attach-target", ""> {
   ];
 }
 
+def GpuSPIRVAttachTarget: Pass<"spirv-attach-target", ""> {
+  let summary = "Attaches an SPIRV target attribute to a GPU Module.";

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-30 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 updated 
https://github.com/llvm/llvm-project/pull/69949

>From 1a4319cff8d95d5a6a6598f94162be28e56d68a8 Mon Sep 17 00:00:00 2001
From: "Lee, Sang Ik" 
Date: Mon, 23 Oct 2023 17:23:54 +
Subject: [PATCH 1/5] [MLIR] SPIRV Target Attribute

Create SPIRV Target Attribute to enable GPU compilation pipeline.
The Target Attribute is modeled after the existing spriv.target_env
Plan is to use this new attribute to enable GPU compilation pipeline
for OpenCL kernels only.
The changes do not impact Vulkan shaders using milr-vulkan-runner.
New GPU Dialect transform pass spirv-attach-target is implemented for
attaching attribute from CLI.
gpu-module-to-binary pass now works with GPU module that has SPIRV module
with OpenCL kernel functions inside.
---
 .../mlir/Dialect/GPU/Transforms/Passes.h  |   1 +
 .../mlir/Dialect/GPU/Transforms/Passes.td |  42 +++
 .../mlir/Dialect/SPIRV/IR/SPIRVAttributes.h   |   6 +
 .../mlir/Dialect/SPIRV/IR/SPIRVAttributes.td  |  31 +
 mlir/include/mlir/InitAllDialects.h   |   2 +
 mlir/include/mlir/Target/SPIRV/Target.h   |  30 +
 mlir/lib/Dialect/GPU/CMakeLists.txt   |   2 +
 .../Dialect/GPU/Transforms/ModuleToBinary.cpp |   2 +
 .../GPU/Transforms/SPIRVAttachTarget.cpp  |  94 ++
 mlir/lib/Target/SPIRV/CMakeLists.txt  |  13 ++
 mlir/lib/Target/SPIRV/Target.cpp  | 115 ++
 .../Dialect/GPU/module-to-binary-spirv.mlir   |  13 ++
 .../Dialect/GPU/spirv-attach-targets.mlir |   7 ++
 mlir/test/Dialect/SPIRV/IR/target.mlir|  14 +++
 14 files changed, 372 insertions(+)
 create mode 100644 mlir/include/mlir/Target/SPIRV/Target.h
 create mode 100644 mlir/lib/Dialect/GPU/Transforms/SPIRVAttachTarget.cpp
 create mode 100644 mlir/lib/Target/SPIRV/Target.cpp
 create mode 100644 mlir/test/Dialect/GPU/module-to-binary-spirv.mlir
 create mode 100644 mlir/test/Dialect/GPU/spirv-attach-targets.mlir
 create mode 100644 mlir/test/Dialect/SPIRV/IR/target.mlir

diff --git a/mlir/include/mlir/Dialect/GPU/Transforms/Passes.h 
b/mlir/include/mlir/Dialect/GPU/Transforms/Passes.h
index 2a891a7d24f809a..42fa46b0a57bdee 100644
--- a/mlir/include/mlir/Dialect/GPU/Transforms/Passes.h
+++ b/mlir/include/mlir/Dialect/GPU/Transforms/Passes.h
@@ -15,6 +15,7 @@
 
 #include "Utils.h"
 #include "mlir/Dialect/GPU/IR/GPUDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"
 #include "mlir/Pass/Pass.h"
 #include 
 
diff --git a/mlir/include/mlir/Dialect/GPU/Transforms/Passes.td 
b/mlir/include/mlir/Dialect/GPU/Transforms/Passes.td
index 3de8e18851369df..44e3e5b6226bfeb 100644
--- a/mlir/include/mlir/Dialect/GPU/Transforms/Passes.td
+++ b/mlir/include/mlir/Dialect/GPU/Transforms/Passes.td
@@ -188,4 +188,46 @@ def GpuROCDLAttachTarget: Pass<"rocdl-attach-target", ""> {
   ];
 }
 
+def GpuSPIRVAttachTarget: Pass<"spirv-attach-target", ""> {
+  let summary = "Attaches an SPIRV target attribute to a GPU Module.";
+  let description = [{
+This pass searches for all GPU Modules in the immediate regions and 
attaches
+an SPIRV target if the module matches the name specified by the `module` 
argument.
+
+Example:
+```
+// File: in1.mlir:
+gpu.module @nvvm_module_1 {...}
+gpu.module @spirv_module_1 {...}
+// mlir-opt --spirv-attach-target="module=spirv.* ver=v1.0 caps=Kernel" 
in1.mlir
+gpu.module @nvvm_module_1 {...}
+gpu.module @spirv_module_1 [#spirv.target, resource_limits = <>>] {...}
+```
+  }];
+  let options = [
+Option<"moduleMatcher", "module", "std::string",
+   /*default=*/ [{""}],
+   "Regex used to identify the modules to attach the target to.">,
+Option<"spirvVersion", "ver", "std::string",
+   /*default=*/ "\"v1.0\"",
+   "SPIRV Addressing Model.">,
+ListOption<"spirvCapabilities", "caps", "std::string",
+   "List of required SPIRV Capabilities">,
+ListOption<"spirvExtensions", "exts", "std::string",
+   "List of required SPIRV Extensions">,
+Option<"clientApi", "client_api", "std::string",
+   /*default=*/ "\"Unknown\"",
+   "Client API">,
+Option<"deviceVendor", "vendor", "std::string",
+   /*default=*/ "\"Unknown\"",
+   "Device Vendor">,
+Option<"deviceType", "device_type", "std::string",
+   /*default=*/ "\"Unknown\"",
+   "Device Type">,
+Option<"deviceId", "device_id", "uint32_t",
+   /*default=*/ "mlir::spirv::TargetEnvAttr::kUnknownDeviceID",
+   "Device ID">,
+  ];
+}
+
 #endif // MLIR_DIALECT_GPU_PASSES
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVAttributes.h 
b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVAttributes.h
index 1d304610a03a8dc..3b914dc4cc82f11 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVAttributes.h
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVAttributes.h
@@ -17,6 +17,12 @@
 #include "mlir/IR/BuiltinAttributes.h"
 #include "mlir/Support/LLVM.h"
 
+namespace mlir 

[clang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-30 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 updated 
https://github.com/llvm/llvm-project/pull/69949

>From 1a4319cff8d95d5a6a6598f94162be28e56d68a8 Mon Sep 17 00:00:00 2001
From: "Lee, Sang Ik" 
Date: Mon, 23 Oct 2023 17:23:54 +
Subject: [PATCH 1/5] [MLIR] SPIRV Target Attribute

Create SPIRV Target Attribute to enable GPU compilation pipeline.
The Target Attribute is modeled after the existing spriv.target_env
Plan is to use this new attribute to enable GPU compilation pipeline
for OpenCL kernels only.
The changes do not impact Vulkan shaders using milr-vulkan-runner.
New GPU Dialect transform pass spirv-attach-target is implemented for
attaching attribute from CLI.
gpu-module-to-binary pass now works with GPU module that has SPIRV module
with OpenCL kernel functions inside.
---
 .../mlir/Dialect/GPU/Transforms/Passes.h  |   1 +
 .../mlir/Dialect/GPU/Transforms/Passes.td |  42 +++
 .../mlir/Dialect/SPIRV/IR/SPIRVAttributes.h   |   6 +
 .../mlir/Dialect/SPIRV/IR/SPIRVAttributes.td  |  31 +
 mlir/include/mlir/InitAllDialects.h   |   2 +
 mlir/include/mlir/Target/SPIRV/Target.h   |  30 +
 mlir/lib/Dialect/GPU/CMakeLists.txt   |   2 +
 .../Dialect/GPU/Transforms/ModuleToBinary.cpp |   2 +
 .../GPU/Transforms/SPIRVAttachTarget.cpp  |  94 ++
 mlir/lib/Target/SPIRV/CMakeLists.txt  |  13 ++
 mlir/lib/Target/SPIRV/Target.cpp  | 115 ++
 .../Dialect/GPU/module-to-binary-spirv.mlir   |  13 ++
 .../Dialect/GPU/spirv-attach-targets.mlir |   7 ++
 mlir/test/Dialect/SPIRV/IR/target.mlir|  14 +++
 14 files changed, 372 insertions(+)
 create mode 100644 mlir/include/mlir/Target/SPIRV/Target.h
 create mode 100644 mlir/lib/Dialect/GPU/Transforms/SPIRVAttachTarget.cpp
 create mode 100644 mlir/lib/Target/SPIRV/Target.cpp
 create mode 100644 mlir/test/Dialect/GPU/module-to-binary-spirv.mlir
 create mode 100644 mlir/test/Dialect/GPU/spirv-attach-targets.mlir
 create mode 100644 mlir/test/Dialect/SPIRV/IR/target.mlir

diff --git a/mlir/include/mlir/Dialect/GPU/Transforms/Passes.h 
b/mlir/include/mlir/Dialect/GPU/Transforms/Passes.h
index 2a891a7d24f809a..42fa46b0a57bdee 100644
--- a/mlir/include/mlir/Dialect/GPU/Transforms/Passes.h
+++ b/mlir/include/mlir/Dialect/GPU/Transforms/Passes.h
@@ -15,6 +15,7 @@
 
 #include "Utils.h"
 #include "mlir/Dialect/GPU/IR/GPUDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"
 #include "mlir/Pass/Pass.h"
 #include 
 
diff --git a/mlir/include/mlir/Dialect/GPU/Transforms/Passes.td 
b/mlir/include/mlir/Dialect/GPU/Transforms/Passes.td
index 3de8e18851369df..44e3e5b6226bfeb 100644
--- a/mlir/include/mlir/Dialect/GPU/Transforms/Passes.td
+++ b/mlir/include/mlir/Dialect/GPU/Transforms/Passes.td
@@ -188,4 +188,46 @@ def GpuROCDLAttachTarget: Pass<"rocdl-attach-target", ""> {
   ];
 }
 
+def GpuSPIRVAttachTarget: Pass<"spirv-attach-target", ""> {
+  let summary = "Attaches an SPIRV target attribute to a GPU Module.";
+  let description = [{
+This pass searches for all GPU Modules in the immediate regions and 
attaches
+an SPIRV target if the module matches the name specified by the `module` 
argument.
+
+Example:
+```
+// File: in1.mlir:
+gpu.module @nvvm_module_1 {...}
+gpu.module @spirv_module_1 {...}
+// mlir-opt --spirv-attach-target="module=spirv.* ver=v1.0 caps=Kernel" 
in1.mlir
+gpu.module @nvvm_module_1 {...}
+gpu.module @spirv_module_1 [#spirv.target, resource_limits = <>>] {...}
+```
+  }];
+  let options = [
+Option<"moduleMatcher", "module", "std::string",
+   /*default=*/ [{""}],
+   "Regex used to identify the modules to attach the target to.">,
+Option<"spirvVersion", "ver", "std::string",
+   /*default=*/ "\"v1.0\"",
+   "SPIRV Addressing Model.">,
+ListOption<"spirvCapabilities", "caps", "std::string",
+   "List of required SPIRV Capabilities">,
+ListOption<"spirvExtensions", "exts", "std::string",
+   "List of required SPIRV Extensions">,
+Option<"clientApi", "client_api", "std::string",
+   /*default=*/ "\"Unknown\"",
+   "Client API">,
+Option<"deviceVendor", "vendor", "std::string",
+   /*default=*/ "\"Unknown\"",
+   "Device Vendor">,
+Option<"deviceType", "device_type", "std::string",
+   /*default=*/ "\"Unknown\"",
+   "Device Type">,
+Option<"deviceId", "device_id", "uint32_t",
+   /*default=*/ "mlir::spirv::TargetEnvAttr::kUnknownDeviceID",
+   "Device ID">,
+  ];
+}
+
 #endif // MLIR_DIALECT_GPU_PASSES
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVAttributes.h 
b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVAttributes.h
index 1d304610a03a8dc..3b914dc4cc82f11 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVAttributes.h
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVAttributes.h
@@ -17,6 +17,12 @@
 #include "mlir/IR/BuiltinAttributes.h"
 #include "mlir/Support/LLVM.h"
 
+namespace mlir 

[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-30 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 edited https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-30 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 edited https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-30 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 edited https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-30 Thread Sang Ik Lee via cfe-commits


@@ -108,6 +138,25 @@ void GPUToSPIRVPass::runOnOperation() {
 if (failed(applyFullConversion(gpuModule, *target, std::move(patterns
   return signalPassFailure();
   }
+
+  // For OpenCL, the gpu.func op in the original gpu.module op needs to be

silee2 wrote:

Keeping the original gpu.func causes legality check error later in the gpu 
compile pipeline. 
If target attr is set for a gpu.module, gpu-to-llvm pass doesn't lower 
gpu.launch_func 
Instead, it is replaced with another gpu.launch_func that has lowered argument 
types (llvm ptrs).
If a gpu.func remains as an input to gpu-to-llvm pass, there is an argument 
mismatch between the new gpu.launch_func and the gpu.func. And a error is fired.
The reason for putting a dummy func.func here is to work around that check.
For func types other than gpu.func, argument types are not checked against 
gpu.launch_func.
But a func.func is still need as there will be a symbol check.


https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-30 Thread Sang Ik Lee via cfe-commits


@@ -108,6 +138,25 @@ void GPUToSPIRVPass::runOnOperation() {
 if (failed(applyFullConversion(gpuModule, *target, std::move(patterns
   return signalPassFailure();
   }
+
+  // For OpenCL, the gpu.func op in the original gpu.module op needs to be

silee2 wrote:

Keeping the original gpu.func causes legality check error later in the gpu 
compile pipeline. 
If target attr is set for a gpu.module, gpu-to-llvm pass doesn't lower 
gpu.launch_func 
Instead, it is replaced with another gpu.launch_func that has lowered argument 
types (llvm ptrs).
If a gpu.func remains as an input to gpu-to-llvm pass, there is an argument 
mismatch between the new gpu.launch_func and the gpu.func. And a error is fired.
The reason for putting a dummy func.func here is to work around that check.
For func types other than gpu.func, argument types are not checked against 
gpu.launch_func.
But a func.func is still need as there will be a symbol check.


https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-30 Thread Sang Ik Lee via cfe-commits


@@ -54,22 +55,52 @@ void GPUToSPIRVPass::runOnOperation() {
 
   SmallVector gpuModules;
   OpBuilder builder(context);
+
+  auto targetEnvSupportsKernelCapability = [](gpu::GPUModuleOp moduleOp) {
+Operation *gpuModule = moduleOp.getOperation();
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+spirv::TargetEnv targetEnv(targetAttr);
+return targetEnv.allows(spirv::Capability::Kernel);
+  };
+
   module.walk([&](gpu::GPUModuleOp moduleOp) {
 // Clone each GPU kernel module for conversion, given that the GPU
 // launch op still needs the original GPU kernel module.
-builder.setInsertionPoint(moduleOp.getOperation());
+// For Vulkan Shader capabilities, we insert the newly converted SPIR-V
+// module right after the original GPU module, as that's the expectation of
+// the in-tree Vulkan runner.
+// For OpenCL Kernel capabilities, we insert the newly converted SPIR-V
+// module inside the original GPU module, as that's the expectaion of the
+// normal GPU compilation pipeline.
+if (targetEnvSupportsKernelCapability(moduleOp)) {
+  builder.setInsertionPoint(moduleOp.getBody(),
+moduleOp.getBody()->begin());
+} else {
+  builder.setInsertionPoint(moduleOp.getOperation());
+}
 gpuModules.push_back(builder.clone(*moduleOp.getOperation()));
   });
 
   // Run conversion for each module independently as they can have different
   // TargetEnv attributes.
   for (Operation *gpuModule : gpuModules) {
+spirv::TargetEnvAttr targetAttr =
+spirv::lookupTargetEnvOrDefault(gpuModule);
+
 // Map MemRef memory space to SPIR-V storage class first if requested.
 if (mapMemorySpace) {
+  spirv::TargetEnv targetEnv(targetAttr);
+  FailureOr memoryModel =
+  spirv::getMemoryModel(targetEnv);
+  if (failed(memoryModel))
+return signalPassFailure();
+
   std::unique_ptr target =
   spirv::getMemorySpaceToStorageClassTarget(*context);
   spirv::MemorySpaceToStorageClassMap memorySpaceMap =
-  spirv::mapMemorySpaceToVulkanStorageClass;
+  (memoryModel == spirv::MemoryModel::OpenCL)

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-30 Thread Sang Ik Lee via cfe-commits


@@ -54,22 +55,52 @@ void GPUToSPIRVPass::runOnOperation() {
 
   SmallVector gpuModules;
   OpBuilder builder(context);
+
+  auto targetEnvSupportsKernelCapability = [](gpu::GPUModuleOp moduleOp) {
+Operation *gpuModule = moduleOp.getOperation();
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+spirv::TargetEnv targetEnv(targetAttr);
+return targetEnv.allows(spirv::Capability::Kernel);
+  };
+
   module.walk([&](gpu::GPUModuleOp moduleOp) {
 // Clone each GPU kernel module for conversion, given that the GPU
 // launch op still needs the original GPU kernel module.
-builder.setInsertionPoint(moduleOp.getOperation());
+// For Vulkan Shader capabilities, we insert the newly converted SPIR-V
+// module right after the original GPU module, as that's the expectation of
+// the in-tree Vulkan runner.
+// For OpenCL Kernel capabilities, we insert the newly converted SPIR-V
+// module inside the original GPU module, as that's the expectaion of the
+// normal GPU compilation pipeline.
+if (targetEnvSupportsKernelCapability(moduleOp)) {
+  builder.setInsertionPoint(moduleOp.getBody(),
+moduleOp.getBody()->begin());
+} else {
+  builder.setInsertionPoint(moduleOp.getOperation());
+}
 gpuModules.push_back(builder.clone(*moduleOp.getOperation()));
   });
 
   // Run conversion for each module independently as they can have different
   // TargetEnv attributes.
   for (Operation *gpuModule : gpuModules) {
+spirv::TargetEnvAttr targetAttr =
+spirv::lookupTargetEnvOrDefault(gpuModule);
+
 // Map MemRef memory space to SPIR-V storage class first if requested.
 if (mapMemorySpace) {
+  spirv::TargetEnv targetEnv(targetAttr);
+  FailureOr memoryModel =
+  spirv::getMemoryModel(targetEnv);
+  if (failed(memoryModel))
+return signalPassFailure();
+
   std::unique_ptr target =
   spirv::getMemorySpaceToStorageClassTarget(*context);
   spirv::MemorySpaceToStorageClassMap memorySpaceMap =
-  spirv::mapMemorySpaceToVulkanStorageClass;
+  (memoryModel == spirv::MemoryModel::OpenCL)

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-30 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 updated 
https://github.com/llvm/llvm-project/pull/69941

>From 7ca3f97b5ee6e5cefd94afd3b090d0dba2120cea Mon Sep 17 00:00:00 2001
From: "Lee, Sang Ik" 
Date: Mon, 23 Oct 2023 16:25:15 +
Subject: [PATCH 1/7] [MLIR] Update convert-gpu-to-spirv pass to prepare using
 GPU compilation pipeline for OpenCL kernels.

This includes a couple of changes to pass behavior for OpenCL kernels.
Vulkan shaders are not impacted by the changes.

1. SPIRV module is placed inside GPU module. This change is required for
gpu-module-to-binary to work correctly as it expects kernel function to be
inside the GPU module.
2. A dummy func.func with same kernel name as gpu.func is created.
GPU compilation pipeline defers lowering of gpu launch kernel op.
Since spirv.func is not directly tied to gpu launch kernel,
a dummy func.func is required to avoid legalization issues.
3. Use correct mapping when mapping MemRef memory space to SPIR-V storage class 
for OpenCL kernels.
---
 mlir/include/mlir/Conversion/Passes.td|  5 +-
 .../Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp  | 76 ---
 .../Conversion/GPUToSPIRV/module-opencl.mlir  |  4 +
 3 files changed, 75 insertions(+), 10 deletions(-)

diff --git a/mlir/include/mlir/Conversion/Passes.td 
b/mlir/include/mlir/Conversion/Passes.td
index 274784fe4a7b29c..652ef5ad95158ca 100644
--- a/mlir/include/mlir/Conversion/Passes.td
+++ b/mlir/include/mlir/Conversion/Passes.td
@@ -578,7 +578,10 @@ def ConvertGPUToSPIRV : Pass<"convert-gpu-to-spirv", 
"ModuleOp"> {
 to control the set and binding if wanted.
   }];
   let constructor = "mlir::createConvertGPUToSPIRVPass()";
-  let dependentDialects = ["spirv::SPIRVDialect"];
+  let dependentDialects = [
+"spirv::SPIRVDialect",
+"func::FuncDialect",
+  ];
   let options = [
 Option<"use64bitIndex", "use-64bit-index",
"bool", /*default=*/"false",
diff --git a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp 
b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp
index 272e3de8723aeb6..35ee0d7038a2c9a 100644
--- a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp
+++ b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp
@@ -17,6 +17,7 @@
 #include "mlir/Conversion/FuncToSPIRV/FuncToSPIRV.h"
 #include "mlir/Conversion/GPUToSPIRV/GPUToSPIRV.h"
 #include "mlir/Conversion/MemRefToSPIRV/MemRefToSPIRV.h"
+#include "mlir/Dialect/Func/IR/FuncOps.h"
 #include "mlir/Dialect/GPU/IR/GPUDialect.h"
 #include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
 #include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
@@ -54,22 +55,63 @@ void GPUToSPIRVPass::runOnOperation() {
 
   SmallVector gpuModules;
   OpBuilder builder(context);
+
+  auto getTargetEnvFromGPUModuleOp = [=](gpu::GPUModuleOp moduleOp) {
+Operation *gpuModule = moduleOp.getOperation();
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();
+return targetEnv;
+  };
+
   module.walk([&](gpu::GPUModuleOp moduleOp) {
 // Clone each GPU kernel module for conversion, given that the GPU
 // launch op still needs the original GPU kernel module.
-builder.setInsertionPoint(moduleOp.getOperation());
+// SPIRV module insertion point by is after original GPU module.
+// This works fine for Vulkan shader that has a dedicated runner.
+// But OpenCL kernel needs SPIRV module placed inside original GPU module 
as
+// OpenCL uses GPU compilation pipeline.
+auto targetEnv = getTargetEnvFromGPUModuleOp(moduleOp);
+FailureOr memoryModel =
+spirv::getMemoryModel(targetEnv);
+if (failed(memoryModel))
+  return signalPassFailure();
+(memoryModel == spirv::MemoryModel::OpenCL)
+? builder.setInsertionPoint(moduleOp.getBody(),
+moduleOp.getBody()->begin())
+: builder.setInsertionPoint(moduleOp.getOperation());
 gpuModules.push_back(builder.clone(*moduleOp.getOperation()));
   });
 
   // Run conversion for each module independently as they can have different
   // TargetEnv attributes.
   for (Operation *gpuModule : gpuModules) {
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();
+FailureOr memoryModel =
+spirv::getMemoryModel(targetEnv);
+if (failed(memoryModel))
+  return signalPassFailure();
+
 // Map MemRef memory space to SPIR-V storage class first if requested.
 if (mapMemorySpace) {
   std::unique_ptr target =
   

[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -54,22 +55,67 @@ void GPUToSPIRVPass::runOnOperation() {
 
   SmallVector gpuModules;
   OpBuilder builder(context);
+
+  auto getTargetEnvFromGPUModuleOp = [*this](gpu::GPUModuleOp moduleOp) {
+Operation *gpuModule = moduleOp.getOperation();
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();
+return targetEnv;
+  };
+
   module.walk([&](gpu::GPUModuleOp moduleOp) {
 // Clone each GPU kernel module for conversion, given that the GPU
 // launch op still needs the original GPU kernel module.
-builder.setInsertionPoint(moduleOp.getOperation());
+// SPIRV module insertion point by is after original GPU module.
+// This works fine for Vulkan shader that has a dedicated runner.
+// But OpenCL kernel needs SPIRV module placed inside original GPU module 
as

silee2 wrote:

I don't know. My goal was to make no change to existing Vulkan workflow. 

https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -54,22 +55,67 @@ void GPUToSPIRVPass::runOnOperation() {
 
   SmallVector gpuModules;
   OpBuilder builder(context);
+
+  auto getTargetEnvFromGPUModuleOp = [*this](gpu::GPUModuleOp moduleOp) {
+Operation *gpuModule = moduleOp.getOperation();
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();
+return targetEnv;
+  };
+
   module.walk([&](gpu::GPUModuleOp moduleOp) {
 // Clone each GPU kernel module for conversion, given that the GPU
 // launch op still needs the original GPU kernel module.
-builder.setInsertionPoint(moduleOp.getOperation());
+// SPIRV module insertion point by is after original GPU module.
+// This works fine for Vulkan shader that has a dedicated runner.
+// But OpenCL kernel needs SPIRV module placed inside original GPU module 
as
+// OpenCL uses GPU compilation pipeline.
+const mlir::spirv::TargetEnv  =
+getTargetEnvFromGPUModuleOp(moduleOp);
+FailureOr memoryModel =
+spirv::getMemoryModel(targetEnv);
+if (failed(memoryModel))
+  return signalPassFailure();
+if (memoryModel == spirv::MemoryModel::OpenCL) {
+  builder.setInsertionPoint(moduleOp.getBody(),
+moduleOp.getBody()->begin());
+} else {
+  builder.setInsertionPoint(moduleOp.getOperation());
+}
 gpuModules.push_back(builder.clone(*moduleOp.getOperation()));
   });
 
   // Run conversion for each module independently as they can have different
   // TargetEnv attributes.
   for (Operation *gpuModule : gpuModules) {
+mlir::spirv::TargetEnvAttr targetAttr =

silee2 wrote:

Now the lambda returns boolean and cannot be used. Also that line is from the 
original code. I just moved it up a bit since I needed access to targetAttr 
before memory space mapping.

https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -54,22 +55,67 @@ void GPUToSPIRVPass::runOnOperation() {
 
   SmallVector gpuModules;
   OpBuilder builder(context);
+
+  auto getTargetEnvFromGPUModuleOp = [*this](gpu::GPUModuleOp moduleOp) {
+Operation *gpuModule = moduleOp.getOperation();
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();
+return targetEnv;
+  };
+
   module.walk([&](gpu::GPUModuleOp moduleOp) {
 // Clone each GPU kernel module for conversion, given that the GPU
 // launch op still needs the original GPU kernel module.
-builder.setInsertionPoint(moduleOp.getOperation());
+// SPIRV module insertion point by is after original GPU module.
+// This works fine for Vulkan shader that has a dedicated runner.
+// But OpenCL kernel needs SPIRV module placed inside original GPU module 
as
+// OpenCL uses GPU compilation pipeline.
+const mlir::spirv::TargetEnv  =
+getTargetEnvFromGPUModuleOp(moduleOp);
+FailureOr memoryModel =

silee2 wrote:

That is a great idea. Thanks! Updated the lambda.


https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -108,6 +147,31 @@ void GPUToSPIRVPass::runOnOperation() {
 if (failed(applyFullConversion(gpuModule, *target, std::move(patterns
   return signalPassFailure();
   }
+
+  // In case of OpenCL, gpu.func in original gpu.module needs to replaced with

silee2 wrote:

Updated comment.

https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -54,22 +55,67 @@ void GPUToSPIRVPass::runOnOperation() {
 
   SmallVector gpuModules;
   OpBuilder builder(context);
+
+  auto getTargetEnvFromGPUModuleOp = [*this](gpu::GPUModuleOp moduleOp) {
+Operation *gpuModule = moduleOp.getOperation();
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();
+return targetEnv;
+  };
+
   module.walk([&](gpu::GPUModuleOp moduleOp) {
 // Clone each GPU kernel module for conversion, given that the GPU
 // launch op still needs the original GPU kernel module.
-builder.setInsertionPoint(moduleOp.getOperation());
+// SPIRV module insertion point by is after original GPU module.
+// This works fine for Vulkan shader that has a dedicated runner.

silee2 wrote:

Thank for the suggestion. Updated comment.

https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -54,22 +55,67 @@ void GPUToSPIRVPass::runOnOperation() {
 
   SmallVector gpuModules;
   OpBuilder builder(context);
+
+  auto getTargetEnvFromGPUModuleOp = [*this](gpu::GPUModuleOp moduleOp) {
+Operation *gpuModule = moduleOp.getOperation();
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();

silee2 wrote:

Thanks! That simplifies the code a lot.

https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -54,22 +55,67 @@ void GPUToSPIRVPass::runOnOperation() {
 
   SmallVector gpuModules;
   OpBuilder builder(context);
+
+  auto getTargetEnvFromGPUModuleOp = [*this](gpu::GPUModuleOp moduleOp) {
+Operation *gpuModule = moduleOp.getOperation();
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =

silee2 wrote:

Removed usage of target.

https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -54,22 +55,67 @@ void GPUToSPIRVPass::runOnOperation() {
 
   SmallVector gpuModules;
   OpBuilder builder(context);
+
+  auto getTargetEnvFromGPUModuleOp = [*this](gpu::GPUModuleOp moduleOp) {
+Operation *gpuModule = moduleOp.getOperation();
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();
+return targetEnv;
+  };
+
   module.walk([&](gpu::GPUModuleOp moduleOp) {
 // Clone each GPU kernel module for conversion, given that the GPU
 // launch op still needs the original GPU kernel module.
-builder.setInsertionPoint(moduleOp.getOperation());
+// SPIRV module insertion point by is after original GPU module.

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -54,22 +55,67 @@ void GPUToSPIRVPass::runOnOperation() {
 
   SmallVector gpuModules;
   OpBuilder builder(context);
+
+  auto getTargetEnvFromGPUModuleOp = [*this](gpu::GPUModuleOp moduleOp) {
+Operation *gpuModule = moduleOp.getOperation();
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();
+return targetEnv;
+  };
+
   module.walk([&](gpu::GPUModuleOp moduleOp) {
 // Clone each GPU kernel module for conversion, given that the GPU
 // launch op still needs the original GPU kernel module.
-builder.setInsertionPoint(moduleOp.getOperation());
+// SPIRV module insertion point by is after original GPU module.

silee2 wrote:

Done.

https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -143,11 +145,12 @@ void GPUToSPIRVPass::runOnOperation() {
 if (failed(applyFullConversion(gpuModule, *target, std::move(patterns
   return signalPassFailure();
   }
+
   // In case of OpenCL, gpu.func in original gpu.module needs to replaced with
   // an empty func.func with same arguments as gpu.func. And it also needs
   // gpu.kernel attribute set.
   module.walk([&](gpu::GPUModuleOp moduleOp) {
-auto targetEnv = getTargetEnvFromGPUModuleOp(moduleOp);
+const mlir::spirv::TargetEnv& targetEnv = 
getTargetEnvFromGPUModuleOp(moduleOp);

silee2 wrote:

Removed mlir::

https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -143,11 +145,12 @@ void GPUToSPIRVPass::runOnOperation() {
 if (failed(applyFullConversion(gpuModule, *target, std::move(patterns
   return signalPassFailure();
   }
+
   // In case of OpenCL, gpu.func in original gpu.module needs to replaced with
   // an empty func.func with same arguments as gpu.func. And it also needs
   // gpu.kernel attribute set.
   module.walk([&](gpu::GPUModuleOp moduleOp) {
-auto targetEnv = getTargetEnvFromGPUModuleOp(moduleOp);
+const mlir::spirv::TargetEnv& targetEnv = 
getTargetEnvFromGPUModuleOp(moduleOp);

silee2 wrote:

Removed mlir::

https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -76,22 +76,24 @@ void GPUToSPIRVPass::runOnOperation() {
 // This works fine for Vulkan shader that has a dedicated runner.
 // But OpenCL kernel needs SPIRV module placed inside original GPU module 
as
 // OpenCL uses GPU compilation pipeline.
-auto targetEnv = getTargetEnvFromGPUModuleOp(moduleOp);
+const mlir::spirv::TargetEnv& targetEnv = 
getTargetEnvFromGPUModuleOp(moduleOp);
 FailureOr memoryModel =
 spirv::getMemoryModel(targetEnv);
 if (failed(memoryModel))
   return signalPassFailure();
-(memoryModel == spirv::MemoryModel::OpenCL)
-? builder.setInsertionPoint(moduleOp.getBody(),
-moduleOp.getBody()->begin())
-: builder.setInsertionPoint(moduleOp.getOperation());
+if (memoryModel == spirv::MemoryModel::OpenCL) {
+  builder.setInsertionPoint(moduleOp.getBody(),
+moduleOp.getBody()->begin());
+} else {
+  builder.setInsertionPoint(moduleOp.getOperation());
+}
 gpuModules.push_back(builder.clone(*moduleOp.getOperation()));
   });
 
   // Run conversion for each module independently as they can have different
   // TargetEnv attributes.
   for (Operation *gpuModule : gpuModules) {
-auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+mlir::spirv::TargetEnvAttr targetAttr = 
spirv::lookupTargetEnvOrDefault(gpuModule);

silee2 wrote:

Removed mlir::

https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -76,22 +76,24 @@ void GPUToSPIRVPass::runOnOperation() {
 // This works fine for Vulkan shader that has a dedicated runner.
 // But OpenCL kernel needs SPIRV module placed inside original GPU module 
as
 // OpenCL uses GPU compilation pipeline.
-auto targetEnv = getTargetEnvFromGPUModuleOp(moduleOp);
+const mlir::spirv::TargetEnv& targetEnv = 
getTargetEnvFromGPUModuleOp(moduleOp);
 FailureOr memoryModel =
 spirv::getMemoryModel(targetEnv);
 if (failed(memoryModel))
   return signalPassFailure();
-(memoryModel == spirv::MemoryModel::OpenCL)
-? builder.setInsertionPoint(moduleOp.getBody(),
-moduleOp.getBody()->begin())
-: builder.setInsertionPoint(moduleOp.getOperation());
+if (memoryModel == spirv::MemoryModel::OpenCL) {
+  builder.setInsertionPoint(moduleOp.getBody(),
+moduleOp.getBody()->begin());
+} else {
+  builder.setInsertionPoint(moduleOp.getOperation());
+}
 gpuModules.push_back(builder.clone(*moduleOp.getOperation()));
   });
 
   // Run conversion for each module independently as they can have different
   // TargetEnv attributes.
   for (Operation *gpuModule : gpuModules) {
-auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+mlir::spirv::TargetEnvAttr targetAttr = 
spirv::lookupTargetEnvOrDefault(gpuModule);

silee2 wrote:

Removed mlir::

https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -76,22 +76,24 @@ void GPUToSPIRVPass::runOnOperation() {
 // This works fine for Vulkan shader that has a dedicated runner.
 // But OpenCL kernel needs SPIRV module placed inside original GPU module 
as
 // OpenCL uses GPU compilation pipeline.
-auto targetEnv = getTargetEnvFromGPUModuleOp(moduleOp);
+const mlir::spirv::TargetEnv& targetEnv = 
getTargetEnvFromGPUModuleOp(moduleOp);

silee2 wrote:

Removed mlir::

https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits


@@ -76,22 +76,24 @@ void GPUToSPIRVPass::runOnOperation() {
 // This works fine for Vulkan shader that has a dedicated runner.
 // But OpenCL kernel needs SPIRV module placed inside original GPU module 
as
 // OpenCL uses GPU compilation pipeline.
-auto targetEnv = getTargetEnvFromGPUModuleOp(moduleOp);
+const mlir::spirv::TargetEnv& targetEnv = 
getTargetEnvFromGPUModuleOp(moduleOp);

silee2 wrote:

Removed mlir::

https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 updated 
https://github.com/llvm/llvm-project/pull/69941

>From 7ca3f97b5ee6e5cefd94afd3b090d0dba2120cea Mon Sep 17 00:00:00 2001
From: "Lee, Sang Ik" 
Date: Mon, 23 Oct 2023 16:25:15 +
Subject: [PATCH 1/6] [MLIR] Update convert-gpu-to-spirv pass to prepare using
 GPU compilation pipeline for OpenCL kernels.

This includes a couple of changes to pass behavior for OpenCL kernels.
Vulkan shaders are not impacted by the changes.

1. SPIRV module is placed inside GPU module. This change is required for
gpu-module-to-binary to work correctly as it expects kernel function to be
inside the GPU module.
2. A dummy func.func with same kernel name as gpu.func is created.
GPU compilation pipeline defers lowering of gpu launch kernel op.
Since spirv.func is not directly tied to gpu launch kernel,
a dummy func.func is required to avoid legalization issues.
3. Use correct mapping when mapping MemRef memory space to SPIR-V storage class 
for OpenCL kernels.
---
 mlir/include/mlir/Conversion/Passes.td|  5 +-
 .../Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp  | 76 ---
 .../Conversion/GPUToSPIRV/module-opencl.mlir  |  4 +
 3 files changed, 75 insertions(+), 10 deletions(-)

diff --git a/mlir/include/mlir/Conversion/Passes.td 
b/mlir/include/mlir/Conversion/Passes.td
index 274784fe4a7b29c..652ef5ad95158ca 100644
--- a/mlir/include/mlir/Conversion/Passes.td
+++ b/mlir/include/mlir/Conversion/Passes.td
@@ -578,7 +578,10 @@ def ConvertGPUToSPIRV : Pass<"convert-gpu-to-spirv", 
"ModuleOp"> {
 to control the set and binding if wanted.
   }];
   let constructor = "mlir::createConvertGPUToSPIRVPass()";
-  let dependentDialects = ["spirv::SPIRVDialect"];
+  let dependentDialects = [
+"spirv::SPIRVDialect",
+"func::FuncDialect",
+  ];
   let options = [
 Option<"use64bitIndex", "use-64bit-index",
"bool", /*default=*/"false",
diff --git a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp 
b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp
index 272e3de8723aeb6..35ee0d7038a2c9a 100644
--- a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp
+++ b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp
@@ -17,6 +17,7 @@
 #include "mlir/Conversion/FuncToSPIRV/FuncToSPIRV.h"
 #include "mlir/Conversion/GPUToSPIRV/GPUToSPIRV.h"
 #include "mlir/Conversion/MemRefToSPIRV/MemRefToSPIRV.h"
+#include "mlir/Dialect/Func/IR/FuncOps.h"
 #include "mlir/Dialect/GPU/IR/GPUDialect.h"
 #include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
 #include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
@@ -54,22 +55,63 @@ void GPUToSPIRVPass::runOnOperation() {
 
   SmallVector gpuModules;
   OpBuilder builder(context);
+
+  auto getTargetEnvFromGPUModuleOp = [=](gpu::GPUModuleOp moduleOp) {
+Operation *gpuModule = moduleOp.getOperation();
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();
+return targetEnv;
+  };
+
   module.walk([&](gpu::GPUModuleOp moduleOp) {
 // Clone each GPU kernel module for conversion, given that the GPU
 // launch op still needs the original GPU kernel module.
-builder.setInsertionPoint(moduleOp.getOperation());
+// SPIRV module insertion point by is after original GPU module.
+// This works fine for Vulkan shader that has a dedicated runner.
+// But OpenCL kernel needs SPIRV module placed inside original GPU module 
as
+// OpenCL uses GPU compilation pipeline.
+auto targetEnv = getTargetEnvFromGPUModuleOp(moduleOp);
+FailureOr memoryModel =
+spirv::getMemoryModel(targetEnv);
+if (failed(memoryModel))
+  return signalPassFailure();
+(memoryModel == spirv::MemoryModel::OpenCL)
+? builder.setInsertionPoint(moduleOp.getBody(),
+moduleOp.getBody()->begin())
+: builder.setInsertionPoint(moduleOp.getOperation());
 gpuModules.push_back(builder.clone(*moduleOp.getOperation()));
   });
 
   // Run conversion for each module independently as they can have different
   // TargetEnv attributes.
   for (Operation *gpuModule : gpuModules) {
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();
+FailureOr memoryModel =
+spirv::getMemoryModel(targetEnv);
+if (failed(memoryModel))
+  return signalPassFailure();
+
 // Map MemRef memory space to SPIR-V storage class first if requested.
 if (mapMemorySpace) {
   std::unique_ptr target =
   

[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 updated 
https://github.com/llvm/llvm-project/pull/69941

>From 7ca3f97b5ee6e5cefd94afd3b090d0dba2120cea Mon Sep 17 00:00:00 2001
From: "Lee, Sang Ik" 
Date: Mon, 23 Oct 2023 16:25:15 +
Subject: [PATCH 1/5] [MLIR] Update convert-gpu-to-spirv pass to prepare using
 GPU compilation pipeline for OpenCL kernels.

This includes a couple of changes to pass behavior for OpenCL kernels.
Vulkan shaders are not impacted by the changes.

1. SPIRV module is placed inside GPU module. This change is required for
gpu-module-to-binary to work correctly as it expects kernel function to be
inside the GPU module.
2. A dummy func.func with same kernel name as gpu.func is created.
GPU compilation pipeline defers lowering of gpu launch kernel op.
Since spirv.func is not directly tied to gpu launch kernel,
a dummy func.func is required to avoid legalization issues.
3. Use correct mapping when mapping MemRef memory space to SPIR-V storage class 
for OpenCL kernels.
---
 mlir/include/mlir/Conversion/Passes.td|  5 +-
 .../Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp  | 76 ---
 .../Conversion/GPUToSPIRV/module-opencl.mlir  |  4 +
 3 files changed, 75 insertions(+), 10 deletions(-)

diff --git a/mlir/include/mlir/Conversion/Passes.td 
b/mlir/include/mlir/Conversion/Passes.td
index 274784fe4a7b29c..652ef5ad95158ca 100644
--- a/mlir/include/mlir/Conversion/Passes.td
+++ b/mlir/include/mlir/Conversion/Passes.td
@@ -578,7 +578,10 @@ def ConvertGPUToSPIRV : Pass<"convert-gpu-to-spirv", 
"ModuleOp"> {
 to control the set and binding if wanted.
   }];
   let constructor = "mlir::createConvertGPUToSPIRVPass()";
-  let dependentDialects = ["spirv::SPIRVDialect"];
+  let dependentDialects = [
+"spirv::SPIRVDialect",
+"func::FuncDialect",
+  ];
   let options = [
 Option<"use64bitIndex", "use-64bit-index",
"bool", /*default=*/"false",
diff --git a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp 
b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp
index 272e3de8723aeb6..35ee0d7038a2c9a 100644
--- a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp
+++ b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp
@@ -17,6 +17,7 @@
 #include "mlir/Conversion/FuncToSPIRV/FuncToSPIRV.h"
 #include "mlir/Conversion/GPUToSPIRV/GPUToSPIRV.h"
 #include "mlir/Conversion/MemRefToSPIRV/MemRefToSPIRV.h"
+#include "mlir/Dialect/Func/IR/FuncOps.h"
 #include "mlir/Dialect/GPU/IR/GPUDialect.h"
 #include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
 #include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
@@ -54,22 +55,63 @@ void GPUToSPIRVPass::runOnOperation() {
 
   SmallVector gpuModules;
   OpBuilder builder(context);
+
+  auto getTargetEnvFromGPUModuleOp = [=](gpu::GPUModuleOp moduleOp) {
+Operation *gpuModule = moduleOp.getOperation();
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();
+return targetEnv;
+  };
+
   module.walk([&](gpu::GPUModuleOp moduleOp) {
 // Clone each GPU kernel module for conversion, given that the GPU
 // launch op still needs the original GPU kernel module.
-builder.setInsertionPoint(moduleOp.getOperation());
+// SPIRV module insertion point by is after original GPU module.
+// This works fine for Vulkan shader that has a dedicated runner.
+// But OpenCL kernel needs SPIRV module placed inside original GPU module 
as
+// OpenCL uses GPU compilation pipeline.
+auto targetEnv = getTargetEnvFromGPUModuleOp(moduleOp);
+FailureOr memoryModel =
+spirv::getMemoryModel(targetEnv);
+if (failed(memoryModel))
+  return signalPassFailure();
+(memoryModel == spirv::MemoryModel::OpenCL)
+? builder.setInsertionPoint(moduleOp.getBody(),
+moduleOp.getBody()->begin())
+: builder.setInsertionPoint(moduleOp.getOperation());
 gpuModules.push_back(builder.clone(*moduleOp.getOperation()));
   });
 
   // Run conversion for each module independently as they can have different
   // TargetEnv attributes.
   for (Operation *gpuModule : gpuModules) {
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();
+FailureOr memoryModel =
+spirv::getMemoryModel(targetEnv);
+if (failed(memoryModel))
+  return signalPassFailure();
+
 // Map MemRef memory space to SPIR-V storage class first if requested.
 if (mapMemorySpace) {
   std::unique_ptr target =
   

[clang] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-27 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 updated 
https://github.com/llvm/llvm-project/pull/69941

>From 7ca3f97b5ee6e5cefd94afd3b090d0dba2120cea Mon Sep 17 00:00:00 2001
From: "Lee, Sang Ik" 
Date: Mon, 23 Oct 2023 16:25:15 +
Subject: [PATCH 1/5] [MLIR] Update convert-gpu-to-spirv pass to prepare using
 GPU compilation pipeline for OpenCL kernels.

This includes a couple of changes to pass behavior for OpenCL kernels.
Vulkan shaders are not impacted by the changes.

1. SPIRV module is placed inside GPU module. This change is required for
gpu-module-to-binary to work correctly as it expects kernel function to be
inside the GPU module.
2. A dummy func.func with same kernel name as gpu.func is created.
GPU compilation pipeline defers lowering of gpu launch kernel op.
Since spirv.func is not directly tied to gpu launch kernel,
a dummy func.func is required to avoid legalization issues.
3. Use correct mapping when mapping MemRef memory space to SPIR-V storage class 
for OpenCL kernels.
---
 mlir/include/mlir/Conversion/Passes.td|  5 +-
 .../Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp  | 76 ---
 .../Conversion/GPUToSPIRV/module-opencl.mlir  |  4 +
 3 files changed, 75 insertions(+), 10 deletions(-)

diff --git a/mlir/include/mlir/Conversion/Passes.td 
b/mlir/include/mlir/Conversion/Passes.td
index 274784fe4a7b29c..652ef5ad95158ca 100644
--- a/mlir/include/mlir/Conversion/Passes.td
+++ b/mlir/include/mlir/Conversion/Passes.td
@@ -578,7 +578,10 @@ def ConvertGPUToSPIRV : Pass<"convert-gpu-to-spirv", 
"ModuleOp"> {
 to control the set and binding if wanted.
   }];
   let constructor = "mlir::createConvertGPUToSPIRVPass()";
-  let dependentDialects = ["spirv::SPIRVDialect"];
+  let dependentDialects = [
+"spirv::SPIRVDialect",
+"func::FuncDialect",
+  ];
   let options = [
 Option<"use64bitIndex", "use-64bit-index",
"bool", /*default=*/"false",
diff --git a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp 
b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp
index 272e3de8723aeb6..35ee0d7038a2c9a 100644
--- a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp
+++ b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp
@@ -17,6 +17,7 @@
 #include "mlir/Conversion/FuncToSPIRV/FuncToSPIRV.h"
 #include "mlir/Conversion/GPUToSPIRV/GPUToSPIRV.h"
 #include "mlir/Conversion/MemRefToSPIRV/MemRefToSPIRV.h"
+#include "mlir/Dialect/Func/IR/FuncOps.h"
 #include "mlir/Dialect/GPU/IR/GPUDialect.h"
 #include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
 #include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
@@ -54,22 +55,63 @@ void GPUToSPIRVPass::runOnOperation() {
 
   SmallVector gpuModules;
   OpBuilder builder(context);
+
+  auto getTargetEnvFromGPUModuleOp = [=](gpu::GPUModuleOp moduleOp) {
+Operation *gpuModule = moduleOp.getOperation();
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();
+return targetEnv;
+  };
+
   module.walk([&](gpu::GPUModuleOp moduleOp) {
 // Clone each GPU kernel module for conversion, given that the GPU
 // launch op still needs the original GPU kernel module.
-builder.setInsertionPoint(moduleOp.getOperation());
+// SPIRV module insertion point by is after original GPU module.
+// This works fine for Vulkan shader that has a dedicated runner.
+// But OpenCL kernel needs SPIRV module placed inside original GPU module 
as
+// OpenCL uses GPU compilation pipeline.
+auto targetEnv = getTargetEnvFromGPUModuleOp(moduleOp);
+FailureOr memoryModel =
+spirv::getMemoryModel(targetEnv);
+if (failed(memoryModel))
+  return signalPassFailure();
+(memoryModel == spirv::MemoryModel::OpenCL)
+? builder.setInsertionPoint(moduleOp.getBody(),
+moduleOp.getBody()->begin())
+: builder.setInsertionPoint(moduleOp.getOperation());
 gpuModules.push_back(builder.clone(*moduleOp.getOperation()));
   });
 
   // Run conversion for each module independently as they can have different
   // TargetEnv attributes.
   for (Operation *gpuModule : gpuModules) {
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+std::unique_ptr target =
+SPIRVConversionTarget::get(targetAttr);
+
+SPIRVConversionOptions options;
+options.use64bitIndex = this->use64bitIndex;
+SPIRVTypeConverter typeConverter(targetAttr, options);
+const spirv::TargetEnv  = typeConverter.getTargetEnv();
+FailureOr memoryModel =
+spirv::getMemoryModel(targetEnv);
+if (failed(memoryModel))
+  return signalPassFailure();
+
 // Map MemRef memory space to SPIR-V storage class first if requested.
 if (mapMemorySpace) {
   std::unique_ptr target =
   

[clang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-27 Thread Sang Ik Lee via cfe-commits

silee2 wrote:

@joker-eph This PR got approval from @fabianmcg. What do I need to do next to 
get the PR merged?

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-26 Thread Sang Ik Lee via cfe-commits

silee2 wrote:

check-flang failed on Windows with two unresolved tests. Does not look related 
to this PR. Merging main again to run CI again.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-26 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 updated 
https://github.com/llvm/llvm-project/pull/69949

>From 1a4319cff8d95d5a6a6598f94162be28e56d68a8 Mon Sep 17 00:00:00 2001
From: "Lee, Sang Ik" 
Date: Mon, 23 Oct 2023 17:23:54 +
Subject: [PATCH 1/3] [MLIR] SPIRV Target Attribute

Create SPIRV Target Attribute to enable GPU compilation pipeline.
The Target Attribute is modeled after the existing spriv.target_env
Plan is to use this new attribute to enable GPU compilation pipeline
for OpenCL kernels only.
The changes do not impact Vulkan shaders using milr-vulkan-runner.
New GPU Dialect transform pass spirv-attach-target is implemented for
attaching attribute from CLI.
gpu-module-to-binary pass now works with GPU module that has SPIRV module
with OpenCL kernel functions inside.
---
 .../mlir/Dialect/GPU/Transforms/Passes.h  |   1 +
 .../mlir/Dialect/GPU/Transforms/Passes.td |  42 +++
 .../mlir/Dialect/SPIRV/IR/SPIRVAttributes.h   |   6 +
 .../mlir/Dialect/SPIRV/IR/SPIRVAttributes.td  |  31 +
 mlir/include/mlir/InitAllDialects.h   |   2 +
 mlir/include/mlir/Target/SPIRV/Target.h   |  30 +
 mlir/lib/Dialect/GPU/CMakeLists.txt   |   2 +
 .../Dialect/GPU/Transforms/ModuleToBinary.cpp |   2 +
 .../GPU/Transforms/SPIRVAttachTarget.cpp  |  94 ++
 mlir/lib/Target/SPIRV/CMakeLists.txt  |  13 ++
 mlir/lib/Target/SPIRV/Target.cpp  | 115 ++
 .../Dialect/GPU/module-to-binary-spirv.mlir   |  13 ++
 .../Dialect/GPU/spirv-attach-targets.mlir |   7 ++
 mlir/test/Dialect/SPIRV/IR/target.mlir|  14 +++
 14 files changed, 372 insertions(+)
 create mode 100644 mlir/include/mlir/Target/SPIRV/Target.h
 create mode 100644 mlir/lib/Dialect/GPU/Transforms/SPIRVAttachTarget.cpp
 create mode 100644 mlir/lib/Target/SPIRV/Target.cpp
 create mode 100644 mlir/test/Dialect/GPU/module-to-binary-spirv.mlir
 create mode 100644 mlir/test/Dialect/GPU/spirv-attach-targets.mlir
 create mode 100644 mlir/test/Dialect/SPIRV/IR/target.mlir

diff --git a/mlir/include/mlir/Dialect/GPU/Transforms/Passes.h 
b/mlir/include/mlir/Dialect/GPU/Transforms/Passes.h
index 2a891a7d24f809a..42fa46b0a57bdee 100644
--- a/mlir/include/mlir/Dialect/GPU/Transforms/Passes.h
+++ b/mlir/include/mlir/Dialect/GPU/Transforms/Passes.h
@@ -15,6 +15,7 @@
 
 #include "Utils.h"
 #include "mlir/Dialect/GPU/IR/GPUDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"
 #include "mlir/Pass/Pass.h"
 #include 
 
diff --git a/mlir/include/mlir/Dialect/GPU/Transforms/Passes.td 
b/mlir/include/mlir/Dialect/GPU/Transforms/Passes.td
index 3de8e18851369df..44e3e5b6226bfeb 100644
--- a/mlir/include/mlir/Dialect/GPU/Transforms/Passes.td
+++ b/mlir/include/mlir/Dialect/GPU/Transforms/Passes.td
@@ -188,4 +188,46 @@ def GpuROCDLAttachTarget: Pass<"rocdl-attach-target", ""> {
   ];
 }
 
+def GpuSPIRVAttachTarget: Pass<"spirv-attach-target", ""> {
+  let summary = "Attaches an SPIRV target attribute to a GPU Module.";
+  let description = [{
+This pass searches for all GPU Modules in the immediate regions and 
attaches
+an SPIRV target if the module matches the name specified by the `module` 
argument.
+
+Example:
+```
+// File: in1.mlir:
+gpu.module @nvvm_module_1 {...}
+gpu.module @spirv_module_1 {...}
+// mlir-opt --spirv-attach-target="module=spirv.* ver=v1.0 caps=Kernel" 
in1.mlir
+gpu.module @nvvm_module_1 {...}
+gpu.module @spirv_module_1 [#spirv.target, resource_limits = <>>] {...}
+```
+  }];
+  let options = [
+Option<"moduleMatcher", "module", "std::string",
+   /*default=*/ [{""}],
+   "Regex used to identify the modules to attach the target to.">,
+Option<"spirvVersion", "ver", "std::string",
+   /*default=*/ "\"v1.0\"",
+   "SPIRV Addressing Model.">,
+ListOption<"spirvCapabilities", "caps", "std::string",
+   "List of required SPIRV Capabilities">,
+ListOption<"spirvExtensions", "exts", "std::string",
+   "List of required SPIRV Extensions">,
+Option<"clientApi", "client_api", "std::string",
+   /*default=*/ "\"Unknown\"",
+   "Client API">,
+Option<"deviceVendor", "vendor", "std::string",
+   /*default=*/ "\"Unknown\"",
+   "Device Vendor">,
+Option<"deviceType", "device_type", "std::string",
+   /*default=*/ "\"Unknown\"",
+   "Device Type">,
+Option<"deviceId", "device_id", "uint32_t",
+   /*default=*/ "mlir::spirv::TargetEnvAttr::kUnknownDeviceID",
+   "Device ID">,
+  ];
+}
+
 #endif // MLIR_DIALECT_GPU_PASSES
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVAttributes.h 
b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVAttributes.h
index 1d304610a03a8dc..3b914dc4cc82f11 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVAttributes.h
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVAttributes.h
@@ -17,6 +17,12 @@
 #include "mlir/IR/BuiltinAttributes.h"
 #include "mlir/Support/LLVM.h"
 
+namespace mlir 

[clang-tools-extra] [MLIR] Enabling Intel GPU Integration. (PR #65539)

2023-09-14 Thread Sang Ik Lee via cfe-commits


@@ -71,7 +71,8 @@ void GPUToSPIRVPass::runOnOperation() {
   std::unique_ptr target =
   spirv::getMemorySpaceToStorageClassTarget(*context);
   spirv::MemorySpaceToStorageClassMap memorySpaceMap =
-  spirv::mapMemorySpaceToVulkanStorageClass;
+  this->useOpenCL ? spirv::mapMemorySpaceToOpenCLStorageClass :
+  spirv::mapMemorySpaceToVulkanStorageClass;

silee2 wrote:

Created #66445 which includes the code change and unit-test for covering.

https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] Enabling Intel GPU Integration. (PR #65539)

2023-09-14 Thread Sang Ik Lee via cfe-commits


@@ -71,7 +71,8 @@ void GPUToSPIRVPass::runOnOperation() {
   std::unique_ptr target =
   spirv::getMemorySpaceToStorageClassTarget(*context);
   spirv::MemorySpaceToStorageClassMap memorySpaceMap =
-  spirv::mapMemorySpaceToVulkanStorageClass;
+  this->useOpenCL ? spirv::mapMemorySpaceToOpenCLStorageClass :
+  spirv::mapMemorySpaceToVulkanStorageClass;

silee2 wrote:

Created #66445 which includes the code change and unit-test for covering.

https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] Enabling Intel GPU Integration. (PR #65539)

2023-09-06 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 edited https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] Enabling Intel GPU Integration. (PR #65539)

2023-09-06 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 edited https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Enabling Intel GPU Integration. (PR #65539)

2023-09-06 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 edited https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Enabling Intel GPU Integration. (PR #65539)

2023-09-06 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 edited https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Enabling Intel GPU Integration. (PR #65539)

2023-09-06 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 edited https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Enabling Intel GPU Integration. (PR #65539)

2023-09-06 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 edited https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Enabling Intel GPU Integration. (PR #65539)

2023-09-06 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 edited https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Enabling Intel GPU Integration. (PR #65539)

2023-09-06 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 edited https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Enabling Intel GPU Integration. (PR #65539)

2023-09-06 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 edited https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Enabling Intel GPU Integration. (PR #65539)

2023-09-06 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 edited https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Enabling Intel GPU Integration. (PR #65539)

2023-09-06 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 edited https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Enabling Intel GPU Integration. (PR #65539)

2023-09-06 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 edited https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Enabling Intel GPU Integration. (PR #65539)

2023-09-06 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 edited https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Enabling Intel GPU Integration. (PR #65539)

2023-09-06 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 edited https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Enabling Intel GPU Integration. (PR #65539)

2023-09-06 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 edited https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Enabling Intel GPU Integration. (PR #65539)

2023-09-06 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 edited https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Enabling Intel GPU Integration. (PR #65539)

2023-09-06 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 edited https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Enabling Intel GPU Integration. (PR #65539)

2023-09-06 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 edited https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Enabling Intel GPU Integration. (PR #65539)

2023-09-06 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 edited https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Enabling Intel GPU Integration. (PR #65539)

2023-09-06 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 edited https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Enabling Intel GPU Integration. (PR #65539)

2023-09-06 Thread Sang Ik Lee via cfe-commits

silee2 wrote:

> I suggest to extract `mgpu` interface changes and `serializetoSpirv` pass to 
> 2 separate PRs.

Agree. And the changes are originally from different authors so should be 
splitted.

https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >