[clang] [MLIR] Enabling Intel GPU Integration. (PR #65539)
https://github.com/keryell 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)
@@ -811,8 +812,13 @@ LogicalResult ConvertAllocOpToGpuRuntimeCallPattern::matchAndRewrite( // descriptor. Type elementPtrType = this->getElementPtrType(memRefType); auto stream = adaptor.getAsyncDependencies().front(); + + auto isHostShared = rewriter.create( + loc, llvmInt64Type, rewriter.getI64IntegerAttr(isShared)); + Value allocatedPtr = - allocCallBuilder.create(loc, rewriter, {sizeBytes, stream}).getResult(); + allocCallBuilder.create(loc, rewriter, {sizeBytes, stream, isHostShared}) + .getResult(); keryell wrote: Technically, SYCL provides a more abstract memory management with `sycl::buffer` and `sycl::accessor` defining an implicit asynchronous task graph. The allocation details are left to the implementation, asynchronous or synchronous allocation is left to the implementers. Here the lower-level synchronous USM memory management API of SYCL is used instead, similar to CUDA/HIP memory management. So, should the `async` allocation in the example be synchronous instead? 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)
@@ -811,8 +812,13 @@ LogicalResult ConvertAllocOpToGpuRuntimeCallPattern::matchAndRewrite( // descriptor. Type elementPtrType = this->getElementPtrType(memRefType); auto stream = adaptor.getAsyncDependencies().front(); + + auto isHostShared = rewriter.create( + loc, llvmInt64Type, rewriter.getI64IntegerAttr(isShared)); + Value allocatedPtr = - allocCallBuilder.create(loc, rewriter, {sizeBytes, stream}).getResult(); + allocCallBuilder.create(loc, rewriter, {sizeBytes, stream, isHostShared}) + .getResult(); keryell wrote: Technically, SYCL provides a more abstract memory management with `sycl::buffer` and `sycl::accessor` defining an implicit asynchronous task graph. The allocation details are left to the implementation, asynchronous or synchronous allocation is left to the implementers. Here the lower-level synchronous USM memory management API of SYCL is used instead, similar to CUDA/HIP memory management. So, should the `async` allocation in the example be synchronous instead? 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)
@@ -811,8 +812,13 @@ LogicalResult ConvertAllocOpToGpuRuntimeCallPattern::matchAndRewrite( // descriptor. Type elementPtrType = this->getElementPtrType(memRefType); auto stream = adaptor.getAsyncDependencies().front(); + + auto isHostShared = rewriter.create( + loc, llvmInt64Type, rewriter.getI64IntegerAttr(isShared)); + Value allocatedPtr = - allocCallBuilder.create(loc, rewriter, {sizeBytes, stream}).getResult(); + allocCallBuilder.create(loc, rewriter, {sizeBytes, stream, isHostShared}) + .getResult(); keryell wrote: I guess that if the runtime uses actually synchronous allocation behind the scene and produces an always-ready async token, it works, even if non optimal. 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)
@@ -811,8 +812,13 @@ LogicalResult ConvertAllocOpToGpuRuntimeCallPattern::matchAndRewrite( // descriptor. Type elementPtrType = this->getElementPtrType(memRefType); auto stream = adaptor.getAsyncDependencies().front(); + + auto isHostShared = rewriter.create( + loc, llvmInt64Type, rewriter.getI64IntegerAttr(isShared)); + Value allocatedPtr = - allocCallBuilder.create(loc, rewriter, {sizeBytes, stream}).getResult(); + allocCallBuilder.create(loc, rewriter, {sizeBytes, stream, isHostShared}) + .getResult(); keryell wrote: I guess that if the runtime uses actually synchronous allocation behind the scene and produces an always-ready async token, it works, even if non optimal. 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)
https://github.com/keryell commented: Quite interesting! At some point it would be nice to have some design document or documentation somewhere explaining how all these MLIR runners works, including this one. Globally this PR add a SYCL runner, but it is very specific for Intel Level 0. It would be nice to have in the future some generalization, like SYCL using OpenCL interoperability interface to run the SPIR-V kernels or even native kernels. 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)
@@ -116,6 +116,7 @@ add_definitions(-DMLIR_ROCM_CONVERSIONS_ENABLED=${MLIR_ENABLE_ROCM_CONVERSIONS}) set(MLIR_ENABLE_CUDA_RUNNER 0 CACHE BOOL "Enable building the mlir CUDA runner") set(MLIR_ENABLE_ROCM_RUNNER 0 CACHE BOOL "Enable building the mlir ROCm runner") +set(MLIR_ENABLE_SYCL_RUNNER 0 CACHE BOOL "Enable building the mlir Sycl runner") keryell wrote: Please spell SYCL correctly. ```suggestion set(MLIR_ENABLE_SYCL_RUNNER 0 CACHE BOOL "Enable building the mlir SYCL runner") ``` One could argue that `mlir` should be spelled `MLIR` but the train seems to have left long time ago. :-) 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)
@@ -0,0 +1,223 @@ +//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===// +// +// 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 +// +//===--===// +// +// Implements C wrappers around the sycl runtime library. +// +//===--===// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#ifdef _WIN32 +#define SYCL_RUNTIME_EXPORT __declspec(dllexport) +#else +#define SYCL_RUNTIME_EXPORT +#endif // _WIN32 + +namespace { + +template +auto catchAll(F &&func) { + try { +return func(); + } catch (const std::exception &e) { +fprintf(stdout, "An exception was thrown: %s\n", e.what()); +fflush(stdout); +abort(); + } catch (...) { +fprintf(stdout, "An unknown exception was thrown\n"); +fflush(stdout); +abort(); + } +} + +#define L0_SAFE_CALL(call) \ + { \ +ze_result_t status = (call); \ +if (status != ZE_RESULT_SUCCESS) { \ + fprintf(stdout, "L0 error %d\n", status); \ + fflush(stdout); \ + abort(); \ +} \ + } + +} // namespace + +static sycl::device getDefaultDevice() { + auto platformList = sycl::platform::get_platforms(); + for (const auto &platform : platformList) { +auto platformName = platform.get_info(); +bool isLevelZero = platformName.find("Level-Zero") != std::string::npos; +if (!isLevelZero) + continue; + +return platform.get_devices()[0]; + } + throw std::runtime_error("getDefaultDevice failed"); +} + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wglobal-constructors" + +// Create global device and context +sycl::device syclDevice = getDefaultDevice(); +sycl::context syclContext = sycl::context(syclDevice); keryell wrote: ```suggestion sycl::context syclContext { syclDevice }; ``` 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)
@@ -0,0 +1,223 @@ +//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===// +// +// 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 +// +//===--===// +// +// Implements C wrappers around the sycl runtime library. +// +//===--===// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#ifdef _WIN32 +#define SYCL_RUNTIME_EXPORT __declspec(dllexport) +#else +#define SYCL_RUNTIME_EXPORT +#endif // _WIN32 + +namespace { + +template +auto catchAll(F &&func) { + try { +return func(); + } catch (const std::exception &e) { +fprintf(stdout, "An exception was thrown: %s\n", e.what()); +fflush(stdout); +abort(); + } catch (...) { +fprintf(stdout, "An unknown exception was thrown\n"); +fflush(stdout); +abort(); + } +} + +#define L0_SAFE_CALL(call) \ + { \ +ze_result_t status = (call); \ +if (status != ZE_RESULT_SUCCESS) { \ + fprintf(stdout, "L0 error %d\n", status); \ + fflush(stdout); \ + abort(); \ +} \ + } + +} // namespace + +static sycl::device getDefaultDevice() { + auto platformList = sycl::platform::get_platforms(); + for (const auto &platform : platformList) { +auto platformName = platform.get_info(); +bool isLevelZero = platformName.find("Level-Zero") != std::string::npos; +if (!isLevelZero) + continue; + +return platform.get_devices()[0]; + } + throw std::runtime_error("getDefaultDevice failed"); +} + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wglobal-constructors" + +// Create global device and context +sycl::device syclDevice = getDefaultDevice(); +sycl::context syclContext = sycl::context(syclDevice); + +#pragma clang diagnostic pop + +struct QUEUE { + sycl::queue syclQueue_; + + QUEUE() { syclQueue_ = sycl::queue(syclContext, syclDevice); } +}; + +static void *allocDeviceMemory(QUEUE *queue, size_t size, bool isShared) { + void *memPtr = nullptr; + if (isShared) { +memPtr = sycl::aligned_alloc_shared(64, size, syclDevice, syclContext); + } else { +memPtr = sycl::aligned_alloc_device(64, size, syclDevice, syclContext); + } + if (memPtr == nullptr) { +throw std::runtime_error("mem allocation failed!"); + } + return memPtr; +} + +static void deallocDeviceMemory(QUEUE *queue, void *ptr) { + sycl::free(ptr, queue->syclQueue_); +} + +static ze_module_handle_t loadModule(const void *data, size_t dataSize) { + assert(data); + ze_module_handle_t zeModule; + ze_module_desc_t desc = {ZE_STRUCTURE_TYPE_MODULE_DESC, + nullptr, + ZE_MODULE_FORMAT_IL_SPIRV, + dataSize, + (const uint8_t *)data, + nullptr, + nullptr}; + auto zeDevice = + sycl::get_native(syclDevice); + auto zeContext = + sycl::get_native(syclContext); + L0_SAFE_CALL(zeModuleCreate(zeContext, zeDevice, &desc, &zeModule, nullptr)); + return zeModule; +} + +static sycl::kernel *getKernel(ze_module_handle_t zeModule, const char *name) { + assert(zeModule); + assert(name); + ze_kernel_handle_t zeKernel; + sycl::kernel *syclKernel; + ze_kernel_desc_t desc = {}; + desc.pKernelName = name; + + L0_SAFE_CALL(zeKernelCreate(zeModule, &desc, &zeKernel)); + sycl::kernel_bundle kernelBundle = + sycl::make_kernel_bundle({zeModule}, + syclContext); + + auto kernel = sycl::make_kernel( + {kernelBundle, zeKernel}, syclContext); + syclKernel = new sycl::kernel(kernel); + return syclKernel; +} + +static void launchKernel(QUEUE *queue, sycl::kernel *kernel, size_t gridX, keryell wrote: ```suggestion static void launchKernel(QUEUE queue, sycl::kernel kernel, size_t gridX, ``` or even use `&` if you are afraid of using the reference semantics of SYCL behind the scene. 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)
@@ -0,0 +1,223 @@ +//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===// +// +// 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 +// +//===--===// +// +// Implements C wrappers around the sycl runtime library. +// +//===--===// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#ifdef _WIN32 +#define SYCL_RUNTIME_EXPORT __declspec(dllexport) +#else +#define SYCL_RUNTIME_EXPORT +#endif // _WIN32 + +namespace { + +template +auto catchAll(F &&func) { + try { +return func(); + } catch (const std::exception &e) { +fprintf(stdout, "An exception was thrown: %s\n", e.what()); +fflush(stdout); +abort(); + } catch (...) { +fprintf(stdout, "An unknown exception was thrown\n"); +fflush(stdout); +abort(); + } +} + +#define L0_SAFE_CALL(call) \ + { \ +ze_result_t status = (call); \ +if (status != ZE_RESULT_SUCCESS) { \ + fprintf(stdout, "L0 error %d\n", status); \ + fflush(stdout); \ + abort(); \ +} \ + } + +} // namespace + +static sycl::device getDefaultDevice() { + auto platformList = sycl::platform::get_platforms(); + for (const auto &platform : platformList) { +auto platformName = platform.get_info(); +bool isLevelZero = platformName.find("Level-Zero") != std::string::npos; +if (!isLevelZero) + continue; + +return platform.get_devices()[0]; + } + throw std::runtime_error("getDefaultDevice failed"); +} + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wglobal-constructors" + +// Create global device and context +sycl::device syclDevice = getDefaultDevice(); +sycl::context syclContext = sycl::context(syclDevice); + +#pragma clang diagnostic pop + +struct QUEUE { keryell wrote: Why this spelling? Coding standard? Why do you need this object? At the end this looks like a `std::optional`. 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)
@@ -0,0 +1,223 @@ +//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===// +// +// 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 +// +//===--===// +// +// Implements C wrappers around the sycl runtime library. +// +//===--===// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#ifdef _WIN32 +#define SYCL_RUNTIME_EXPORT __declspec(dllexport) +#else +#define SYCL_RUNTIME_EXPORT +#endif // _WIN32 + +namespace { + +template +auto catchAll(F &&func) { + try { +return func(); + } catch (const std::exception &e) { +fprintf(stdout, "An exception was thrown: %s\n", e.what()); +fflush(stdout); +abort(); + } catch (...) { +fprintf(stdout, "An unknown exception was thrown\n"); +fflush(stdout); +abort(); + } +} + +#define L0_SAFE_CALL(call) \ + { \ +ze_result_t status = (call); \ +if (status != ZE_RESULT_SUCCESS) { \ + fprintf(stdout, "L0 error %d\n", status); \ + fflush(stdout); \ + abort(); \ +} \ + } + +} // namespace + +static sycl::device getDefaultDevice() { + auto platformList = sycl::platform::get_platforms(); + for (const auto &platform : platformList) { +auto platformName = platform.get_info(); +bool isLevelZero = platformName.find("Level-Zero") != std::string::npos; +if (!isLevelZero) + continue; + +return platform.get_devices()[0]; + } + throw std::runtime_error("getDefaultDevice failed"); +} + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wglobal-constructors" + +// Create global device and context +sycl::device syclDevice = getDefaultDevice(); +sycl::context syclContext = sycl::context(syclDevice); + +#pragma clang diagnostic pop + +struct QUEUE { keryell wrote: Why this spelling? Coding standard? Why do you need this object? At the end this looks like a `std::optional`. 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)
https://github.com/keryell 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)
@@ -0,0 +1,223 @@ +//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===// +// +// 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 +// +//===--===// +// +// Implements C wrappers around the sycl runtime library. +// +//===--===// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#ifdef _WIN32 +#define SYCL_RUNTIME_EXPORT __declspec(dllexport) +#else +#define SYCL_RUNTIME_EXPORT +#endif // _WIN32 + +namespace { + +template +auto catchAll(F &&func) { + try { +return func(); + } catch (const std::exception &e) { +fprintf(stdout, "An exception was thrown: %s\n", e.what()); +fflush(stdout); +abort(); + } catch (...) { +fprintf(stdout, "An unknown exception was thrown\n"); +fflush(stdout); +abort(); + } +} + +#define L0_SAFE_CALL(call) \ + { \ +ze_result_t status = (call); \ +if (status != ZE_RESULT_SUCCESS) { \ + fprintf(stdout, "L0 error %d\n", status); \ + fflush(stdout); \ + abort(); \ +} \ + } + +} // namespace + +static sycl::device getDefaultDevice() { + auto platformList = sycl::platform::get_platforms(); + for (const auto &platform : platformList) { +auto platformName = platform.get_info(); +bool isLevelZero = platformName.find("Level-Zero") != std::string::npos; +if (!isLevelZero) + continue; + +return platform.get_devices()[0]; + } + throw std::runtime_error("getDefaultDevice failed"); +} + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wglobal-constructors" + +// Create global device and context +sycl::device syclDevice = getDefaultDevice(); +sycl::context syclContext = sycl::context(syclDevice); keryell wrote: ```suggestion sycl::context syclContext { syclDevice }; ``` 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)
@@ -0,0 +1,223 @@ +//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===// +// +// 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 +// +//===--===// +// +// Implements C wrappers around the sycl runtime library. +// +//===--===// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#ifdef _WIN32 +#define SYCL_RUNTIME_EXPORT __declspec(dllexport) +#else +#define SYCL_RUNTIME_EXPORT +#endif // _WIN32 + +namespace { + +template +auto catchAll(F &&func) { + try { +return func(); + } catch (const std::exception &e) { +fprintf(stdout, "An exception was thrown: %s\n", e.what()); +fflush(stdout); +abort(); + } catch (...) { +fprintf(stdout, "An unknown exception was thrown\n"); +fflush(stdout); +abort(); + } +} + +#define L0_SAFE_CALL(call) \ + { \ +ze_result_t status = (call); \ +if (status != ZE_RESULT_SUCCESS) { \ + fprintf(stdout, "L0 error %d\n", status); \ + fflush(stdout); \ + abort(); \ +} \ + } + +} // namespace + +static sycl::device getDefaultDevice() { + auto platformList = sycl::platform::get_platforms(); + for (const auto &platform : platformList) { +auto platformName = platform.get_info(); +bool isLevelZero = platformName.find("Level-Zero") != std::string::npos; +if (!isLevelZero) + continue; + +return platform.get_devices()[0]; + } + throw std::runtime_error("getDefaultDevice failed"); +} + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wglobal-constructors" + +// Create global device and context +sycl::device syclDevice = getDefaultDevice(); +sycl::context syclContext = sycl::context(syclDevice); + +#pragma clang diagnostic pop + +struct QUEUE { + sycl::queue syclQueue_; + + QUEUE() { syclQueue_ = sycl::queue(syclContext, syclDevice); } +}; + +static void *allocDeviceMemory(QUEUE *queue, size_t size, bool isShared) { + void *memPtr = nullptr; + if (isShared) { +memPtr = sycl::aligned_alloc_shared(64, size, syclDevice, syclContext); + } else { +memPtr = sycl::aligned_alloc_device(64, size, syclDevice, syclContext); + } + if (memPtr == nullptr) { +throw std::runtime_error("mem allocation failed!"); + } + return memPtr; +} + +static void deallocDeviceMemory(QUEUE *queue, void *ptr) { + sycl::free(ptr, queue->syclQueue_); +} + +static ze_module_handle_t loadModule(const void *data, size_t dataSize) { + assert(data); + ze_module_handle_t zeModule; + ze_module_desc_t desc = {ZE_STRUCTURE_TYPE_MODULE_DESC, + nullptr, + ZE_MODULE_FORMAT_IL_SPIRV, + dataSize, + (const uint8_t *)data, + nullptr, + nullptr}; + auto zeDevice = + sycl::get_native(syclDevice); + auto zeContext = + sycl::get_native(syclContext); + L0_SAFE_CALL(zeModuleCreate(zeContext, zeDevice, &desc, &zeModule, nullptr)); + return zeModule; +} + +static sycl::kernel *getKernel(ze_module_handle_t zeModule, const char *name) { + assert(zeModule); + assert(name); + ze_kernel_handle_t zeKernel; + sycl::kernel *syclKernel; + ze_kernel_desc_t desc = {}; + desc.pKernelName = name; + + L0_SAFE_CALL(zeKernelCreate(zeModule, &desc, &zeKernel)); + sycl::kernel_bundle kernelBundle = + sycl::make_kernel_bundle({zeModule}, + syclContext); + + auto kernel = sycl::make_kernel( + {kernelBundle, zeKernel}, syclContext); + syclKernel = new sycl::kernel(kernel); + return syclKernel; +} + +static void launchKernel(QUEUE *queue, sycl::kernel *kernel, size_t gridX, + size_t gridY, size_t gridZ, size_t blockX, + size_t blockY, size_t blockZ, size_t sharedMemBytes, + void **params, size_t paramsCount) { + auto syclGlobalRange = + ::sycl::range<3>(blockZ * gridZ, blockY * gridY, blockX * gridX); + auto syclLocalRange = ::sycl::range<3>(blockZ, blockY, blockX); + sycl::nd_range<3> syclNdRange( + sycl::nd_range<3>(syclGloba
[clang-tools-extra] [MLIR] Enabling Intel GPU Integration. (PR #65539)
@@ -116,6 +116,7 @@ add_definitions(-DMLIR_ROCM_CONVERSIONS_ENABLED=${MLIR_ENABLE_ROCM_CONVERSIONS}) set(MLIR_ENABLE_CUDA_RUNNER 0 CACHE BOOL "Enable building the mlir CUDA runner") set(MLIR_ENABLE_ROCM_RUNNER 0 CACHE BOOL "Enable building the mlir ROCm runner") +set(MLIR_ENABLE_SYCL_RUNNER 0 CACHE BOOL "Enable building the mlir Sycl runner") keryell wrote: Please spell SYCL correctly. ```suggestion set(MLIR_ENABLE_SYCL_RUNNER 0 CACHE BOOL "Enable building the mlir SYCL runner") ``` One could argue that `mlir` should be spelled `MLIR` but the train seems to have left long time ago. :-) 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
[PATCH] D26735: [OpenCL] Disable && (address of label) GNU extension for OpenCL
keryell added a comment. +1 Please do not remove anything, since it may be useful in some contexts. I do not think there are negative tests in the Khronos OpenCL conformance test suite anyway. https://reviews.llvm.org/D26735 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15914: [OpenCL] Pipe builtin functions
keryell added a subscriber: keryell. Comment at: include/clang/Basic/Builtins.h:39 @@ -38,2 +38,3 @@ MS_LANG = 0x10, // builtin requires MS mode. + OCLC_LANG = 0x20,// builtin for OpenCL C only. ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages. Yes, it may be useful to differentiate OpenCL C from the on-going OpenCL C++ http://reviews.llvm.org/D15914 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SYCL] The sycl_kernel_entry_point attribute. (PR #111389)
https://github.com/keryell approved this pull request. LGTM. Thanks for the good documentation! https://github.com/llvm/llvm-project/pull/111389 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Call code gen; create empty cir.func op (PR #113483)
https://github.com/keryell edited https://github.com/llvm/llvm-project/pull/113483 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Call code gen; create empty cir.func op (PR #113483)
@@ -0,0 +1,38 @@ +//===- CIRAttrs.cpp - MLIR CIR Attributes -===// +// +// 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 defines the attributes in the CIR dialect. +// +//===--===// + +#include "clang/CIR/Dialect/IR/CIRDialect.h" + +using namespace mlir; +using namespace mlir::cir; keryell wrote: What about removing all the `using namespace` since this is a new start to the project? https://github.com/llvm/llvm-project/pull/113483 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Call code gen; create empty cir.func op (PR #113483)
https://github.com/keryell commented: Nice! https://github.com/llvm/llvm-project/pull/113483 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SYCL] The sycl_kernel_entry_point attribute. (PR #111389)
@@ -407,7 +407,8 @@ def MicrosoftExt : LangOpt<"MicrosoftExt">; def Borland : LangOpt<"Borland">; def CUDA : LangOpt<"CUDA">; def HIP : LangOpt<"HIP">; -def SYCL : LangOpt<"SYCLIsDevice">; +def SYCLHost : LangOpt<"SYCLIsHost">; keryell wrote: On the other hand SYCL is a trademark from Khronos, so if it can stay SYCL it is better from this perspective. Otherwise people get confused and create more effort like https://github.com/llvm/llvm-project/pull/113060 :smiley: https://github.com/llvm/llvm-project/pull/111389 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SYCL] The sycl_kernel_entry_point attribute. (PR #111389)
@@ -455,6 +455,174 @@ The SYCL kernel in the previous code sample meets these expectations. }]; } +def SYCLKernelEntryPointDocs : Documentation { + let Category = DocCatFunction; + let Content = [{ +The ``sycl_kernel_entry_point`` attribute facilitates the generation of an +offload kernel entry point, sometimes called a SYCL kernel caller function, +suitable for invoking a SYCL kernel on an offload device. The attribute is +intended for use in the implementation of SYCL kernel invocation functions +like the ``single_task`` and ``parallel_for`` member functions of the +``sycl::handler`` class specified in section 4.9.4, "Command group ``handler`` +class", of the SYCL 2020 specification. + +The attribute requires a single type argument that specifies a class type that +meets the requirements for a SYCL kernel name as described in section 5.2, +"Naming of kernels", of the SYCL 2020 specification. A unique kernel name type +is required for each function declared with the attribute. The attribute may +not first appear on a declaration that follows a definition of the function. + +The attribute only appertains to functions and only those that meet the +following requirements. + +* Has a ``void`` return type. +* Is not a non-static member function, constructor, or destructor. +* Is not a C variadic function. +* Is not a coroutine. +* Is not defined as deleted or as defaulted. +* Is not declared with the ``constexpr`` or ``consteval`` specifiers. keryell wrote: Just rethinking about this, since I have worked today on `constexpr` in a related context https://github.com/KhronosGroup/SYCL-CTS/pull/976 This looks like a pessimistic interpretation of the specification or something we could clarify in the SYCL committee. It is not really important to consider `consteval` as it will always be in a constant evaluated context, so it will never reach SYCL codegen (perhaps in the future if we want to speed up the slooow constant evaluator of Clang itself on some accelerators? :rofl: ). And why not having a kernel which is `constexpr` function too? It will only matter when in a non-constant evaluated context. https://github.com/llvm/llvm-project/pull/111389 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] floating-point, pointer, and function types (PR #120484)
keryell wrote: @dkolsen-pgi Great PR! Since it touches functions returning `!void` or `!cir.void`, I made some changes recently with https://github.com/llvm/clangir/commit/568b51537e573c7a8fb616cda5cdd0aa54bc0832 to avoid disrupting some MLIR invariants. Are you up-streaming the changes in commit order or are you up-streaming the changes with the latest version of a feature? @joker-eph How to up-stream some changes which are cross-project like https://github.com/llvm/clangir/pull/1203 which introduces a new MLIR parser/pretty-printer feature like: https://github.com/llvm/clangir/pull/1203/files#diff-cfea91beb87a3b28295e5612974f0556b4daf9a42c1adeb65e56f0dec062feaa https://github.com/llvm/clangir/pull/1203/files#diff-6c1c134d749d53cf770548806b955401e47b1f15ffe084905a0b132d73b0b1fe https://github.com/llvm/clangir/pull/1203/files#diff-dabff257abfd11fded480c2dfc0c2afdf640769384af9e37820e11003a75edb1 to allow some keywords starting with `!`? https://github.com/llvm/llvm-project/pull/120484 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] floating-point, pointer, and function types (PR #120484)
keryell wrote: > My bad here, we usually don't accept such changes and I missed that during > review time. ClangIR policy to changes outside CIR is to upstream them to > MLIR and after that's done we cherry-pick it to the incubator (so rebases are > smooth). I'll have to revert your change, sorry for the churn! @bcardosolopes I can work on the phase 2 of the change I had in mind and remove also the `!void` from function type textual IR to avoid adding a new feature in the MLIR parsing infrastructure. https://github.com/llvm/llvm-project/pull/120484 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SYCL] change sycl version accrodnig to standard (PR #114790)
keryell wrote: That sounds good. Could you fix the typos in the PR title and the commit messages. Please write SYCL in uppercase everywhere since it is a standard name. https://github.com/llvm/llvm-project/pull/114790 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Better handling of `void` function return (PR #128089)
@@ -273,29 +273,36 @@ def CIR_PointerType : CIR_Type<"Pointer", "ptr", def CIR_FuncType : CIR_Type<"Func", "func"> { let summary = "CIR function type"; let description = [{ -The `!cir.func` is a function type. It consists of a single return type, a -list of parameter types and can optionally be variadic. +The `!cir.func` is a function type. It consists of an optional return type, +a list of parameter types and can optionally be variadic. Example: ```mlir +!cir.func<()> !cir.func +!cir.func<(!s8i, !s8i)> !cir.func !cir.func ``` }]; let parameters = (ins ArrayRefParameter<"mlir::Type">:$inputs, -"mlir::Type":$returnType, "bool":$varArg); +"mlir::Type":$optionalReturnType, "bool":$varArg); + // Use a custom parser to handle the optional return and argument types + // without an optional anchor. let assemblyFormat = [{ -`<` $returnType ` ` `(` custom($inputs, $varArg) `>` +`<` custom($optionalReturnType, $inputs, $varArg) `>` }]; let builders = [ +// Construct with an actual return type or explicit !cir.void keryell wrote: No, I really meant explicit here. If you put an explicit `!cir.void` in the assembly text, it will be discarded and will be nowhere in the IR. It is as if there was This is for compatibility with pas ClangIR behavior. Of course, since we are up-streaming it, do we need this backward compatibility? If not, it might breaks more stuff while rebasing ClangIR downstream... :thinking: https://github.com/llvm/llvm-project/pull/128089 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Better handling of `void` function return (PR #128089)
@@ -331,9 +335,38 @@ FuncType FuncType::clone(TypeRange inputs, TypeRange results) const { return get(llvm::to_vector(inputs), results[0], isVarArg()); } -mlir::ParseResult parseFuncTypeArgs(mlir::AsmParser &p, -llvm::SmallVector ¶ms, -bool &isVarArg) { +// A special parser is needed for function returning void to handle the missing +// type. +static mlir::ParseResult parseFuncTypeReturn(mlir::AsmParser &p, + mlir::Type &optionalReturnType) { + if (succeeded(p.parseOptionalLParen())) { +// If we have already a '(', the function has no return type +optionalReturnType = {}; +return mlir::success(); + } + mlir::Type type; + if (p.parseType(type)) +return mlir::failure(); + if (isa(type)) +// An explicit !cir.void means also no return type. +optionalReturnType = {}; + else +// Otherwise use the actual type. +optionalReturnType = type; + return p.parseLParen(); +} + +// A special pretty-printer for function returning or not a result. +static void printFuncTypeReturn(mlir::AsmPrinter &p, +mlir::Type optionalReturnType) { + if (optionalReturnType) +p << optionalReturnType << ' '; + p << '('; +} + +static mlir::ParseResult +parseFuncTypeArgs(mlir::AsmParser &p, llvm::SmallVector ¶ms, + bool &isVarArg) { isVarArg = false; // `(` `)` if (succeeded(p.parseOptionalRParen())) keryell wrote: I think this is the way the parsers are implemented to chain things ahead. See again my comment with `void` keyword. At the end it is a trade-off between implementator comfort and code beauty vs the concrete assembly syntax exposed to the end user. https://github.com/llvm/llvm-project/pull/128089 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Better handling of `void` function return (PR #128089)
https://github.com/keryell edited https://github.com/llvm/llvm-project/pull/128089 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Better handling of `void` function return (PR #128089)
@@ -331,9 +335,38 @@ FuncType FuncType::clone(TypeRange inputs, TypeRange results) const { return get(llvm::to_vector(inputs), results[0], isVarArg()); } -mlir::ParseResult parseFuncTypeArgs(mlir::AsmParser &p, -llvm::SmallVector ¶ms, -bool &isVarArg) { +// A special parser is needed for function returning void to handle the missing +// type. +static mlir::ParseResult parseFuncTypeReturn(mlir::AsmParser &p, + mlir::Type &optionalReturnType) { + if (succeeded(p.parseOptionalLParen())) { +// If we have already a '(', the function has no return type +optionalReturnType = {}; +return mlir::success(); + } + mlir::Type type; + if (p.parseType(type)) +return mlir::failure(); + if (isa(type)) +// An explicit !cir.void means also no return type. keryell wrote: We could put the comment before the if otherwise. https://github.com/llvm/llvm-project/pull/128089 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Better handling of `void` function return (PR #128089)
@@ -375,11 +409,48 @@ void printFuncTypeArgs(mlir::AsmPrinter &p, mlir::ArrayRef params, p << ')'; } +// Use a custom parser to handle the optional return and argument types without +// an optional anchor. +static mlir::ParseResult parseFuncType(mlir::AsmParser &p, + mlir::Type &optionalReturnTypes, + llvm::SmallVector ¶ms, + bool &isVarArg) { + if (failed(parseFuncTypeReturn(p, optionalReturnTypes))) +return failure(); + return parseFuncTypeArgs(p, params, isVarArg); +} + +static void printFuncType(mlir::AsmPrinter &p, mlir::Type optionalReturnTypes, + mlir::ArrayRef params, bool isVarArg) { + printFuncTypeReturn(p, optionalReturnTypes); + printFuncTypeArgs(p, params, isVarArg); +} + +// Return the actual return type or an explicit !cir.void if the function does +// not return anything +mlir::Type FuncType::getReturnType() const { + if (isVoid()) +return cir::VoidType::get(getContext()); + return static_cast(getImpl())->optionalReturnType; +} + +/// Returns the result type of the function as an ArrayRef, enabling better +/// integration with generic MLIR utilities. llvm::ArrayRef FuncType::getReturnTypes() const { - return static_cast(getImpl())->returnType; + if (isVoid()) +return {}; + return static_cast(getImpl())->optionalReturnType; keryell wrote: No because it returns the real return types (plural) that any real MLIR user is waiting for: the actual return types, which in the case of C/C++ is 0 or 1 type. The whole point of this PR is to fix this bug and not to return some synthetic `!cir.void` which was breaking the neighborhood. https://github.com/llvm/llvm-project/pull/128089 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Better handling of `void` function return (PR #128089)
https://github.com/keryell commented: Sorry for being late to the party! https://github.com/llvm/llvm-project/pull/128089 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Better handling of `void` function return (PR #128089)
@@ -331,9 +335,38 @@ FuncType FuncType::clone(TypeRange inputs, TypeRange results) const { return get(llvm::to_vector(inputs), results[0], isVarArg()); } -mlir::ParseResult parseFuncTypeArgs(mlir::AsmParser &p, -llvm::SmallVector ¶ms, -bool &isVarArg) { +// A special parser is needed for function returning void to handle the missing +// type. +static mlir::ParseResult parseFuncTypeReturn(mlir::AsmParser &p, + mlir::Type &optionalReturnType) { + if (succeeded(p.parseOptionalLParen())) { +// If we have already a '(', the function has no return type keryell wrote: Yes this is a kind of look-ahead which is required when I introduced to remove the creation of an artificial `!cir.void` which had the consequence of breaking an MLIR invariant, `number(return-types) == number(return-values)`. A C type like `char(int)` is lowered and pretty-printed as `!cir.func(!cir.int)` while `void(int)` is lowered and pretty-printed as `!cir.func<(!cir.int)`. For the MLIR functions themselves, they are handled by the `func` MLIR standard dialect with a syntax like: ```mlir func.func @count(%x: i64) -> (i64, i64) // The same returning nothing: func.func @f(%x: i64) ``` with an empty type for returning "void". An alternate design could be to have a new keyword like `void` understood by the parser to avoid the manual look ahead in the parser as the MLIR default parser knows how to discriminate with prefix keywords. Then `void(int)` would be lowered and pretty-printed as `!cir.func)`. https://github.com/llvm/llvm-project/pull/128089 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Better handling of `void` function return (PR #128089)
https://github.com/keryell edited https://github.com/llvm/llvm-project/pull/128089 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Initial implementation of lowering CIR to MLIR (PR #127835)
keryell wrote: I appreciate the parallelism for sure! :smile: It would be nice if your team can book more time to work on the fundamental issues related to CIR→MLIR in the incubator. https://github.com/llvm/llvm-project/pull/127835 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Better handling of `void` function return (PR #128089)
@@ -331,9 +335,38 @@ FuncType FuncType::clone(TypeRange inputs, TypeRange results) const { return get(llvm::to_vector(inputs), results[0], isVarArg()); } -mlir::ParseResult parseFuncTypeArgs(mlir::AsmParser &p, -llvm::SmallVector ¶ms, -bool &isVarArg) { +// A special parser is needed for function returning void to handle the missing +// type. +static mlir::ParseResult parseFuncTypeReturn(mlir::AsmParser &p, + mlir::Type &optionalReturnType) { + if (succeeded(p.parseOptionalLParen())) { +// If we have already a '(', the function has no return type +optionalReturnType = {}; +return mlir::success(); + } + mlir::Type type; + if (p.parseType(type)) +return mlir::failure(); + if (isa(type)) +// An explicit !cir.void means also no return type. +optionalReturnType = {}; + else +// Otherwise use the actual type. +optionalReturnType = type; + return p.parseLParen(); +} + +// A special pretty-printer for function returning or not a result. +static void printFuncTypeReturn(mlir::AsmPrinter &p, +mlir::Type optionalReturnType) { + if (optionalReturnType) +p << optionalReturnType << ' '; + p << '('; +} + +static mlir::ParseResult +parseFuncTypeArgs(mlir::AsmParser &p, llvm::SmallVector ¶ms, + bool &isVarArg) { isVarArg = false; // `(` `)` if (succeeded(p.parseOptionalRParen())) keryell wrote: I like this idea too. I have tried to be as close as the original syntax to avoid disrupting too much the tests and the users but there is no reason to do something else. If there is a consensus from the ClangIR stake-holders, go for it! https://github.com/llvm/llvm-project/pull/128089 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Add cir-opt tool to exercise CIR dialect parsing (PR #128254)
https://github.com/keryell approved this pull request. Thanks! https://github.com/llvm/llvm-project/pull/128254 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Initial implementation of lowering CIR to MLIR (PR #127835)
https://github.com/keryell approved this pull request. Thank you! https://github.com/llvm/llvm-project/pull/127835 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits