Skip to content

[MLIR][GPU][XeVM] Add XeVM target and XeVM dialect integration tests. #148286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions mlir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ else()
set(MLIR_ENABLE_ROCM_CONVERSIONS 0)
endif()

# Build the XeVM conversions and run according tests if the SPIRV backend
# is available.
if ("SPIRV" IN_LIST LLVM_TARGETS_TO_BUILD)
set(MLIR_ENABLE_XEVM_CONVERSIONS 1)
else()
set(MLIR_ENABLE_XEVM_CONVERSIONS 0)
endif()

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")
Expand Down
31 changes: 31 additions & 0 deletions mlir/include/mlir/Target/LLVM/XeVM/Target.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//===-- Target.h - MLIR XeVM target registration ----------------*- C++ -*-===//
//
// This file is licensed 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 attaching the XeVM target interface.
//
//===----------------------------------------------------------------------===//

#ifndef MLIR_TARGET_XEVM_TARGET_H
#define MLIR_TARGET_XEVM_TARGET_H

namespace mlir {
class DialectRegistry;
class MLIRContext;
} // namespace mlir

namespace mlir::xevm {
/// Registers the `TargetAttrInterface` for the `#xevm.target` attribute in
/// the given registry.
void registerXeVMTargetInterfaceExternalModels(mlir::DialectRegistry &registry);

/// Registers the `TargetAttrInterface` for the `#xevm.target` attribute in
/// the registry associated with the given context.
void registerXeVMTargetInterfaceExternalModels(mlir::MLIRContext &context);
} // namespace mlir::xevm

#endif // MLIR_TARGET_XEVM_TARGET_H
39 changes: 39 additions & 0 deletions mlir/include/mlir/Target/LLVM/XeVM/Utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//===-- Utils.h - MLIR XeVM target utils ------------------------*- C++ -*-===//
//
// This file is licensed 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 files declares XeVM target related utility classes and functions.
//
//===----------------------------------------------------------------------===//

#ifndef MLIR_TARGET_LLVM_XEVM_UTILS_H
#define MLIR_TARGET_LLVM_XEVM_UTILS_H

#include "mlir/Dialect/GPU/IR/CompilationInterfaces.h"
#include "mlir/Dialect/LLVMIR/XeVMDialect.h"
#include "mlir/Target/LLVM/ModuleToObject.h"

namespace mlir {
namespace xevm {

/// Base class for all XeVM serializations from GPU modules into binary strings.
/// By default this class serializes into LLVM bitcode.
class SerializeGPUModuleBase : public mlir::LLVM::ModuleToObject {
public:
SerializeGPUModuleBase(mlir::Operation &module, XeVMTargetAttr target,
const mlir::gpu::TargetOptions &targetOptions = {});

static void init();
XeVMTargetAttr getTarget() const;

protected:
XeVMTargetAttr target;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: consider target => xeTarget

};
} // namespace xevm
} // namespace mlir

#endif // MLIR_TARGET_LLVM_XEVM_UTILS_H
1 change: 1 addition & 0 deletions mlir/lib/Dialect/GPU/Transforms/XeVMAttachTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "mlir/Dialect/LLVMIR/XeVMDialect.h"
#include "mlir/IR/Builders.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Target/LLVM/XeVM/Target.h"
#include "llvm/Support/Regex.h"

namespace mlir {
Expand Down
2 changes: 2 additions & 0 deletions mlir/lib/RegisterAllDialects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
#include "mlir/Interfaces/CastInterfaces.h"
#include "mlir/Target/LLVM/NVVM/Target.h"
#include "mlir/Target/LLVM/ROCDL/Target.h"
#include "mlir/Target/LLVM/XeVM/Target.h"
#include "mlir/Target/SPIRV/Target.h"

/// Add all the MLIR dialects to the provided registry.
Expand Down Expand Up @@ -197,6 +198,7 @@ void mlir::registerAllDialects(DialectRegistry &registry) {
NVVM::registerNVVMTargetInterfaceExternalModels(registry);
ROCDL::registerROCDLTargetInterfaceExternalModels(registry);
spirv::registerSPIRVTargetInterfaceExternalModels(registry);
xevm::registerXeVMTargetInterfaceExternalModels(registry);
}

/// Append all the MLIR dialects to the registry contained in the given context.
Expand Down
1 change: 1 addition & 0 deletions mlir/lib/RegisterAllExtensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include "mlir/Target/LLVMIR/Dialect/GPU/GPUToLLVMIRTranslation.h"
#include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
#include "mlir/Target/LLVMIR/Dialect/ROCDL/ROCDLToLLVMIRTranslation.h"
#include "mlir/Target/LLVMIR/Dialect/XeVM/XeVMToLLVMIRTranslation.h"

/// This function may be called to register all MLIR dialect extensions with the
/// provided registry.
Expand Down
32 changes: 32 additions & 0 deletions mlir/lib/Target/LLVM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,35 @@ if(MLIR_ENABLE_ROCM_CONVERSIONS)
)
endif()

if ("SPIRV" IN_LIST LLVM_TARGETS_TO_BUILD)
set(SPIRV_LIBS
SPIRVCodeGen

)
endif()

add_mlir_dialect_library(MLIRXeVMTarget
XeVM/Target.cpp

OBJECT

ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/LLVMIR

LINK_COMPONENTS
${SPIRV_LIBS}

LINK_LIBS PUBLIC
MLIRIR
MLIRExecutionEngineUtils
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to depend on ExeuctionEngine and GPUDialect?

MLIRSupport
MLIRGPUDialect
MLIRTargetLLVM
MLIRXeVMToLLVMIRTranslation
)

# Ensure SPIRV headers are included. Warning: references build directory!
target_include_directories(MLIRXeVMTarget PRIVATE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI may not like it. This workaround relies on ${LLVM_MAIN_SRC_DIR} and ${LLVM_BINARY_DIR} being non-empty in MLIR build, which is not guaranteed.

${LLVM_MAIN_SRC_DIR}/lib/Target/SPIRV
${LLVM_BINARY_DIR}/lib/Target/SPIRV
)
Loading