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


[ROCm/clr commit: 1c46212c4b]
This commit is contained in:
foreman
2017-03-31 15:51:21 -04:00
förälder d3ac3503e1
incheckning 91ead8b192
4 ändrade filer med 56 tillägg och 0 borttagningar
@@ -17,6 +17,9 @@ public:
bool init();
const std::string& GetBuildOptsAppend() const { return buildOptsAppend_; }
const std::string& appFileName() const { return appFileName_; }
protected:
enum DataTypes
{
@@ -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();
@@ -77,6 +77,9 @@ public:
typedef std::map<std::string, Symbol> symbols_t;
private:
//! Replaces the compiled program with the new version from HD
void StubProgramSource(const std::string& app_name);
//! The context this program is part of.
SharedReference<Context> context_;
@@ -181,6 +181,8 @@ release(uint, GPU_WAVES_PER_SIMD, 0, \
"Force the number of waves per SIMD (1-10)") \
release(bool, GPU_WAVE_LIMIT_ENABLE, false, \
"1 = Enable adaptive wave limiter") \
release(bool, OCL_STUB_PROGRAMS, false, \
"1 = Enables OCL programs stubing") \
release_on_stg(uint, GPU_WAVE_LIMIT_CU_PER_SH, 0, \
"Assume the number of CU per SH for wave limiter") \
release_on_stg(uint, GPU_WAVE_LIMIT_MAX_WAVE, 10, \