P4 to Git Change 1393413 by gandryey@gera-w8 on 2017/03/31 15:38:06

SWDEV-79445 - OCL generic changes and code clean-up
	- Add OCL_STUB_PROGRAMS it allows to dumps the original OCL programs with unique name and reuse possibly modified versions on the second run.

Affected files ...

... //depot/stg/opencl/drivers/opencl/runtime/device/appprofile.hpp#11 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/program.cpp#85 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/program.hpp#40 edit
... //depot/stg/opencl/drivers/opencl/runtime/utils/flags.hpp#268 edit
This commit is contained in:
foreman
2017-03-31 15:51:21 -04:00
parent a708eb45ce
commit 1c46212c4b
4 changed files with 56 additions and 0 deletions
+48
View File
@@ -12,6 +12,9 @@
#include <cstdlib> // for malloc
#include <cstring> // for strcmp
#include <sstream>
#include <fstream>
#include <iostream>
#include <utility>
namespace amd {
@@ -413,6 +416,46 @@ Program::link(
return retval;
}
void Program::StubProgramSource(const std::string& app_name)
{
static uint program_counter = 0;
std::fstream stub_read;
std::stringstream file_name;
std::string app_name_no_ext;
std::size_t length = app_name.rfind(".exe");
if (length == std::string::npos) {
length = app_name.size();
}
app_name_no_ext.assign(app_name.c_str(), length);
// Construct a unique file name for the CL program
file_name << app_name_no_ext << "_program_" << program_counter << ".cl";
stub_read.open(file_name.str().c_str(), (std::fstream::in | std::fstream::binary));
// Check if we have OpenCL program
if (stub_read.is_open()) {
// Find the stream size
stub_read.seekg(0, std::fstream::end);
size_t size = stub_read.tellg();
stub_read.seekg(0, std::ios::beg);
char* data = new char[size];
stub_read.read(data, size);
stub_read.close();
sourceCode_.assign(data, size);
delete[] data;
}
else {
std::fstream stub_write;
stub_write.open(file_name.str().c_str(), (std::fstream::out | std::fstream::binary));
stub_write << sourceCode_;
stub_write.close();
}
program_counter++;
}
cl_int
Program::build(
const std::vector<Device*>& devices,
@@ -431,6 +474,11 @@ Program::build(
}
}
if (OCL_STUB_PROGRAMS && !sourceCode_.empty()) {
// The app name should be the samme for all device
StubProgramSource(devices[0]->appProfile()->appFileName());
}
// Clear the program object
clear();