Skip to content

Commit e7420de

Browse files
fix: ocloc fatbinary handle -out_dir without -output
Currently if we pass `-out_dir` in ocloc fatbinary cmdline, e.g.: ./ocloc compile -file vector.cl ... -out_dir ../exampler_dir ocloc sets the name for the output file from the `-output` parameter. But as the `-output` parameter is not provided, the file name will be empty and won't be written to disk. This patch adds support for a scenario where you pass `-out_dir` without `-output`. In this case, the file will have default name - input file's base name. Related-To: NEO-10603 Signed-off-by: Fabian Zwolinski <[email protected]>
1 parent b3b72d0 commit e7420de

File tree

2 files changed

+83
-5
lines changed

2 files changed

+83
-5
lines changed

opencl/test/unit_test/offline_compiler/ocloc_fatbinary_tests.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,76 @@ TEST_F(OclocFatBinaryProductAcronymsTests, givenBinaryOutputNameOptionWhenBuildi
508508
}
509509
}
510510

511+
TEST_F(OclocFatBinaryProductAcronymsTests, givenBinaryOutputDirOptionWhenBuildingThenCorrectFileIsCreated) {
512+
auto acronyms = prepareProductsWithoutDashes(oclocArgHelperWithoutInput.get());
513+
if (acronyms.size() < 2) {
514+
GTEST_SKIP();
515+
}
516+
517+
std::string acronymsTarget = acronyms[0] + "," + acronyms[1];
518+
std::vector<ConstStringRef> expected{ConstStringRef(acronyms[0]), ConstStringRef(acronyms[1])};
519+
auto got = NEO::getTargetProductsForFatbinary(acronymsTarget, oclocArgHelperWithoutInput.get());
520+
EXPECT_EQ(got, expected);
521+
522+
oclocArgHelperWithoutInput->getPrinterRef().setSuppressMessages(false);
523+
524+
{
525+
std::stringstream resString;
526+
std::vector<std::string> argv = {
527+
"ocloc",
528+
"-file",
529+
clFiles + "copybuffer.cl",
530+
"-out_dir",
531+
"../expected_output_directory",
532+
"-device",
533+
acronymsTarget};
534+
535+
testing::internal::CaptureStdout();
536+
int retVal = buildFatBinary(argv, oclocArgHelperWithoutInput.get());
537+
auto output = testing::internal::GetCapturedStdout();
538+
EXPECT_EQ(retVal, OCLOC_SUCCESS);
539+
540+
const std::string expectedFatbinaryFileName = "../expected_output_directory/copybuffer.ar";
541+
EXPECT_EQ(1u, NEO::virtualFileList.size());
542+
EXPECT_TRUE(NEO::virtualFileList.find(expectedFatbinaryFileName) != NEO::virtualFileList.end());
543+
544+
for (const auto &product : expected) {
545+
resString << "Build succeeded for : " << product.str() + ".\n";
546+
}
547+
548+
EXPECT_STREQ(output.c_str(), resString.str().c_str());
549+
}
550+
551+
{
552+
std::stringstream resString;
553+
std::vector<std::string> argv = {
554+
"ocloc",
555+
"-file",
556+
clFiles + "copybuffer.cl",
557+
"-out_dir",
558+
"../expected_output_directory",
559+
"-output",
560+
"expected_filename",
561+
"-device",
562+
acronymsTarget};
563+
564+
testing::internal::CaptureStdout();
565+
int retVal = buildFatBinary(argv, oclocArgHelperWithoutInput.get());
566+
auto output = testing::internal::GetCapturedStdout();
567+
EXPECT_EQ(retVal, OCLOC_SUCCESS);
568+
569+
const std::string expectedFatbinaryFileName = "../expected_output_directory/expected_filename";
570+
EXPECT_EQ(2u, NEO::virtualFileList.size());
571+
EXPECT_TRUE(NEO::virtualFileList.find(expectedFatbinaryFileName) != NEO::virtualFileList.end());
572+
573+
for (const auto &product : expected) {
574+
resString << "Build succeeded for : " << product.str() + ".\n";
575+
}
576+
577+
EXPECT_STREQ(output.c_str(), resString.str().c_str());
578+
}
579+
}
580+
511581
TEST_F(OclocFatBinaryProductAcronymsTests, givenTwoSameReleaseTargetsWhenGetProductsAcronymsThenDuplicatesAreNotFound) {
512582
if (enabledReleasesAcronyms.empty()) {
513583
GTEST_SKIP();

shared/offline_compiler/source/ocloc_fatbinary.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -401,13 +401,21 @@ int buildFatBinary(const std::vector<std::string> &args, OclocArgHelper *argHelp
401401
}
402402

403403
auto fatbinaryData = fatbinary.encode();
404-
std::string fatbinaryFileName = outputFileName;
405-
if (outputFileName.empty() && (false == inputFileName.empty())) {
406-
fatbinaryFileName = OfflineCompiler::getFileNameTrunk(inputFileName) + ".ar";
407-
}
404+
405+
std::string fatbinaryFileName = "";
406+
408407
if (false == outputDirectory.empty()) {
409-
fatbinaryFileName = outputDirectory + "/" + outputFileName;
408+
fatbinaryFileName = outputDirectory + "/";
409+
}
410+
411+
if (false == outputFileName.empty()) {
412+
fatbinaryFileName += outputFileName;
413+
} else {
414+
if (false == inputFileName.empty()) {
415+
fatbinaryFileName += OfflineCompiler::getFileNameTrunk(inputFileName) + ".ar";
416+
}
410417
}
418+
411419
argHelper->saveOutput(fatbinaryFileName, fatbinaryData.data(), fatbinaryData.size());
412420

413421
return 0;

0 commit comments

Comments
 (0)