Skip to content

[Offload] Add ol_dimensions_t and convert ranges from size_t -> uint32_t #143901

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 2 commits into from
Jun 12, 2025
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
10 changes: 10 additions & 0 deletions offload/liboffload/API/Common.td
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ def : Struct {
];
}

def : Struct {
let name = "ol_dimensions_t";
let desc = "A three element vector";
let members = [
StructMember<"uint32_t", "x", "X">,
StructMember<"uint32_t", "y", "Y">,
StructMember<"uint32_t", "z", "Z">,
];
}

def : Function {
let name = "olInit";
let desc = "Perform initialization of the Offload library and plugins";
Expand Down
8 changes: 2 additions & 6 deletions offload/liboffload/API/Kernel.td
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ def : Struct {
let desc = "Size-related arguments for a kernel launch.";
let members = [
StructMember<"size_t", "Dimensions", "Number of work dimensions">,
StructMember<"size_t", "NumGroupsX", "Number of work groups on the X dimension">,
StructMember<"size_t", "NumGroupsY", "Number of work groups on the Y dimension">,
StructMember<"size_t", "NumGroupsZ", "Number of work groups on the Z dimension">,
StructMember<"size_t", "GroupSizeX", "Size of a work group on the X dimension.">,
StructMember<"size_t", "GroupSizeY", "Size of a work group on the Y dimension.">,
StructMember<"size_t", "GroupSizeZ", "Size of a work group on the Z dimension.">,
StructMember<"struct ol_dimensions_t", "NumGroups", "Number of work groups in each dimension">,
StructMember<"struct ol_dimensions_t", "GroupSize", "Size of a work group in each dimension">,
StructMember<"size_t", "DynSharedMemory", "Size of dynamic shared memory in bytes.">
];
}
Expand Down
12 changes: 6 additions & 6 deletions offload/liboffload/src/OffloadImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,12 +499,12 @@ Error olLaunchKernel_impl(ol_queue_handle_t Queue, ol_device_handle_t Device,
auto *QueueImpl = Queue ? Queue->AsyncInfo : nullptr;
AsyncInfoWrapperTy AsyncInfoWrapper(*DeviceImpl, QueueImpl);
KernelArgsTy LaunchArgs{};
LaunchArgs.NumTeams[0] = LaunchSizeArgs->NumGroupsX;
LaunchArgs.NumTeams[1] = LaunchSizeArgs->NumGroupsY;
LaunchArgs.NumTeams[2] = LaunchSizeArgs->NumGroupsZ;
LaunchArgs.ThreadLimit[0] = LaunchSizeArgs->GroupSizeX;
LaunchArgs.ThreadLimit[1] = LaunchSizeArgs->GroupSizeY;
LaunchArgs.ThreadLimit[2] = LaunchSizeArgs->GroupSizeZ;
LaunchArgs.NumTeams[0] = LaunchSizeArgs->NumGroups.x;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised this isn't giving a warning of narrowing from u64 -> u32

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://godbolt.org/z/8Enn4z8o8

C++ doesn't care, I guess.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought that was an LLVM default on warning? Maybe liboffload isn't using the right flags to build.

LaunchArgs.NumTeams[1] = LaunchSizeArgs->NumGroups.y;
LaunchArgs.NumTeams[2] = LaunchSizeArgs->NumGroups.z;
LaunchArgs.ThreadLimit[0] = LaunchSizeArgs->GroupSize.x;
LaunchArgs.ThreadLimit[1] = LaunchSizeArgs->GroupSize.y;
LaunchArgs.ThreadLimit[2] = LaunchSizeArgs->GroupSize.z;
LaunchArgs.DynCGroupMem = LaunchSizeArgs->DynSharedMemory;

KernelLaunchParamsTy Params;
Expand Down
13 changes: 4 additions & 9 deletions offload/unittests/OffloadAPI/kernel/olLaunchKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@ struct LaunchKernelTestBase : OffloadQueueTest {
DeviceBin->getBufferSize(), &Program));
ASSERT_SUCCESS(olGetKernel(Program, kernel, &Kernel));
LaunchArgs.Dimensions = 1;
LaunchArgs.GroupSizeX = 64;
LaunchArgs.GroupSizeY = 1;
LaunchArgs.GroupSizeZ = 1;

LaunchArgs.NumGroupsX = 1;
LaunchArgs.NumGroupsY = 1;
LaunchArgs.NumGroupsZ = 1;
LaunchArgs.GroupSize = {64, 1, 1};
LaunchArgs.NumGroups = {1, 1, 1};

LaunchArgs.DynSharedMemory = 0;
}
Expand Down Expand Up @@ -60,7 +55,7 @@ OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olLaunchKernelNoArgsTest);
TEST_P(olLaunchKernelTest, Success) {
void *Mem;
ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_MANAGED,
LaunchArgs.GroupSizeX * sizeof(uint32_t), &Mem));
LaunchArgs.GroupSize.x * sizeof(uint32_t), &Mem));
struct {
void *Mem;
} Args{Mem};
Expand Down Expand Up @@ -88,7 +83,7 @@ TEST_P(olLaunchKernelNoArgsTest, Success) {
TEST_P(olLaunchKernelTest, SuccessSynchronous) {
void *Mem;
ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_MANAGED,
LaunchArgs.GroupSizeX * sizeof(uint32_t), &Mem));
LaunchArgs.GroupSize.x * sizeof(uint32_t), &Mem));

struct {
void *Mem;
Expand Down
Loading