summaryrefslogtreecommitdiff
path: root/cpu_ref/rsCpuScriptGroup2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpu_ref/rsCpuScriptGroup2.cpp')
-rw-r--r--cpu_ref/rsCpuScriptGroup2.cpp97
1 files changed, 34 insertions, 63 deletions
diff --git a/cpu_ref/rsCpuScriptGroup2.cpp b/cpu_ref/rsCpuScriptGroup2.cpp
index df1172b7..1cc382f4 100644
--- a/cpu_ref/rsCpuScriptGroup2.cpp
+++ b/cpu_ref/rsCpuScriptGroup2.cpp
@@ -11,8 +11,6 @@
#include <vector>
#ifndef RS_COMPATIBILITY_LIB
-#include <zlib.h>
-
#include "bcc/Config/Config.h"
#endif
@@ -227,41 +225,11 @@ string getCoreLibPath(Context* context, string* coreLibRelaxedPath) {
#endif
}
-bool getChecksum(const std::vector<string>& inputBitcodeFilenames,
- const string& coreLibPath, const string& coreLibRelaxedPath,
- const char* commandLine,
- char* checksumStr) {
- uint32_t checksum = adler32(0L, Z_NULL, 0);
-
- for (const auto& bcFilename : inputBitcodeFilenames) {
- if (!android::renderscript::addFileToChecksum(bcFilename.c_str(), checksum)) {
- return false;
- }
- }
-
- if (!android::renderscript::addFileToChecksum(coreLibPath.c_str(), checksum)) {
- return false;
- }
-
- if (!coreLibRelaxedPath.empty() &&
- !android::renderscript::addFileToChecksum(coreLibRelaxedPath.c_str(), checksum)) {
- return false;
- }
-
- // include checksum of command line arguments
- checksum = adler32(checksum, (const unsigned char *) commandLine,
- strlen(commandLine));
-
- sprintf(checksumStr, "%08x", checksum);
-
- return true;
-}
-
void setupCompileArguments(
- const vector<string>& inputs, const vector<string>& kernelBatches,
+ const vector<const char*>& inputs, const vector<string>& kernelBatches,
const vector<string>& invokeBatches,
- const string& output_dir, const string& output_filename,
- const string& coreLibPath, const string& coreLibRelaxedPath,
+ const char* outputDir, const char* outputFileName,
+ const char* coreLibPath, const char* coreLibRelaxedPath,
vector<const char*>* args) {
args->push_back(RsdCpuScriptImpl::BCC_EXE_PATH);
args->push_back("-fPIC");
@@ -269,11 +237,11 @@ void setupCompileArguments(
args->push_back("-mtriple");
args->push_back(DEFAULT_TARGET_TRIPLE_STRING);
args->push_back("-bclib");
- args->push_back(coreLibPath.c_str());
+ args->push_back(coreLibPath);
args->push_back("-bclib_relaxed");
- args->push_back(coreLibRelaxedPath.c_str());
- for (const string& input : inputs) {
- args->push_back(input.c_str());
+ args->push_back(coreLibRelaxedPath);
+ for (const char* input : inputs) {
+ args->push_back(input);
}
for (const string& batch : kernelBatches) {
args->push_back("-merge");
@@ -284,13 +252,13 @@ void setupCompileArguments(
args->push_back(batch.c_str());
}
args->push_back("-output_path");
- args->push_back(output_dir.c_str());
+ args->push_back(outputDir);
args->push_back("-o");
- args->push_back(output_filename.c_str());
+ args->push_back(outputFileName);
}
void generateSourceSlot(const Closure& closure,
- const std::vector<std::string>& inputs,
+ const std::vector<const char*>& inputs,
std::stringstream& ss) {
const IDBase* funcID = (const IDBase*)closure.mFunctionID.get();
const Script* script = funcID->mScript;
@@ -317,7 +285,11 @@ void CpuScriptGroup2Impl::compile(const char* cacheDir) {
return;
}
- std::set<string> inputSet;
+ auto comparator = [](const char* str1, const char* str2) -> bool {
+ return strcmp(str1, str2) < 0;
+ };
+ std::set<const char*, decltype(comparator)> inputSet(comparator);
+
for (Closure* closure : mGroup->mClosures) {
const Script* script = closure->mFunctionID.get()->mScript;
@@ -328,11 +300,11 @@ void CpuScriptGroup2Impl::compile(const char* cacheDir) {
const RsdCpuScriptImpl *cpuScript =
(const RsdCpuScriptImpl*)script->mHal.drv;
- const string& bitcodeFilename = cpuScript->getBitcodeFilePath();
+ const char* bitcodeFilename = cpuScript->getBitcodeFilePath();
inputSet.insert(bitcodeFilename);
}
- std::vector<string> inputs(inputSet.begin(), inputSet.end());
+ std::vector<const char*> inputs(inputSet.begin(), inputSet.end());
std::vector<string> kernelBatches;
std::vector<string> invokeBatches;
@@ -362,26 +334,32 @@ void CpuScriptGroup2Impl::compile(const char* cacheDir) {
objFilePath.append(mGroup->mName);
objFilePath.append(".o");
- string outputFileName(mGroup->mName);
+ const char* resName = mGroup->mName;
string coreLibRelaxedPath;
const string& coreLibPath = getCoreLibPath(getCpuRefImpl()->getContext(),
&coreLibRelaxedPath);
vector<const char*> arguments;
- string output_dir(cacheDir);
- setupCompileArguments(inputs, kernelBatches, invokeBatches, output_dir,
- outputFileName, coreLibPath, coreLibRelaxedPath,
+ setupCompileArguments(inputs, kernelBatches, invokeBatches, cacheDir,
+ resName, coreLibPath.c_str(), coreLibRelaxedPath.c_str(),
&arguments);
std::unique_ptr<const char> cmdLine(rsuJoinStrings(arguments.size() - 1,
- arguments.data()));
+ arguments.data()));
- if (!getChecksum(inputs, coreLibPath, coreLibRelaxedPath, cmdLine.get(),
- mChecksum)) {
+ inputs.push_back(coreLibPath.c_str());
+ inputs.push_back(coreLibRelaxedPath.c_str());
+
+ uint32_t checksum = constructBuildChecksum(nullptr, 0, cmdLine.get(),
+ inputs.data(), inputs.size());
+
+ if (checksum == 0) {
return;
}
- const char* resName = outputFileName.c_str();
+ std::stringstream ss;
+ ss << std::hex << checksum;
+ const char* checksumStr = ss.str().c_str();
//===--------------------------------------------------------------------===//
// Try to load a shared lib from code cache matching filename and checksum
@@ -390,16 +368,9 @@ void CpuScriptGroup2Impl::compile(const char* cacheDir) {
mScriptObj = SharedLibraryUtils::loadSharedLibrary(cacheDir, resName);
if (mScriptObj != nullptr) {
mExecutable = ScriptExecutable::createFromSharedObject(
- getCpuRefImpl()->getContext(), mScriptObj);
+ getCpuRefImpl()->getContext(), mScriptObj, checksum);
if (mExecutable != nullptr) {
- if (mExecutable->isChecksumValid(mChecksum)) {
- return;
- } else {
- ALOGE("Invalid checksum from cached so: %s (expected: %s)",
- mExecutable->getBuildChecksum(), mChecksum);
- }
- delete mExecutable;
- mExecutable = nullptr;
+ return;
} else {
ALOGE("Failed to create an executable object from so file");
}
@@ -412,7 +383,7 @@ void CpuScriptGroup2Impl::compile(const char* cacheDir) {
//===--------------------------------------------------------------------===//
arguments.push_back("-build-checksum");
- arguments.push_back(mChecksum);
+ arguments.push_back(checksumStr);
arguments.push_back(nullptr);
bool compiled = rsuExecuteCommand(RsdCpuScriptImpl::BCC_EXE_PATH,