Skip to content

[offload][SYCL] Add SYCL Module splitting. #131347

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 4 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
39 changes: 39 additions & 0 deletions llvm/include/llvm/Frontend/SYCL/SplitModule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//===-------- SplitModule.h - module split ----------------------*- 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
//
//===----------------------------------------------------------------------===//
// Functionality to split a module for SYCL Offloading Kind.
//===----------------------------------------------------------------------===//

#ifndef LLVM_FRONTEND_SYCL_SPLIT_MODULE_H
#define LLVM_FRONTEND_SYCL_SPLIT_MODULE_H

#include "llvm/ADT/STLFunctionalExtras.h"
#include "llvm/Frontend/SYCL/Utils.h"

#include <memory>
#include <optional>
#include <string>

namespace llvm {

class Module;
class Function;

namespace sycl {

using PostSplitCallbackType = function_ref<void(std::unique_ptr<Module> Part)>;

/// Splits the given module \p M.
/// Every split image is being passed to \p Callback for further possible
/// processing.
void splitModule(std::unique_ptr<Module> M, IRSplitMode Mode,
PostSplitCallbackType Callback);

} // namespace sycl
} // namespace llvm

#endif // LLVM_FRONTEND_SYCL_SPLIT_MODULE_H
67 changes: 67 additions & 0 deletions llvm/include/llvm/Frontend/SYCL/Utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//===------------ Utils.h - SYCL utility functions ------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
// Utility functions for SYCL.
//===----------------------------------------------------------------------===//
#ifndef LLVM_FRONTEND_SYCL_UTILS_H
#define LLVM_FRONTEND_SYCL_UTILS_H

#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"

#include <string>

namespace llvm {

class Module;
class Function;
class raw_ostream;

namespace sycl {

enum class IRSplitMode {
IRSM_PER_TU, // one module per translation unit
IRSM_PER_KERNEL, // one module per kernel
IRSM_NONE // no splitting
};

/// \returns IRSplitMode value if \p S is recognized. Otherwise, std::nullopt is
/// returned.
std::optional<IRSplitMode> convertStringToSplitMode(StringRef S);

/// The structure represents a LLVM Module accompanied by additional
/// information. Split Modules are being stored at disk due to the high RAM
/// consumption during the whole splitting process.
struct ModuleAndSYCLMetadata {
std::string ModuleFilePath;
std::string Symbols;

ModuleAndSYCLMetadata() = delete;
ModuleAndSYCLMetadata(const ModuleAndSYCLMetadata &) = default;
ModuleAndSYCLMetadata &operator=(const ModuleAndSYCLMetadata &) = default;
ModuleAndSYCLMetadata(ModuleAndSYCLMetadata &&) = default;
ModuleAndSYCLMetadata &operator=(ModuleAndSYCLMetadata &&) = default;

ModuleAndSYCLMetadata(const Twine &File, std::string Symbols)
: ModuleFilePath(File.str()), Symbols(std::move(Symbols)) {}
};

/// Checks whether the function is a SYCL entry point.
bool isEntryPoint(const Function &F);

std::string makeSymbolTable(const Module &M);

using StringTable = SmallVector<SmallVector<SmallString<64>>>;

void writeStringTable(const StringTable &Table, raw_ostream &OS);

} // namespace sycl
} // namespace llvm

#endif // LLVM_FRONTEND_SYCL_UTILS_H
1 change: 1 addition & 0 deletions llvm/lib/Frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ add_subdirectory(HLSL)
add_subdirectory(OpenACC)
add_subdirectory(OpenMP)
add_subdirectory(Offloading)
add_subdirectory(SYCL)
13 changes: 13 additions & 0 deletions llvm/lib/Frontend/SYCL/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
add_llvm_component_library(LLVMFrontendSYCL
SplitModule.cpp
Utils.cpp

ADDITIONAL_HEADER_DIRS
${LLVM_MAIN_INCLUDE_DIR}/llvm/Frontend
${LLVM_MAIN_INCLUDE_DIR}/llvm/Frontend/SYCL

LINK_COMPONENTS
Core
Support
TransformUtils
)
Loading
Loading