Skip to content

Commit 7c34687

Browse files
fix: add option to enable/disable heapless in ocloc
Related-To: GSD-10681 Signed-off-by: Kamil Kopryk <[email protected]>
1 parent b10c6b4 commit 7c34687

File tree

8 files changed

+75
-9
lines changed

8 files changed

+75
-9
lines changed

level_zero/core/source/module/module_imp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ std::string ModuleTranslationUnit::generateCompilerOptions(const char *buildOpti
155155
bool isDebuggerActive = neoDevice.getDebugger() != nullptr;
156156
NEO::CompilerOptions::concatenateAppend(internalOptions, compilerProductHelper.getCachingPolicyOptions(isDebuggerActive));
157157

158-
NEO::CompilerOptions::applyExtraInternalOptions(internalOptions, compilerProductHelper);
158+
NEO::CompilerOptions::applyExtraInternalOptions(internalOptions, compilerProductHelper, NEO::CompilerOptions::HeaplessMode::defaultMode);
159159
return internalOptions;
160160
}
161161

opencl/source/program/program.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ std::string Program::getInternalOptions() const {
109109
CompilerOptions::concatenateAppend(internalOptions, CompilerOptions::preserveVec3Type);
110110
auto isDebuggerActive = pClDevice->getDevice().getDebugger() != nullptr;
111111
CompilerOptions::concatenateAppend(internalOptions, compilerProductHelper.getCachingPolicyOptions(isDebuggerActive));
112-
CompilerOptions::applyExtraInternalOptions(internalOptions, compilerProductHelper);
112+
CompilerOptions::applyExtraInternalOptions(internalOptions, compilerProductHelper, NEO::CompilerOptions::HeaplessMode::defaultMode);
113113

114114
return internalOptions;
115115
}

opencl/test/unit_test/offline_compiler/offline_compiler_tests.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2024 Intel Corporation
2+
* Copyright (C) 2018-2025 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -4606,6 +4606,44 @@ TEST(OclocCompile, GivenStatefulAddressModeWhenInvalidArgsPAssedThenErrorIsRetur
46064606
EXPECT_STRNE(output.c_str(), "");
46074607
}
46084608

