Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7e31668
[SYCL] Add support for multiple filtered outputs in sycl-post-link
jzc Feb 15, 2024
d3439ad
Merge remote-tracking branch 'intel/sycl' into sycl-post-link-filtering
jzc Feb 15, 2024
98c0387
Fix build after merge
jzc Feb 15, 2024
84f208d
Add some newlines
jzc Feb 15, 2024
ca6005a
Add a test description
jzc Feb 22, 2024
3d471e6
Update -o description
jzc Feb 22, 2024
296596c
Add comment for isTargetCompatibleWithModule
jzc Feb 22, 2024
a650294
Add missing message for assert
jzc Feb 22, 2024
35559c4
Ensure the specified target is a recognized target
jzc Feb 22, 2024
b79a8a3
Merge remote-tracking branch 'intel/sycl' into sycl-post-link-filtering
jzc Feb 22, 2024
88f2083
Merge remote-tracking branch 'intel/sycl' into sycl-post-link-filtering
jzc Mar 11, 2024
bf7e493
Update driver to pass architecture to sycl-post-link
jzc Mar 12, 2024
02949ea
Revert "Update driver to pass architecture to sycl-post-link"
jzc Mar 12, 2024
f088450
Use function instead of constructor
jzc Mar 12, 2024
6f10b42
Change unrecognized target handling
jzc Mar 12, 2024
fb25de6
Revert "Revert "Update driver to pass architecture to sycl-post-link""
jzc Mar 12, 2024
73dd265
Add unrecognized target test
jzc Mar 14, 2024
a3b45bc
Merge remote-tracking branch 'intel/sycl' into sycl-post-link-filtering
jzc Mar 14, 2024
4d2f88d
Address review comments
jzc Mar 22, 2024
837d8e0
Merge remote-tracking branch 'intel/sycl' into sycl-post-link-filtering
jzc Mar 22, 2024
035539c
Remove unnecessary flags from driver test
jzc Mar 22, 2024
40a8447
Simplify if statement
jzc Mar 22, 2024
456a22e
Fix up includes
jzc Mar 22, 2024
07fd45e
Move include
jzc Mar 25, 2024
28ceb84
Update comment
jzc Mar 25, 2024
e4d6c24
Update getSYCLDeviceRequirements name
jzc Mar 25, 2024
2e3d46d
Merge remote-tracking branch 'intel/sycl' into sycl-post-link-filtering
jzc Apr 4, 2024
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
4 changes: 4 additions & 0 deletions llvm/include/llvm/SYCLLowerIR/DeviceConfigFile.td
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,7 @@ def : TargetInfo<"x86_64", [], [], "", "", 1>;
//defvar AspectList = [AspectCpu] # AllUSMAspects;
//def : TargetInfo<"Test", AspectList, []>;
//def : TargetInfo<"Test2", [AspectCpu] # AllUSMAspects, []>;

def : TargetInfo<"intel_gpu_cfl", [AspectFp16, AspectFp64, AspectAtomic64], [8, 16, 32]>;
def : TargetInfo<"intel_gpu_tgllp", [AspectFp16, AspectAtomic64], [8, 16, 32]>;
def : TargetInfo<"intel_gpu_pvc", [AspectFp16, AspectFp64, AspectAtomic64], [16, 32]>;
9 changes: 9 additions & 0 deletions llvm/include/llvm/SYCLLowerIR/ModuleSplitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#ifndef LLVM_SYCLLOWERIR_MODULE_SPLITTER_H
#define LLVM_SYCLLOWERIR_MODULE_SPLITTER_H

#include "SYCLDeviceRequirements.h"

