Skip to content

Commit be8379c

Browse files
committed
Rename function and make optional
1 parent ae21468 commit be8379c

File tree

8 files changed

+70
-52
lines changed

8 files changed

+70
-52
lines changed

offload/liboffload/API/Kernel.td

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,17 @@ def : Function {
4444
}
4545

4646
def : Function {
47-
let name = "olGetKernelMaxGroupSize";
48-
let desc = "Get the maximum block size needed to achieve maximum occupancy.";
47+
let name = "olCalculateMaxOccupancy";
48+
let desc = "Given dynamic memory size, query the device for a workgroup size that will result in optimal occupancy.";
4949
let details = [];
5050
let params = [
5151
Param<"ol_device_handle_t", "Device", "device intended to run the kernel", PARAM_IN>,
5252
Param<"ol_symbol_handle_t", "Kernel", "handle of the kernel", PARAM_IN>,
53-
Param<"size_t", "SharedMemory", "dynamic shared memory required", PARAM_IN>,
54-
Param<"size_t*", "GroupSize", "maximum block size", PARAM_OUT>
53+
Param<"size_t", "SharedMemory", "dynamic shared memory required per work item in bytes", PARAM_IN>,
54+
Param<"size_t*", "GroupSize", "optimal block size", PARAM_OUT>
5555
];
5656
let returns = [
5757
Return<"OL_ERRC_SYMBOL_KIND", ["The provided symbol is not a kernel"]>,
58+
Return<"OL_ERRC_UNSUPPORTED", ["The backend cannot provide this information"]>,
5859
];
5960
}

offload/liboffload/src/OffloadImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ Error olDestroyProgram_impl(ol_program_handle_t Program) {
696696
return olDestroy(Program);
697697
}
698698

699-
Error olGetKernelMaxGroupSize_impl(ol_device_handle_t Device,
699+
Error olCalculateMaxOccupancy_impl(ol_device_handle_t Device,
700700
ol_symbol_handle_t Kernel,
701701
size_t DynamicMemSize, size_t *GroupSize) {
702702
if (Kernel->Kind != OL_SYMBOL_KIND_KERNEL)

offload/plugins-nextgen/amdgpu/src/rtl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,9 @@ struct AMDGPUKernelTy : public GenericKernelTy {
575575
/// TODO: This needs to be implemented for amdgpu
576576
Expected<uint64_t> maxGroupSize(GenericDeviceTy &GenericDevice,
577577
uint64_t DynamicMemSize) const override {
578-
return 1;
578+
return Plugin::error(
579+
ErrorCode::UNSUPPORTED,
580+
"occupancy calculations for AMDGPU are not yet implemented");
579581
}
580582

581583
/// Print more elaborate kernel launch info for AMDGPU

offload/plugins-nextgen/host/src/rtl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ struct GenELF64KernelTy : public GenericKernelTy {
117117
/// Return maximum block size for maximum occupancy
118118
Expected<uint64_t> maxGroupSize(GenericDeviceTy &Device,
119119
uint64_t DynamicMemSize) const override {
120-
// TODO
121-
return 1;
120+
return Plugin::error(
121+
ErrorCode::UNSUPPORTED,
122+
"occupancy calculations are not implemented for the host device");
122123
}
123124

124125
private:

offload/unittests/OffloadAPI/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ add_offload_unittest("init"
2020
target_compile_definitions("init.unittests" PRIVATE DISABLE_WRAPPER)
2121

2222
add_offload_unittest("kernel"
23-
kernel/olGetKernelMaxGroupSize.cpp
23+
kernel/olCalculateMaxOccupancy.cpp
2424
kernel/olLaunchKernel.cpp)
2525

2626
add_offload_unittest("memory"

offload/unittests/OffloadAPI/common/Fixtures.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@
2626
} while (0)
2727
#endif
2828

29+
#ifndef ASSERT_SUCCESS_OR_UNSUPPORTED
30+
#define ASSERT_SUCCESS_OR_UNSUPPORTED(ACTUAL) \
31+
do { \
32+
ol_result_t Res = ACTUAL; \
33+
if (Res && Res->Code == OL_ERRC_UNSUPPORTED) { \
34+
GTEST_SKIP() << #ACTUAL " returned unsupported; skipping test"; \
35+
return; \
36+
} else if (Res && Res->Code != OL_ERRC_SUCCESS) { \
37+
GTEST_FAIL() << #ACTUAL " returned " << Res->Code << ": " \
38+
<< Res->Details; \
39+
} \
40+
} while (0)
41+
#endif
42+
2943
// TODO: rework this so the EXPECTED/ACTUAL results are readable
3044
#ifndef ASSERT_ERROR
3145
#define ASSERT_ERROR(EXPECTED, ACTUAL) \
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//===------- Offload API tests - olCalculateMaxOccupancy ------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "../common/Fixtures.hpp"
10+
#include <OffloadAPI.h>
11+
#include <gtest/gtest.h>
12+
13+
using olCalculateMaxOccupancyTest = OffloadKernelTest;
14+
OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olCalculateMaxOccupancyTest);
15+
16+
TEST_P(olCalculateMaxOccupancyTest, Success) {
17+
size_t Size{0};
18+
ASSERT_SUCCESS_OR_UNSUPPORTED(olCalculateMaxOccupancy(Device, Kernel, 0, &Size));
19+
ASSERT_GT(Size, 0u);
20+
}
21+
22+
TEST_P(olCalculateMaxOccupancyTest, SuccessMem) {
23+
size_t Size{0};
24+
ASSERT_SUCCESS_OR_UNSUPPORTED(olCalculateMaxOccupancy(Device, Kernel, 1024, &Size));
25+
ASSERT_GT(Size, 0u);
26+
}
27+
28+
TEST_P(olCalculateMaxOccupancyTest, NullKernel) {
29+
size_t Size;
30+
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE,
31+
olCalculateMaxOccupancy(Device, nullptr, 0, &Size));
32+
}
33+
34+
TEST_P(olCalculateMaxOccupancyTest, NullDevice) {
35+
size_t Size;
36+
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE,
37+
olCalculateMaxOccupancy(nullptr, Kernel, 0, &Size));
38+
}
39+
40+
TEST_P(olCalculateMaxOccupancyTest, NullOutput) {
41+
ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER,
42+
olCalculateMaxOccupancy(Device, Kernel, 0, nullptr));
43+
}

offload/unittests/OffloadAPI/kernel/olGetKernelMaxGroupSize.cpp

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)