Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 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
30 changes: 30 additions & 0 deletions mlir/include/mlir/Target/LLVM/XeVM/Target.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//===-- 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_LLVM_XEVM_TARGET_H
#define MLIR_TARGET_LLVM_XEVM_TARGET_H

namespace mlir {
class DialectRegistry;
class MLIRContext;
namespace 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 xevm
} // namespace mlir

#endif // MLIR_TARGET_LLVM_XEVM_TARGET_H
62 changes: 62 additions & 0 deletions mlir/include/mlir/Target/LLVM/XeVM/Utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//===-- 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/IR/Attributes.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 LLVM::ModuleToObject {
public:
SerializeGPUModuleBase(Operation &module, XeVMTargetAttr target,
const gpu::TargetOptions &targetOptions = {});

/// Returns the target attribute.
XeVMTargetAttr getTarget() const;

/// Loads the bitcode files in `librariesToLink`.
std::optional<SmallVector<std::unique_ptr<llvm::Module>>>
loadBitcodeFiles(llvm::Module &module) override;

/// Returns the gpu module being serialized.
gpu::GPUModuleOp getGPUModuleOp();

/// Compiles to native code using `ocloc`.
std::optional<SmallVector<char, 0>> compileToBinary(const std::string &asmStr,
StringRef inputFormat);

protected:
/// XeVM Target attribute.
XeVMTargetAttr xeTarget;
/// List of LLVM bitcode to link into after translation to LLVM IR.
/// The attributes can be StringAttr pointing to a file path, or
/// a Resource blob pointing to the LLVM bitcode in-memory.
SmallVector<Attribute> librariesToLink;

/// Returns the path to the tool used for serialization.
std::optional<std::string> findTool(StringRef tool);

/// GPU compilation target options.
gpu::TargetOptions targetOptions;
};
} // 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 @@ -102,6 +102,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 @@ -199,6 +200,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
23 changes: 23 additions & 0 deletions mlir/lib/Target/LLVM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,26 @@ 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

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

XeVM target needs to access things like gpu::TargetAttrInterface and gpu::TargetOptions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And base ModuleToObject requires makeOptimizingTransformer from ExecutionEngine

MLIRSupport
MLIRGPUDialect
MLIRTargetLLVM
MLIRXeVMToLLVMIRTranslation
)
Loading