diff --git a/level_zero/core/source/module/module_imp.cpp b/level_zero/core/source/module/module_imp.cpp index 3c711ef8c2..aff5b9a3d9 100644 --- a/level_zero/core/source/module/module_imp.cpp +++ b/level_zero/core/source/module/module_imp.cpp @@ -50,6 +50,7 @@ NEO::ConstStringRef greaterThan4GbRequired = "-ze-opt-greater-than-4GB-buffer-re NEO::ConstStringRef hasBufferOffsetArg = "-ze-intel-has-buffer-offset-arg"; NEO::ConstStringRef debugKernelEnable = "-ze-kernel-debug-enable"; NEO::ConstStringRef enableLibraryCompile = "-library-compilation"; +NEO::ConstStringRef enableGlobalVariableSymbols = "-take-global-address"; } // namespace BuildOptions ModuleTranslationUnit::ModuleTranslationUnit(L0::Device *device) @@ -667,7 +668,7 @@ void ModuleImp::createBuildOptions(const char *pBuildFlags, std::string &apiOpti moveBuildOption(internalBuildOptions, apiOptions, NEO::CompilerOptions::greaterThan4gbBuffersRequired, BuildOptions::greaterThan4GbRequired); moveBuildOption(internalBuildOptions, apiOptions, NEO::CompilerOptions::allowZebin, NEO::CompilerOptions::allowZebin); this->libraryExportEnabled = moveBuildOption(apiOptions, apiOptions, BuildOptions::enableLibraryCompile, BuildOptions::enableLibraryCompile); - + this->globalExportEnabled = moveBuildOption(apiOptions, apiOptions, BuildOptions::enableGlobalVariableSymbols, BuildOptions::enableGlobalVariableSymbols); createBuildExtraOptions(apiOptions, internalBuildOptions); } if (NEO::ApiSpecificConfig::getBindlessConfiguration()) { @@ -676,6 +677,9 @@ void ModuleImp::createBuildOptions(const char *pBuildFlags, std::string &apiOpti if (!this->libraryExportEnabled && NEO::DebugManager.flags.EnableProgramSymbolTableGeneration.get()) { NEO::CompilerOptions::concatenateAppend(apiOptions, BuildOptions::enableLibraryCompile.str()); } + if (!this->globalExportEnabled && NEO::DebugManager.flags.EnableGlobalSymbolGeneration.get()) { + NEO::CompilerOptions::concatenateAppend(apiOptions, BuildOptions::enableGlobalVariableSymbols.str()); + } } void ModuleImp::updateBuildLog(NEO::Device *neoDevice) { diff --git a/level_zero/core/source/module/module_imp.h b/level_zero/core/source/module/module_imp.h index 312a480fc4..b71628b4c5 100644 --- a/level_zero/core/source/module/module_imp.h +++ b/level_zero/core/source/module/module_imp.h @@ -31,6 +31,7 @@ extern NEO::ConstStringRef greaterThan4GbRequired; extern NEO::ConstStringRef hasBufferOffsetArg; extern NEO::ConstStringRef debugKernelEnable; extern NEO::ConstStringRef enableLibraryCompile; +extern NEO::ConstStringRef enableGlobalVariableSymbols; } // namespace BuildOptions struct ModuleTranslationUnit { @@ -160,6 +161,7 @@ struct ModuleImp : public Module { bool isFullyLinked = false; bool allocatePrivateMemoryPerDispatch = true; bool libraryExportEnabled = false; + bool globalExportEnabled = false; ModuleType type; NEO::Linker::UnresolvedExternals unresolvedExternalsInfo{}; std::set importedSymbolAllocations{}; diff --git a/level_zero/core/test/unit_tests/sources/module/test_module.cpp b/level_zero/core/test/unit_tests/sources/module/test_module.cpp index 913089846a..d34e524773 100644 --- a/level_zero/core/test/unit_tests/sources/module/test_module.cpp +++ b/level_zero/core/test/unit_tests/sources/module/test_module.cpp @@ -2477,6 +2477,62 @@ TEST_F(ModuleTest, givenBuildOptionsWithEnableLibraryCompileWhenEnableProgramSym EXPECT_TRUE(NEO::CompilerOptions::contains(buildOptions, BuildOptions::enableLibraryCompile)); } +TEST_F(ModuleTest, givenBuildOptionsWhenEnableGlobalSymbolGenerationIsEnabledThenEnableGlobalVariableSymbolsIsSet) { + DebugManagerStateRestore restorer; + DebugManager.flags.EnableGlobalSymbolGeneration.set(1); + auto module = std::make_unique(device, nullptr, ModuleType::User); + ASSERT_NE(nullptr, module); + + std::string buildOptions; + std::string internalBuildOptions; + + module->createBuildOptions("", buildOptions, internalBuildOptions); + + EXPECT_TRUE(NEO::CompilerOptions::contains(buildOptions, BuildOptions::enableGlobalVariableSymbols)); +} + +TEST_F(ModuleTest, givenBuildOptionsWhenEnableGlobalSymbolGenerationIsDisabledThenEnableGlobalVariableSymbolsIsNotSet) { + DebugManagerStateRestore restorer; + DebugManager.flags.EnableGlobalSymbolGeneration.set(0); + auto module = std::make_unique(device, nullptr, ModuleType::User); + ASSERT_NE(nullptr, module); + + std::string buildOptions; + std::string internalBuildOptions; + + module->createBuildOptions("", buildOptions, internalBuildOptions); + + EXPECT_FALSE(NEO::CompilerOptions::contains(buildOptions, BuildOptions::enableGlobalVariableSymbols)); +} + +TEST_F(ModuleTest, givenBuildOptionsWithEnableGlobalVariableSymbolsWhenEnableGlobalSymbolGenerationIsDisabledThenEnableGlobalVariableSymbolsIsSet) { + DebugManagerStateRestore restorer; + DebugManager.flags.EnableGlobalSymbolGeneration.set(0); + auto module = std::make_unique(device, nullptr, ModuleType::User); + ASSERT_NE(nullptr, module); + + std::string buildOptions; + std::string internalBuildOptions; + + module->createBuildOptions(BuildOptions::enableGlobalVariableSymbols.str().c_str(), buildOptions, internalBuildOptions); + + EXPECT_TRUE(NEO::CompilerOptions::contains(buildOptions, BuildOptions::enableGlobalVariableSymbols)); +} + +TEST_F(ModuleTest, givenBuildOptionsWithEnableGlobalVariableSymbolsWhenEnableGlobalSymbolGenerationIsEnabledThenEnableGlobalVariableSymbolsIsSet) { + DebugManagerStateRestore restorer; + DebugManager.flags.EnableGlobalSymbolGeneration.set(1); + auto module = std::make_unique(device, nullptr, ModuleType::User); + ASSERT_NE(nullptr, module); + + std::string buildOptions; + std::string internalBuildOptions; + + module->createBuildOptions(BuildOptions::enableGlobalVariableSymbols.str().c_str(), buildOptions, internalBuildOptions); + + EXPECT_TRUE(NEO::CompilerOptions::contains(buildOptions, BuildOptions::enableGlobalVariableSymbols)); +} + TEST_F(ModuleTest, givenInternalOptionsWhenBindlessEnabledThenBindlesOptionsPassed) { DebugManagerStateRestore restorer; DebugManager.flags.UseBindlessMode.set(1); diff --git a/shared/source/debug_settings/debug_variables_base.inl b/shared/source/debug_settings/debug_variables_base.inl index f63dca9bec..3975217254 100644 --- a/shared/source/debug_settings/debug_variables_base.inl +++ b/shared/source/debug_settings/debug_variables_base.inl @@ -335,6 +335,7 @@ DECLARE_DEBUG_VARIABLE(bool, EngineInstancedSubDevices, false, "Create subdevice DECLARE_DEBUG_VARIABLE(bool, AllowSingleTileEngineInstancedSubDevices, false, "Create subdevices assigned to specific engine on single tile config") DECLARE_DEBUG_VARIABLE(bool, EnablePrivateBO, false, "Enable PRELIM_I915_GEM_CREATE_EXT_VM_PRIVATE extension creating VM_PRIVATE BOs") DECLARE_DEBUG_VARIABLE(bool, EnableProgramSymbolTableGeneration, true, "Enforce IGC to always generate the Program Symbol Table for Exported Functions for all Modules used by Level Zero.") +DECLARE_DEBUG_VARIABLE(bool, EnableGlobalSymbolGeneration, true, "Enforce IGC to always generate the Symbol Table Entry for Global Variables for all Modules used by Level Zero") DECLARE_DEBUG_VARIABLE(int32_t, ReturnSubDevicesAsApiDevices, -1, "Expose each subdevice as a separate device during clGetDeviceIDs or zeDeviceGet API call") DECLARE_DEBUG_VARIABLE(int32_t, ForceRunAloneContext, -1, "Control creation of run-alone HW context, -1:default, 0:disable, 1:enable") DECLARE_DEBUG_VARIABLE(int32_t, AddClGlSharing, -1, "Add cl-gl extension") diff --git a/shared/test/common/test_files/igdrcl.config b/shared/test/common/test_files/igdrcl.config index d8ede563a1..9414640c57 100644 --- a/shared/test/common/test_files/igdrcl.config +++ b/shared/test/common/test_files/igdrcl.config @@ -351,6 +351,7 @@ OverrideDrmRegion = -1 AllowSingleTileEngineInstancedSubDevices = 0 EnableProgramSymbolTableGeneration = 1 BinaryCacheTrace = false +EnableGlobalSymbolGeneration = 1 OverrideL1CacheControlInSurfaceState = -1 OverrideL1CacheControlInSurfaceStateForScratchSpace = -1 OverridePreferredSlmAllocationSizePerDss = -1