Skip to content

Commit df2e76f

Browse files
jchodorCompute-Runtime-Automation
authored andcommitted
Fixing residency of extern device functions
Change-Id: Icad696cbf6fb3fc0276f0d0d488bf92091525d9b
1 parent 51dccca commit df2e76f

File tree

7 files changed

+29
-10
lines changed

7 files changed

+29
-10
lines changed

level_zero/core/source/kernel/kernel.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ struct KernelImmutableData {
4141
return residencyContainer;
4242
}
4343

44+
std::vector<NEO::GraphicsAllocation *> &getResidencyContainer() {
45+
return residencyContainer;
46+
}
47+
4448
uint32_t getIsaSize() const;
4549
NEO::GraphicsAllocation *getIsaGraphicsAllocation() const { return isaGraphicsAllocation.get(); }
4650

level_zero/core/source/kernel/kernel_imp.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -698,12 +698,8 @@ ze_result_t KernelImp::initialize(const ze_kernel_desc_t *desc) {
698698

699699
this->setDebugSurface();
700700

701-
for (auto &alloc : kernelImmData->getResidencyContainer()) {
702-
residencyContainer.push_back(alloc);
703-
}
704-
for (auto &alloc : module->getImportedSymbolAllocations()) {
705-
residencyContainer.push_back(alloc);
706-
}
701+
residencyContainer.insert(residencyContainer.end(), kernelImmData->getResidencyContainer().begin(),
702+
kernelImmData->getResidencyContainer().end());
707703

708704
return ZE_RESULT_SUCCESS;
709705
}

level_zero/core/source/module/module.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ struct Module : _ze_module_handle_t {
4545
virtual const std::vector<std::unique_ptr<KernelImmutableData>> &getKernelImmutableDataVector() const = 0;
4646
virtual uint32_t getMaxGroupSize() const = 0;
4747
virtual bool isDebugEnabled() const = 0;
48-
virtual const std::set<NEO::GraphicsAllocation *> &getImportedSymbolAllocations() const = 0;
4948

5049
Module() = default;
5150
Module(const Module &) = delete;

level_zero/core/source/module/module_imp.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,16 @@ bool ModuleImp::linkBinary() {
481481
}
482482
DBG_LOG(PrintRelocations, NEO::constructRelocationsDebugMessage(this->symbols));
483483
isFullyLinked = true;
484+
for (auto &kernImmData : this->kernelImmDatas) {
485+
kernImmData->getResidencyContainer().reserve(kernImmData->getResidencyContainer().size() +
486+
((this->exportedFunctionsSurface != nullptr) ? 1 : 0) + this->importedSymbolAllocations.size());
487+
488+
if (nullptr != this->exportedFunctionsSurface) {
489+
kernImmData->getResidencyContainer().push_back(this->exportedFunctionsSurface);
490+
}
491+
kernImmData->getResidencyContainer().insert(kernImmData->getResidencyContainer().end(), this->importedSymbolAllocations.begin(),
492+
this->importedSymbolAllocations.end());
493+
}
484494
return true;
485495
}
486496

level_zero/core/source/module/module_imp.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ struct ModuleImp : public Module {
114114
return this->translationUnit.get();
115115
}
116116

117-
const std::set<NEO::GraphicsAllocation *> &getImportedSymbolAllocations() const override { return importedSymbolAllocations; }
118-
119117
protected:
120118
void copyPatchedSegments(const NEO::Linker::PatchableSegments &isaSegmentsForPatching);
121119
void verifyDebugCapabilities();

level_zero/core/test/unit_tests/mocks/mock_module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct WhiteBox<::L0::Module> : public ::L0::ModuleImp {
2323
using BaseClass = ::L0::ModuleImp;
2424
using BaseClass::BaseClass;
2525
using BaseClass::device;
26+
using BaseClass::exportedFunctionsSurface;
2627
using BaseClass::isFullyLinked;
2728
using BaseClass::kernelImmDatas;
2829
using BaseClass::symbols;
@@ -34,7 +35,6 @@ using Module = WhiteBox<::L0::Module>;
3435

3536
template <>
3637
struct Mock<Module> : public Module {
37-
Mock() = delete;
3838
Mock(::L0::Device *device, ModuleBuildLog *moduleBuildLog);
3939

4040
MOCK_METHOD(ze_result_t, createKernel, (const ze_kernel_desc_t *desc, ze_kernel_handle_t *phFunction), (override));

level_zero/core/test/unit_tests/sources/module/test_module.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "shared/test/unit_test/device_binary_format/zebin_tests.h"
1010

1111
#include "opencl/source/program/kernel_info.h"
12+
#include "opencl/test/unit_test/mocks/mock_graphics_allocation.h"
1213
#include "test.h"
1314

1415
#include "level_zero/core/source/context/context.h"
@@ -180,6 +181,17 @@ HWTEST_F(ModuleSpecConstantsTests, givenSpecializationConstantsSetInDescriptorTh
180181

181182
using ModuleLinkingTest = Test<DeviceFixture>;
182183

184+
HWTEST_F(ModuleLinkingTest, whenExternFunctionsAllocationIsPresentThenItsBeingAddedToResidencyContainer) {
185+
Mock<Module> module(device, nullptr);
186+
MockGraphicsAllocation alloc;
187+
module.exportedFunctionsSurface = &alloc;
188+
module.kernelImmDatas.push_back(std::make_unique<L0::KernelImmutableData>());
189+
module.translationUnit->programInfo.linkerInput.reset(new NEO::LinkerInput);
190+
module.linkBinary();
191+
ASSERT_EQ(1U, module.kernelImmDatas[0]->getResidencyContainer().size());
192+
EXPECT_EQ(&alloc, module.kernelImmDatas[0]->getResidencyContainer()[0]);
193+
}
194+
183195
HWTEST_F(ModuleLinkingTest, givenFailureDuringLinkingWhenCreatingModuleThenModuleInitialiationFails) {
184196
auto mockCompiler = new MockCompilerInterface();
185197
auto rootDeviceEnvironment = neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0].get();

0 commit comments

Comments
 (0)