#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/IR/Function.h"
Expand Down Expand Up @@ -108,6 +110,7 @@ class ModuleDesc {
std::unique_ptr<Module> M;
EntryPointGroup EntryPoints;
bool IsTopLevel = false;
std::optional<SYCLDeviceRequirements> Reqs;

public:
struct Properties {
Expand Down Expand Up @@ -193,6 +196,12 @@ class ModuleDesc {

ModuleDesc clone() const;

const SYCLDeviceRequirements &getOrComputeDeviceRequirements() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const SYCLDeviceRequirements &getOrComputeDeviceRequirements() {
const SYCLDeviceRequirements &getOrComputeDeviceRequirements() const {

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I've missed that we actually do modify Reqs field and therefore this method is indeed non-const, so perhaps my suggestion was not that good in the end?

if (!Reqs.has_value())
Reqs = SYCLDeviceRequirements(*this);
return *Reqs;
}

#ifndef NDEBUG
void verifyESIMDProperty() const;
void dump() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@

#pragma once

#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include <cstdint>
#include <map>
#include <optional>
#include <set>
#include <vector>

namespace llvm {
Expand All @@ -23,8 +27,15 @@ namespace util {
class PropertyValue;
}

void getSYCLDeviceRequirements(
const module_split::ModuleDesc &M,
std::map<StringRef, util::PropertyValue> &Requirements);
struct SYCLDeviceRequirements {
SYCLDeviceRequirements(const module_split::ModuleDesc &M);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit. I would propose a separate function getSYCLDeviceRequirements or createSYCLDeviceRequirements instead of the sophisticated constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

std::set<uint32_t> Aspects;
std::set<uint32_t> FixedTarget;
std::optional<llvm::SmallVector<uint64_t, 3>> ReqdWorkGroupSize;
std::optional<llvm::SmallString<256>> JointMatrix;
std::optional<llvm::SmallString<256>> JointMatrixMad;
std::optional<uint32_t> SubGroupSize;

std::map<StringRef, util::PropertyValue> asMap() const;
};
} // namespace llvm
1 change: 1 addition & 0 deletions llvm/lib/SYCLLowerIR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ add_llvm_component_library(LLVMSYCLLowerIR
ModuleSplitter.cpp
MutatePrintfAddrspace.cpp
SYCLAddOptLevelAttribute.cpp
SYCLDeviceRequirements.cpp
SYCLPropagateAspectsUsage.cpp
SYCLPropagateJointMatrixUsage.cpp
SYCLUtils.cpp
Expand Down
132 changes: 132 additions & 0 deletions llvm/lib/SYCLLowerIR/SYCLDeviceRequirements.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
//===----- SYCLDeviceRequirements.cpp - collect data for used aspects ----=-==//
//
// 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
//
//===----------------------------------------------------------------------===//

#include "llvm/SYCLLowerIR/SYCLDeviceRequirements.h"

#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/IR/Module.h"
#include "llvm/SYCLLowerIR/ModuleSplitter.h"
#include "llvm/Support/PropertySetIO.h"

#include <set>
#include <vector>

using namespace llvm;

static int64_t ExtractSignedIntegerFromMDNodeOperand(const MDNode *N,
unsigned OpNo) {
Constant *C = cast<ConstantAsMetadata>(N->getOperand(OpNo).get())->getValue();
return C->getUniqueInteger().getSExtValue();
}
static uint64_t ExtractUnsignedIntegerFromMDNodeOperand(const MDNode *N,
unsigned OpNo) {
Constant *C = cast<ConstantAsMetadata>(N->getOperand(OpNo).get())->getValue();
return C->getUniqueInteger().getZExtValue();
}
static llvm::StringRef ExtractStringFromMDNodeOperand(const MDNode *N,
unsigned OpNo) {
MDString *S = cast<llvm::MDString>(N->getOperand(OpNo).get());
return S->getString();
}

SYCLDeviceRequirements::SYCLDeviceRequirements(
const module_split::ModuleDesc &MD) {
// Process all functions in the module
for (const Function &F : MD.getModule()) {
if (auto *MDN = F.getMetadata("sycl_used_aspects")) {
for (size_t I = 0, E = MDN->getNumOperands(); I < E; ++I) {
auto Val = ExtractSignedIntegerFromMDNodeOperand(MDN, I);
// Don't put internal aspects (with negative integer value) into the
// requirements, they are used only for device image splitting.
if (Val >= 0)
Aspects.insert(Val);
}
}

if (auto *MDN = F.getMetadata("sycl_fixed_targets")) {
for (size_t I = 0, E = MDN->getNumOperands(); I < E; ++I) {
auto Val = ExtractUnsignedIntegerFromMDNodeOperand(MDN, I);
FixedTarget.insert(Val);
}
}

if (auto *MDN = F.getMetadata("reqd_work_group_size")) {
llvm::SmallVector<uint64_t, 3> NewReqdWorkGroupSize;
for (size_t I = 0, E = MDN->getNumOperands(); I < E; ++I)
NewReqdWorkGroupSize.push_back(
ExtractUnsignedIntegerFromMDNodeOperand(MDN, I));
if (!ReqdWorkGroupSize.has_value())
ReqdWorkGroupSize = NewReqdWorkGroupSize;
}

if (auto *MDN = F.getMetadata("sycl_joint_matrix")) {
auto Val = ExtractStringFromMDNodeOperand(MDN, 0);
if (!Val.empty())
JointMatrix = Val;
}

if (auto *MDN = F.getMetadata("sycl_joint_matrix_mad")) {
auto Val = ExtractStringFromMDNodeOperand(MDN, 0);
if (!Val.empty())
JointMatrixMad = Val;
}
}

// Process just the entry points in the module
for (const Function *F : MD.entries()) {
if (auto *MDN = F->getMetadata("intel_reqd_sub_group_size")) {
// There should only be at most one function with
// intel_reqd_sub_group_size metadata when considering the entry
// points of a module, but not necessarily when considering all the
// functions of a module: an entry point with a
// intel_reqd_sub_group_size can call an ESIMD function through
// invoke_esimd, and that function has intel_reqd_sub_group_size=1,
// which is valid.
assert(MDN->getNumOperands() == 1);
auto MDValue = ExtractUnsignedIntegerFromMDNodeOperand(MDN, 0);
if (!SubGroupSize)
SubGroupSize = MDValue;
else
assert(*SubGroupSize == static_cast<uint32_t>(MDValue));
}
}
}

std::map<StringRef, util::PropertyValue> SYCLDeviceRequirements::asMap() const {
std::map<StringRef, util::PropertyValue> Requirements;

Requirements["aspects"] =
std::vector<uint32_t>(Aspects.begin(), Aspects.end());
Copy link
Contributor

Choose a reason for hiding this comment

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

What if Aspects set is empty? Shouldn't we apply if (<property is set>) <fill Requirements> here as it's done for other properties?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was preserving the behavior of the code before I refactored this part, which always attached the property. I believe the runtime can handle the property not being attach but I also might need to update some tests if I do.

// We don't need the "fixed_target" property if it's empty
if (std::string(MDName) == "sycl_fixed_targets" && Values.empty())
continue;
Requirements[MappedName] =
std::vector<uint32_t>(Values.begin(), Values.end());


// We don't need the "fixed_target" property if it's empty
if (!FixedTarget.empty())
Requirements["fixed_target"] =
std::vector<uint32_t>(FixedTarget.begin(), FixedTarget.end());

// TODO: Before intel/llvm#10620, the reqd_work_group_size attribute
// stores its values as uint32_t, but this needed to be expanded to
// uint64_t. However, this change did not happen in ABI-breaking
// window, so we attach the required work-group size as the
// reqd_work_group_size_uint64_t attribute. At the next ABI-breaking
// window, this can be changed back to reqd_work_group_size.
if (ReqdWorkGroupSize.has_value())
Requirements["reqd_work_group_size_uint64_t"] = *ReqdWorkGroupSize;

if (JointMatrix.has_value())
Requirements["joint_matrix"] = *JointMatrix;

if (JointMatrixMad.has_value())
Requirements["joint_matrix_mad"] = *JointMatrixMad;

// Do not attach reqd_sub_group_size if there is no attached metadata
if (SubGroupSize.has_value())
Requirements["reqd_sub_group_size"] = *SubGroupSize;

return Requirements;
}
Loading