mirror of
https://github.com/intel/compute-runtime.git
synced 2025-11-15 10:14:56 +08:00
Revert "Remove Support for reading a function pointer of a kernel"
This reverts commit 299dcb8bd2.
Signed-off-by: Compute-Runtime-Validation <compute-runtime-validation@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
00ff0dc337
commit
f4c8a146eb
@@ -899,12 +899,30 @@ bool ModuleImp::linkBinary() {
|
||||
}
|
||||
|
||||
ze_result_t ModuleImp::getFunctionPointer(const char *pFunctionName, void **pfnFunction) {
|
||||
// Check if the function is in the exported symbol table, if the symbol cannot be found then this function name is invalid.
|
||||
// Check if the function is in the exported symbol table
|
||||
auto symbolIt = symbols.find(pFunctionName);
|
||||
if ((symbolIt == symbols.end()) || (symbolIt->second.symbol.segment != NEO::SegmentType::Instructions)) {
|
||||
if ((symbolIt != symbols.end()) && (symbolIt->second.symbol.segment == NEO::SegmentType::Instructions)) {
|
||||
*pfnFunction = reinterpret_cast<void *>(symbolIt->second.gpuAddress);
|
||||
}
|
||||
// If the Function Pointer is not in the exported symbol table, then this function might be a kernel.
|
||||
// Check if the function name matches a kernel and return the gpu address to that function
|
||||
if (*pfnFunction == nullptr) {
|
||||
auto kernelImmData = this->getKernelImmutableData(pFunctionName);
|
||||
if (kernelImmData != nullptr) {
|
||||
auto isaAllocation = kernelImmData->getIsaGraphicsAllocation();
|
||||
*pfnFunction = reinterpret_cast<void *>(isaAllocation->getGpuAddress());
|
||||
// Ensure that any kernel in this module which uses this kernel module function pointer has access to the memory.
|
||||
for (auto &data : this->getKernelImmutableDataVector()) {
|
||||
if (data.get() != kernelImmData) {
|
||||
data.get()->getResidencyContainer().insert(data.get()->getResidencyContainer().end(), isaAllocation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (*pfnFunction == nullptr) {
|
||||
return ZE_RESULT_ERROR_INVALID_FUNCTION_NAME;
|
||||
}
|
||||
*pfnFunction = reinterpret_cast<void *>(symbolIt->second.gpuAddress);
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -1801,6 +1801,41 @@ TEST_F(ModuleFunctionPointerTests, givenInvalidFunctionNameAndModuleWithExported
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_FUNCTION_NAME, res);
|
||||
}
|
||||
|
||||
TEST_F(ModuleFunctionPointerTests, givenModuleWithExportedSymbolThenGetFunctionPointerReturnsGpuAddressToKernelFunction) {
|
||||
|
||||
uint64_t gpuAddress = 0x12345;
|
||||
|
||||
NEO::SymbolInfo symbolInfo{};
|
||||
symbolInfo.segment = NEO::SegmentType::Instructions;
|
||||
NEO::Linker::RelocatedSymbol relocatedSymbol{symbolInfo, gpuAddress};
|
||||
|
||||
char kernelHeap[MemoryConstants::pageSize] = {};
|
||||
|
||||
auto kernelInfo = std::make_unique<NEO::KernelInfo>();
|
||||
kernelInfo->heapInfo.pKernelHeap = kernelHeap;
|
||||
kernelInfo->heapInfo.KernelHeapSize = MemoryConstants::pageSize;
|
||||
kernelInfo->kernelDescriptor.kernelMetadata.kernelName = "kernelFunction";
|
||||
module0->getTranslationUnit()->programInfo.kernelInfos.push_back(kernelInfo.release());
|
||||
NEO::KernelDescriptor kernelDescriptor;
|
||||
kernelDescriptor.kernelMetadata.kernelName = "kernelFunction";
|
||||
|
||||
auto kernelImmData = std::make_unique<WhiteBox<::L0::KernelImmutableData>>(device);
|
||||
kernelImmData->isaGraphicsAllocation.reset(neoDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(
|
||||
{device->getRootDeviceIndex(), MemoryConstants::pageSize, NEO::AllocationType::KERNEL_ISA, neoDevice->getDeviceBitfield()}));
|
||||
|
||||
kernelImmData->kernelDescriptor = &kernelDescriptor;
|
||||
|
||||
module0->kernelImmDatas.push_back(std::move(kernelImmData));
|
||||
|
||||
module0->symbols["externalFunction"] = relocatedSymbol;
|
||||
|
||||
void *functionPointer = nullptr;
|
||||
ze_result_t res = module0->getFunctionPointer("kernelFunction", &functionPointer);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
|
||||
EXPECT_EQ(reinterpret_cast<uint64_t>(functionPointer), module0->kernelImmDatas[0]->getIsaGraphicsAllocation()->getGpuAddress());
|
||||
}
|
||||
|
||||
class DeviceModuleSetArgBufferTest : public ModuleFixture, public ::testing::Test {
|
||||
public:
|
||||
void SetUp() override {
|
||||
|
||||
Reference in New Issue
Block a user