mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-05 09:09:04 +08:00
zebin: sanitize scratch space size
Sanitize scratch space size to value programmable on GPU. Signed-off-by: Krystian Chmielewski <krystian.chmielewski@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
7fa9cfd7fc
commit
1f6c09ba1d
@@ -3497,7 +3497,7 @@ kernels:
|
||||
EXPECT_EQ(256U * 8, programInfo.kernelInfos[0]->kernelDescriptor.kernelAttributes.perHwThreadPrivateMemorySize);
|
||||
}
|
||||
|
||||
TEST(PopulateKernelDescriptor, GivenPerThreadMemoryBufferWhenTypeIsScratchThenSetsProperFieldsInDescriptor) {
|
||||
TEST(PopulateKernelDescriptor, GivenPerThreadMemoryBufferOfSizeSmallerThanMinimalWhenTypeIsScratchThenSetsProperFieldsInDescriptor) {
|
||||
NEO::ConstStringRef zeinfo = R"===(
|
||||
kernels:
|
||||
- name : some_kernel
|
||||
@@ -3509,6 +3509,8 @@ kernels:
|
||||
size: 512
|
||||
)===";
|
||||
NEO::ProgramInfo programInfo;
|
||||
programInfo.minScratchSpaceSize = 1024U;
|
||||
|
||||
ZebinTestData::ValidEmptyProgram zebin;
|
||||
zebin.appendSection(NEO::Elf::SHT_PROGBITS, NEO::Elf::SectionsNamesZebin::textPrefix.str() + "some_kernel", {});
|
||||
std::string errors, warnings;
|
||||
@@ -3529,7 +3531,45 @@ kernels:
|
||||
EXPECT_TRUE(errors.empty()) << errors;
|
||||
EXPECT_TRUE(warnings.empty()) << warnings;
|
||||
ASSERT_EQ(1U, programInfo.kernelInfos.size());
|
||||
EXPECT_EQ(512U, programInfo.kernelInfos[0]->kernelDescriptor.kernelAttributes.perThreadScratchSize[0]);
|
||||
EXPECT_EQ(1024U, programInfo.kernelInfos[0]->kernelDescriptor.kernelAttributes.perThreadScratchSize[0]);
|
||||
EXPECT_EQ(0U, programInfo.kernelInfos[0]->kernelDescriptor.kernelAttributes.perThreadScratchSize[1]);
|
||||
}
|
||||
|
||||
TEST(PopulateKernelDescriptor, GivenPerThreadMemoryBufferOfSizeBiggerThanMinimalWhenTypeIsScratchThenSetsProperFieldsInDescriptor) {
|
||||
NEO::ConstStringRef zeinfo = R"===(
|
||||
kernels:
|
||||
- name : some_kernel
|
||||
execution_env:
|
||||
simd_size: 8
|
||||
per_thread_memory_buffers:
|
||||
- type: scratch
|
||||
usage: private_space
|
||||
size: 1540
|
||||
)===";
|
||||
NEO::ProgramInfo programInfo;
|
||||
programInfo.minScratchSpaceSize = 1024U;
|
||||
|
||||
ZebinTestData::ValidEmptyProgram zebin;
|
||||
zebin.appendSection(NEO::Elf::SHT_PROGBITS, NEO::Elf::SectionsNamesZebin::textPrefix.str() + "some_kernel", {});
|
||||
std::string errors, warnings;
|
||||
auto elf = NEO::Elf::decodeElf(zebin.storage, errors, warnings);
|
||||
ASSERT_NE(nullptr, elf.elfFileHeader) << errors << " " << warnings;
|
||||
|
||||
NEO::Yaml::YamlParser parser;
|
||||
bool parseSuccess = parser.parse(zeinfo, errors, warnings);
|
||||
ASSERT_TRUE(parseSuccess) << errors << " " << warnings;
|
||||
|
||||
NEO::ZebinSections zebinSections;
|
||||
auto extractErr = NEO::extractZebinSections(elf, zebinSections, errors, warnings);
|
||||
ASSERT_EQ(NEO::DecodeError::Success, extractErr) << errors << " " << warnings;
|
||||
|
||||
auto &kernelNode = *parser.createChildrenRange(*parser.findNodeWithKeyDfs("kernels")).begin();
|
||||
auto err = NEO::populateKernelDescriptor(programInfo, elf, zebinSections, parser, kernelNode, errors, warnings);
|
||||
EXPECT_EQ(NEO::DecodeError::Success, err);
|
||||
EXPECT_TRUE(errors.empty()) << errors;
|
||||
EXPECT_TRUE(warnings.empty()) << warnings;
|
||||
ASSERT_EQ(1U, programInfo.kernelInfos.size());
|
||||
EXPECT_EQ(2048U, programInfo.kernelInfos[0]->kernelDescriptor.kernelAttributes.perThreadScratchSize[0]);
|
||||
EXPECT_EQ(0U, programInfo.kernelInfos[0]->kernelDescriptor.kernelAttributes.perThreadScratchSize[1]);
|
||||
}
|
||||
|
||||
@@ -3542,7 +3582,7 @@ kernels:
|
||||
per_thread_memory_buffers:
|
||||
- type: scratch
|
||||
usage: private_space
|
||||
size: 512
|
||||
size: 1024
|
||||
slot : 1
|
||||
)===";
|
||||
NEO::ProgramInfo programInfo;
|
||||
@@ -3567,7 +3607,7 @@ kernels:
|
||||
EXPECT_TRUE(warnings.empty()) << warnings;
|
||||
ASSERT_EQ(1U, programInfo.kernelInfos.size());
|
||||
EXPECT_EQ(0U, programInfo.kernelInfos[0]->kernelDescriptor.kernelAttributes.perThreadScratchSize[0]);
|
||||
EXPECT_EQ(512U, programInfo.kernelInfos[0]->kernelDescriptor.kernelAttributes.perThreadScratchSize[1]);
|
||||
EXPECT_EQ(1024U, programInfo.kernelInfos[0]->kernelDescriptor.kernelAttributes.perThreadScratchSize[1]);
|
||||
}
|
||||
|
||||
TEST(PopulateKernelDescriptor, GivenPerThreadMemoryBufferWhenSlotIsInvalidThenFails) {
|
||||
@@ -3604,6 +3644,39 @@ kernels:
|
||||
EXPECT_TRUE(warnings.empty()) << warnings;
|
||||
}
|
||||
|
||||
TEST(PopulateKernelDescriptor, GivenPerThreadMemoryBufferWithInvalidSizeThenErrorIsReturned) {
|
||||
NEO::ConstStringRef zeinfo = R"===(
|
||||
kernels:
|
||||
- name : some_kernel
|
||||
execution_env:
|
||||
simd_size: 8
|
||||
per_thread_memory_buffers:
|
||||
- type: scratch
|
||||
usage: private_space
|
||||
size: 0
|
||||
)===";
|
||||
NEO::ProgramInfo programInfo;
|
||||
ZebinTestData::ValidEmptyProgram zebin;
|
||||
zebin.appendSection(NEO::Elf::SHT_PROGBITS, NEO::Elf::SectionsNamesZebin::textPrefix.str() + "some_kernel", {});
|
||||
std::string errors, warnings;
|
||||
auto elf = NEO::Elf::decodeElf(zebin.storage, errors, warnings);
|
||||
ASSERT_NE(nullptr, elf.elfFileHeader) << errors << " " << warnings;
|
||||
|
||||
NEO::Yaml::YamlParser parser;
|
||||
bool parseSuccess = parser.parse(zeinfo, errors, warnings);
|
||||
ASSERT_TRUE(parseSuccess) << errors << " " << warnings;
|
||||
|
||||
NEO::ZebinSections zebinSections;
|
||||
auto extractErr = NEO::extractZebinSections(elf, zebinSections, errors, warnings);
|
||||
ASSERT_EQ(NEO::DecodeError::Success, extractErr) << errors << " " << warnings;
|
||||
|
||||
auto &kernelNode = *parser.createChildrenRange(*parser.findNodeWithKeyDfs("kernels")).begin();
|
||||
auto err = NEO::populateKernelDescriptor(programInfo, elf, zebinSections, parser, kernelNode, errors, warnings);
|
||||
EXPECT_EQ(NEO::DecodeError::InvalidBinary, err);
|
||||
EXPECT_STREQ("DeviceBinaryFormat::Zebin : Invalid per-thread memory buffer allocation size (size must be greater than 0) in context of : some_kernel.\n", errors.c_str());
|
||||
EXPECT_TRUE(warnings.empty()) << warnings;
|
||||
}
|
||||
|
||||
TEST(PopulateKernelDescriptor, GivenPerThreadMemoryBufferWithMultipleScratchEntriesForTheSameSlotThenFails) {
|
||||
NEO::ConstStringRef zeinfo = R"===(
|
||||
kernels:
|
||||
|
||||
Reference in New Issue
Block a user