4609+
TEST(OclocCompile, GivenInvalidHeaplessModeOptionWhenOclocArgsAreParsedThenErrorIsReturned) {
4610+
4611+
MockOfflineCompiler ocloc;
4612+
std::vector<std::string> args = {
4613+
"ocloc",
4614+
"-file",
4615+
clFiles + "copybuffer.cl",
4616+
"-device",
4617+
gEnvironment->devicePrefix.c_str(),
4618+
"-heapless_mode",
4619+
"invalid"};
4620+
testing::internal::CaptureStdout();
4621+
int retVal = ocloc.parseCommandLine(args.size(), args);
4622+
EXPECT_EQ(OCLOC_INVALID_COMMAND_LINE, retVal);
4623+
std::string output = testing::internal::GetCapturedStdout();
4624+
EXPECT_STRNE(output.c_str(), "");
4625+
}
4626+
4627+
TEST(OclocCompile, GivenValidHeaplessModeOptionWhenOclocArgsAreParsedThenSuccessIsReturned) {
4628+
4629+
for (auto heaplessMode : {"enable", "disable", "default"}) {
4630+
MockOfflineCompiler ocloc;
4631+
std::vector<std::string> args = {
4632+
"ocloc",
4633+
"-file",
4634+
clFiles + "copybuffer.cl",
4635+
"-device",
4636+
gEnvironment->devicePrefix.c_str(),
4637+
"-heapless_mode",
4638+
heaplessMode};
4639+
testing::internal::CaptureStdout();
4640+
int retVal = ocloc.parseCommandLine(args.size(), args);
4641+
EXPECT_EQ(OCLOC_SUCCESS, retVal);
4642+
std::string output = testing::internal::GetCapturedStdout();
4643+
EXPECT_STREQ(output.c_str(), "");
4644+
}
4645+
}
4646+
46094647
TEST(OclocCompile, GivenStatefulAddressModeSetToBindlessWhenBuildThenBindlessModeInternalOptionsAreAdded) {
46104648
MockOfflineCompiler ocloc;
46114649

shared/offline_compiler/source/offline_compiler.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,19 @@ int OfflineCompiler::parseCommandLine(size_t numArgs, const std::vector<std::str
10751075
} else if ("-stateful_address_mode" == currArg) {
10761076
addressingMode = argv[argIndex + 1];
10771077
argIndex++;
1078+
} else if (("-heapless_mode" == currArg) && hasMoreArgs) {
1079+
if (argv[argIndex + 1] == "enable") {
1080+
heaplessMode = CompilerOptions::HeaplessMode::enabled;
1081+
} else if (argv[argIndex + 1] == "disable") {
1082+
heaplessMode = CompilerOptions::HeaplessMode::disabled;
1083+
} else if (argv[argIndex + 1] == "default") {
1084+
heaplessMode = CompilerOptions::HeaplessMode::defaultMode;
1085+
} else {
1086+
argHelper->printf("Error: Invalid heapless mode.\n");
1087+
retVal = OCLOC_INVALID_COMMAND_LINE;
1088+
break;
1089+
}
1090+
argIndex++;
10781091
} else if (("-config" == currArg) && hasMoreArgs) {
10791092
parseHwInfoConfigString(argv[argIndex + 1], hwInfoConfig);
10801093
if (!hwInfoConfig) {
@@ -1189,7 +1202,7 @@ void OfflineCompiler::appendExtraInternalOptions(std::string &internalOptions) {
11891202
}
11901203

11911204
CompilerOptions::concatenateAppend(internalOptions, compilerProductHelper->getCachingPolicyOptions(false));
1192-
CompilerOptions::applyExtraInternalOptions(internalOptions, *compilerProductHelper);
1205+
CompilerOptions::applyExtraInternalOptions(internalOptions, *compilerProductHelper, this->heaplessMode);
11931206
}
11941207

11951208
void OfflineCompiler::parseDebugSettings() {
@@ -1412,6 +1425,11 @@ Usage: ocloc [compile] -file <filename> -device <device_type> [-output <filename
14121425
-stateful_address_mode default - default mode
14131426
not defined: default mode.
14141427
1428+
-heapless_mode Enforce heapless mode for the binary. The possible values are:
1429+
-heapless_mode enable - enforce generating in heapless mode
1430+
-heapless_mode disable - enforce generating in heapful mode
1431+
-heapless_mode default - default mode for current platform
1432+
14151433
-config Target hardware info config for a single device,
14161434
e.g 1x4x8.
14171435

shared/offline_compiler/source/offline_compiler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#pragma once
99

1010
#include "shared/offline_compiler/source/ocloc_api.h"
11+
#include "shared/source/compiler_interface/compiler_options.h"
1112
#include "shared/source/helpers/hw_info.h"
1213
#include "shared/source/helpers/non_copyable_or_moveable.h"
1314
#include "shared/source/utilities/arrayref.h"
@@ -199,6 +200,7 @@ All supported acronyms: %s.
199200
std::string internalOptionsReadFromFile = "";
200201
std::string formatToEnforce = "";
201202
std::string addressingMode = "default";
203+
CompilerOptions::HeaplessMode heaplessMode = CompilerOptions::HeaplessMode::defaultMode;
202204
std::string irHash, genHash, dbgHash, elfHash;
203205
std::string cacheDir;
204206

shared/source/compiler_interface/compiler_options.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2024 Intel Corporation
2+
* Copyright (C) 2019-2025 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -184,5 +184,12 @@ std::string wrapInQuotes(const std::string &stringToWrap);
184184

185185
void applyAdditionalInternalOptions(std::string &internalOptions);
186186
void applyAdditionalApiOptions(std::string &apiOptions);
187+
188+
enum class HeaplessMode {
189+
enabled,
190+
disabled,
191+
defaultMode,
192+
};
193+
187194
} // namespace CompilerOptions
188195
} // namespace NEO

shared/source/compiler_interface/compiler_options_extra.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2023 Intel Corporation
2+
* Copyright (C) 2023-2025 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -9,7 +9,7 @@
99

1010
namespace NEO {
1111
namespace CompilerOptions {
12-
void applyExtraInternalOptions(std::string &internalOptions, const CompilerProductHelper &compilerProductHelper) {
12+
void applyExtraInternalOptions(std::string &internalOptions, const CompilerProductHelper &compilerProductHelper, HeaplessMode heaplessMode) {
1313
}
1414

1515
} // namespace CompilerOptions

shared/source/compiler_interface/compiler_options_extra.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2023 Intel Corporation
2+
* Copyright (C) 2023-2025 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -13,8 +13,9 @@ namespace NEO {
1313
class CompilerProductHelper;
1414

1515
namespace CompilerOptions {
16+
enum class HeaplessMode;
1617

17-
void applyExtraInternalOptions(std::string &internalOptions, const CompilerProductHelper &compilerProductHelper);
18+
void applyExtraInternalOptions(std::string &internalOptions, const CompilerProductHelper &compilerProductHelper, CompilerOptions::HeaplessMode heaplessMode);
1819

1920
} // namespace CompilerOptions
2021
} // namespace NEO

0 commit comments

Comments
 (0)