Skip to content

[SYCL] Fix a bug when using no device split and reqd_work_group_size #16236

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

Merged
merged 8 commits into from
Dec 6, 2024
Merged
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
14 changes: 14 additions & 0 deletions llvm/include/llvm/Support/PropertySetIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ class PropertySetRegistry {
static constexpr char SYCL_HOST_PIPES[] = "SYCL/host pipes";
static constexpr char SYCL_VIRTUAL_FUNCTIONS[] = "SYCL/virtual functions";

static constexpr char PROPERTY_REQD_WORK_GROUP_SIZE[] =
"reqd_work_group_size_uint64_t";

/// Function for bulk addition of an entire property set in the given
/// \p Category .
template <typename MapTy> void add(StringRef Category, const MapTy &Props) {
Expand All @@ -230,6 +233,17 @@ class PropertySetRegistry {
PropSet.insert({PropName, PropertyValue(PropVal)});
}

void remove(StringRef Category, StringRef PropName) {
auto PropertySetIt = PropSetMap.find(Category);
if (PropertySetIt == PropSetMap.end())
return;
auto &PropertySet = PropertySetIt->second;
auto PropIt = PropertySet.find(PropName);
if (PropIt == PropertySet.end())
return;
PropertySet.erase(PropIt);
}

/// Parses from the given \p Buf a property set registry.
static Expected<std::unique_ptr<PropertySetRegistry>>
read(const MemoryBuffer *Buf);
Expand Down
13 changes: 2 additions & 11 deletions llvm/lib/SYCLLowerIR/SYCLDeviceRequirements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ SYCLDeviceRequirements
llvm::computeDeviceRequirements(const Module &M,
const SetVector<Function *> &EntryPoints) {
SYCLDeviceRequirements Reqs;
bool MultipleReqdWGSize = false;
// Process all functions in the module
for (const Function &F : M) {
if (auto *MDN = F.getMetadata("sycl_used_aspects")) {
Expand Down Expand Up @@ -81,8 +80,6 @@ llvm::computeDeviceRequirements(const Module &M,
ExtractUnsignedIntegerFromMDNodeOperand(MDN, I));
if (!Reqs.ReqdWorkGroupSize.has_value())
Reqs.ReqdWorkGroupSize = NewReqdWorkGroupSize;
if (Reqs.ReqdWorkGroupSize != NewReqdWorkGroupSize)
MultipleReqdWGSize = true;
}

if (auto *MDN = F.getMetadata("sycl_joint_matrix")) {
Expand Down Expand Up @@ -119,13 +116,6 @@ llvm::computeDeviceRequirements(const Module &M,
}
}

// Usually, we would only expect one ReqdWGSize, as the module passed to
// this function would be split according to that. However, when splitting
// is disabled, this cannot be guaranteed. In this case, we reset the value,
// which makes so that no value is reqd_work_group_size data is attached in
// in the device image.
if (MultipleReqdWGSize)
Reqs.ReqdWorkGroupSize.reset();
return Reqs;
}

Expand All @@ -152,7 +142,8 @@ std::map<StringRef, util::PropertyValue> SYCLDeviceRequirements::asMap() const {
// 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;
Requirements[util::PropertySetRegistry::PROPERTY_REQD_WORK_GROUP_SIZE] =
*ReqdWorkGroupSize;

if (JointMatrix.has_value())
Requirements["joint_matrix"] = *JointMatrix;
Expand Down
9 changes: 9 additions & 0 deletions llvm/tools/sycl-post-link/sycl-post-link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,15 @@ std::string saveModuleProperties(module_split::ModuleDesc &MD,
auto PropSet =
computeModuleProperties(MD.getModule(), MD.entries(), GlobProps);

// When the split mode is none, the required work group size will be added
// to the whole module, which will make the runtime unable to
// launch the other kernels in the module that have different
// required work group sizes or no required work group sizes. So we need to
// remove the required work group size metadata in this case.
if (SplitMode == module_split::SPLIT_NONE)
PropSet.remove(PropSetRegTy::SYCL_DEVICE_REQUIREMENTS,
PropSetRegTy::PROPERTY_REQD_WORK_GROUP_SIZE);

std::string NewSuff = Suff.str();
if (!Target.empty()) {
PropSet.add(PropSetRegTy::SYCL_DEVICE_REQUIREMENTS, "compile_target",
Expand Down
19 changes: 19 additions & 0 deletions sycl/test-e2e/Regression/no-split-reqd-wg-size-2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// This test checks that with -fsycl-device-code-split=off, kernels
// with different reqd_work_group_size dimensions can be launched.

// RUN: %{build} -fsycl-device-code-split=off -o %t.out
// RUN: %{run} %t.out

// UNSUPPORTED: hip

#include <sycl/detail/core.hpp>

using namespace sycl;

int main(int argc, char **argv) {
queue q;
q.single_task([] {});
q.parallel_for(range<2>(24, 1),
[=](auto) [[sycl::reqd_work_group_size(24, 1)]] {});
return 0;
}
2 changes: 1 addition & 1 deletion sycl/test-e2e/Regression/no-split-reqd-wg-size.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This test checks that with -fsycl-device-code-split=off, kernels
// with different reqd_work_group_size dimensions can be launched.

// RUN: %{build} -fsycl -fsycl-device-code-split=off -o %t.out
// RUN: %{build} -fsycl-device-code-split=off -o %t.out
// RUN: %{run} %t.out

// UNSUPPORTED: hip
Expand Down
Loading