| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011-2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| Jean-Luc Brouillet | 9ab5094 | 2014-06-18 18:10:32 -0700 | [diff] [blame] | 7 | * |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 17 | #include "rsCpuCore.h" |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 18 | #include "rsCpuScript.h" |
| Yang Ni | 2abfcc6 | 2015-02-17 16:05:19 -0800 | [diff] [blame] | 19 | #include "rsCpuExecutable.h" |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 20 | |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 21 | #ifdef RS_COMPATIBILITY_LIB |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 22 | #include <stdio.h> |
| Stephen Hines | ee48c0b | 2013-10-30 17:48:30 -0700 | [diff] [blame] | 23 | #include <sys/stat.h> |
| Stephen Hines | c2c11cc | 2013-07-19 01:07:42 -0700 | [diff] [blame] | 24 | #include <unistd.h> |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 25 | #else |
| Pirama Arumuga Nainar | 2fa8a23 | 2015-03-25 17:21:40 -0700 | [diff] [blame] | 26 | #include "rsCppUtils.h" |
| 27 | |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 28 | #include <bcc/BCCContext.h> |
| Stephen Hines | 82e0a67 | 2014-05-05 15:40:56 -0700 | [diff] [blame] | 29 | #include <bcc/Config/Config.h> |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 30 | #include <bcc/Renderscript/RSCompilerDriver.h> |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 31 | #include <bcinfo/MetadataExtractor.h> |
| Stephen Hines | ba17ae4 | 2013-06-05 17:18:04 -0700 | [diff] [blame] | 32 | #include <cutils/properties.h> |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 33 | |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 34 | #include <zlib.h> |
| 35 | #include <sys/file.h> |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 36 | #include <sys/types.h> |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 37 | #include <unistd.h> |
| Stephen Hines | 0051132 | 2014-01-31 11:20:23 -0800 | [diff] [blame] | 38 | |
| 39 | #include <string> |
| 40 | #include <vector> |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 41 | #endif |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 42 | |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 43 | #include <set> |
| 44 | #include <string> |
| 45 | #include <dlfcn.h> |
| 46 | #include <stdlib.h> |
| 47 | #include <string.h> |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 48 | #include <iostream> |
| Yang Ni | cb17015 | 2015-04-16 10:27:02 -0700 | [diff] [blame] | 49 | #include <sstream> |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 50 | |
| 51 | #ifdef __LP64__ |
| 52 | #define SYSLIBPATH "/system/lib64" |
| 53 | #else |
| 54 | #define SYSLIBPATH "/system/lib" |
| 55 | #endif |
| 56 | |
| Stephen Hines | ba17ae4 | 2013-06-05 17:18:04 -0700 | [diff] [blame] | 57 | namespace { |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 58 | #ifndef RS_COMPATIBILITY_LIB |
| 59 | |
| Stephen Hines | ba17ae4 | 2013-06-05 17:18:04 -0700 | [diff] [blame] | 60 | static bool is_force_recompile() { |
| 61 | #ifdef RS_SERVER |
| 62 | return false; |
| 63 | #else |
| 64 | char buf[PROPERTY_VALUE_MAX]; |
| 65 | |
| 66 | // Re-compile if floating point precision has been overridden. |
| 67 | property_get("debug.rs.precision", buf, ""); |
| 68 | if (buf[0] != '\0') { |
| 69 | return true; |
| 70 | } |
| 71 | |
| 72 | // Re-compile if debug.rs.forcerecompile is set. |
| 73 | property_get("debug.rs.forcerecompile", buf, "0"); |
| 74 | if ((::strcmp(buf, "1") == 0) || (::strcmp(buf, "true") == 0)) { |
| 75 | return true; |
| 76 | } else { |
| 77 | return false; |
| 78 | } |
| 79 | #endif // RS_SERVER |
| 80 | } |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 81 | |
| Chris Wailes | 6847e73 | 2014-08-11 17:30:51 -0700 | [diff] [blame] | 82 | static void setCompileArguments(std::vector<const char*>* args, |
| 83 | const std::string& bcFileName, |
| 84 | const char* cacheDir, const char* resName, |
| 85 | const char* core_lib, bool useRSDebugContext, |
| 86 | const char* bccPluginName) { |
| Jean-Luc Brouillet | 40e35cd | 2014-06-25 18:21:45 -0700 | [diff] [blame] | 87 | rsAssert(cacheDir && resName && core_lib); |
| Yang Ni | da0f069 | 2015-01-12 13:03:40 -0800 | [diff] [blame] | 88 | args->push_back(android::renderscript::RsdCpuScriptImpl::BCC_EXE_PATH); |
| Tim Murray | 687cfe8 | 2015-01-08 14:59:38 -0800 | [diff] [blame] | 89 | args->push_back("-unroll-runtime"); |
| 90 | args->push_back("-scalarize-load-store"); |
| Jean-Luc Brouillet | 40e35cd | 2014-06-25 18:21:45 -0700 | [diff] [blame] | 91 | args->push_back("-o"); |
| 92 | args->push_back(resName); |
| 93 | args->push_back("-output_path"); |
| 94 | args->push_back(cacheDir); |
| 95 | args->push_back("-bclib"); |
| 96 | args->push_back(core_lib); |
| 97 | args->push_back("-mtriple"); |
| 98 | args->push_back(DEFAULT_TARGET_TRIPLE_STRING); |
| 99 | |
| Tim Murray | 358ffb8 | 2014-12-09 11:53:06 -0800 | [diff] [blame] | 100 | // Enable workaround for A53 codegen by default. |
| 101 | #if defined(__aarch64__) && !defined(DISABLE_A53_WORKAROUND) |
| 102 | args->push_back("-aarch64-fix-cortex-a53-835769"); |
| 103 | #endif |
| 104 | |
| Jean-Luc Brouillet | 40e35cd | 2014-06-25 18:21:45 -0700 | [diff] [blame] | 105 | // Execute the bcc compiler. |
| 106 | if (useRSDebugContext) { |
| 107 | args->push_back("-rs-debug-ctx"); |
| 108 | } else { |
| 109 | // Only load additional libraries for compiles that don't use |
| 110 | // the debug context. |
| 111 | if (bccPluginName && strlen(bccPluginName) > 0) { |
| 112 | args->push_back("-load"); |
| 113 | args->push_back(bccPluginName); |
| 114 | } |
| 115 | } |
| 116 | |
| Stephen Hines | 45e753a | 2015-01-19 20:58:44 -0800 | [diff] [blame] | 117 | args->push_back("-fPIC"); |
| 118 | args->push_back("-embedRSInfo"); |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 119 | |
| Chris Wailes | 6847e73 | 2014-08-11 17:30:51 -0700 | [diff] [blame] | 120 | args->push_back(bcFileName.c_str()); |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 121 | args->push_back(nullptr); |
| Jean-Luc Brouillet | 40e35cd | 2014-06-25 18:21:45 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| Chris Wailes | 6847e73 | 2014-08-11 17:30:51 -0700 | [diff] [blame] | 124 | static bool compileBitcode(const std::string &bcFileName, |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 125 | const char *bitcode, |
| 126 | size_t bitcodeSize, |
| Pirama Arumuga Nainar | 2fa8a23 | 2015-03-25 17:21:40 -0700 | [diff] [blame] | 127 | std::vector<const char *> &compileArguments) { |
| Jean-Luc Brouillet | 40e35cd | 2014-06-25 18:21:45 -0700 | [diff] [blame] | 128 | rsAssert(bitcode && bitcodeSize); |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 129 | |
| Chris Wailes | 6847e73 | 2014-08-11 17:30:51 -0700 | [diff] [blame] | 130 | FILE *bcfile = fopen(bcFileName.c_str(), "w"); |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 131 | if (!bcfile) { |
| Chris Wailes | 6847e73 | 2014-08-11 17:30:51 -0700 | [diff] [blame] | 132 | ALOGE("Could not write to %s", bcFileName.c_str()); |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 133 | return false; |
| 134 | } |
| 135 | size_t nwritten = fwrite(bitcode, 1, bitcodeSize, bcfile); |
| 136 | fclose(bcfile); |
| 137 | if (nwritten != bitcodeSize) { |
| 138 | ALOGE("Could not write %zu bytes to %s", bitcodeSize, |
| Chris Wailes | 6847e73 | 2014-08-11 17:30:51 -0700 | [diff] [blame] | 139 | bcFileName.c_str()); |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 140 | return false; |
| 141 | } |
| 142 | |
| Pirama Arumuga Nainar | 2fa8a23 | 2015-03-25 17:21:40 -0700 | [diff] [blame] | 143 | return android::renderscript::rsuExecuteCommand( |
| 144 | android::renderscript::RsdCpuScriptImpl::BCC_EXE_PATH, |
| 145 | compileArguments.size()-1, compileArguments.data()); |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 146 | } |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 147 | |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 148 | bool isChecksumNeeded() { |
| 149 | char buf[PROPERTY_VALUE_MAX]; |
| 150 | property_get("ro.debuggable", buf, ""); |
| 151 | return (buf[0] == '1'); |
| 152 | } |
| 153 | |
| 154 | bool addFileToChecksum(const char *fileName, uint32_t &checksum) { |
| 155 | int FD = open(fileName, O_RDONLY); |
| 156 | if (FD == -1) { |
| 157 | ALOGE("Cannot open file \'%s\' to compute checksum", fileName); |
| 158 | return false; |
| 159 | } |
| 160 | |
| 161 | char buf[256]; |
| 162 | while (true) { |
| 163 | ssize_t nread = read(FD, buf, sizeof(buf)); |
| 164 | if (nread < 0) { // bail out on failed read |
| 165 | ALOGE("Error while computing checksum for file \'%s\'", fileName); |
| 166 | return false; |
| 167 | } |
| 168 | |
| 169 | checksum = adler32(checksum, (const unsigned char *) buf, nread); |
| 170 | if (static_cast<size_t>(nread) < sizeof(buf)) // EOF |
| 171 | break; |
| 172 | } |
| 173 | |
| Pirama Arumuga Nainar | 2fa8a23 | 2015-03-25 17:21:40 -0700 | [diff] [blame] | 174 | if (TEMP_FAILURE_RETRY(close(FD)) != 0) { |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 175 | ALOGE("Cannot close file \'%s\' after computing checksum", fileName); |
| 176 | return false; |
| 177 | } |
| 178 | return true; |
| 179 | } |
| Yang Ni | cb17015 | 2015-04-16 10:27:02 -0700 | [diff] [blame] | 180 | |
| 181 | #endif // !defined(RS_COMPATIBILITY_LIB) |
| 182 | } // namespace |
| 183 | |
| 184 | namespace android { |
| 185 | namespace renderscript { |
| 186 | |
| 187 | #ifndef RS_COMPATIBILITY_LIB |
| 188 | |
| 189 | uint32_t constructBuildChecksum(uint8_t const *bitcode, size_t bitcodeSize, |
| 190 | const char *commandLine, |
| 191 | const char** bccFiles, size_t numFiles) { |
| 192 | uint32_t checksum = adler32(0L, Z_NULL, 0); |
| 193 | |
| 194 | // include checksum of bitcode |
| 195 | if (bitcode != nullptr && bitcodeSize > 0) { |
| 196 | checksum = adler32(checksum, bitcode, bitcodeSize); |
| 197 | } |
| 198 | |
| 199 | // include checksum of command line arguments |
| 200 | checksum = adler32(checksum, (const unsigned char *) commandLine, |
| 201 | strlen(commandLine)); |
| 202 | |
| 203 | // include checksum of bccFiles |
| 204 | for (size_t i = 0; i < numFiles; i++) { |
| 205 | const char* bccFile = bccFiles[i]; |
| 206 | if (bccFile[0] != 0 && !addFileToChecksum(bccFile, checksum)) { |
| 207 | // return empty checksum instead of something partial/corrupt |
| 208 | return 0; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | return checksum; |
| 213 | } |
| 214 | |
| Yang Ni | f02a2b0 | 2015-04-07 16:00:31 -0700 | [diff] [blame] | 215 | #endif // !RS_COMPATIBILITY_LIB |
| Yang Ni | 1c44cb6 | 2015-01-22 12:02:27 -0800 | [diff] [blame] | 216 | |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 217 | RsdCpuScriptImpl::RsdCpuScriptImpl(RsdCpuReferenceImpl *ctx, const Script *s) { |
| 218 | mCtx = ctx; |
| 219 | mScript = s; |
| 220 | |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 221 | mScriptSO = nullptr; |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 222 | |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 223 | #ifndef RS_COMPATIBILITY_LIB |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 224 | mCompilerDriver = nullptr; |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 225 | #endif |
| 226 | |
| Tim Murray | e195a3f | 2014-03-13 15:04:58 -0700 | [diff] [blame] | 227 | |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 228 | mRoot = nullptr; |
| 229 | mRootExpand = nullptr; |
| 230 | mInit = nullptr; |
| 231 | mFreeChildren = nullptr; |
| Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 232 | mScriptExec = nullptr; |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 233 | |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 234 | mBoundAllocs = nullptr; |
| 235 | mIntrinsicData = nullptr; |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 236 | mIsThreadable = true; |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 237 | |
| Yang Ni | cb17015 | 2015-04-16 10:27:02 -0700 | [diff] [blame] | 238 | mBuildChecksum = 0; |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 239 | mChecksumNeeded = false; |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 240 | } |
| 241 | |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 242 | bool RsdCpuScriptImpl::storeRSInfoFromSO() { |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 243 | // The shared object may have an invalid build checksum. |
| 244 | // Validate and fail early. |
| 245 | mScriptExec = ScriptExecutable::createFromSharedObject( |
| Yang Ni | cb17015 | 2015-04-16 10:27:02 -0700 | [diff] [blame] | 246 | mCtx->getContext(), mScriptSO, |
| 247 | mChecksumNeeded ? mBuildChecksum : 0); |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 248 | |
| 249 | if (mScriptExec == nullptr) { |
| 250 | return false; |
| 251 | } |
| 252 | |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 253 | mRoot = (RootFunc_t) dlsym(mScriptSO, "root"); |
| 254 | if (mRoot) { |
| 255 | //ALOGE("Found root(): %p", mRoot); |
| 256 | } |
| 257 | mRootExpand = (RootFunc_t) dlsym(mScriptSO, "root.expand"); |
| 258 | if (mRootExpand) { |
| 259 | //ALOGE("Found root.expand(): %p", mRootExpand); |
| 260 | } |
| 261 | mInit = (InvokeFunc_t) dlsym(mScriptSO, "init"); |
| 262 | if (mInit) { |
| 263 | //ALOGE("Found init(): %p", mInit); |
| 264 | } |
| 265 | mFreeChildren = (InvokeFunc_t) dlsym(mScriptSO, ".rs.dtor"); |
| 266 | if (mFreeChildren) { |
| 267 | //ALOGE("Found .rs.dtor(): %p", mFreeChildren); |
| 268 | } |
| 269 | |
| Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 270 | size_t varCount = mScriptExec->getExportedVariableCount(); |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 271 | if (varCount > 0) { |
| 272 | mBoundAllocs = new Allocation *[varCount]; |
| 273 | memset(mBoundAllocs, 0, varCount * sizeof(*mBoundAllocs)); |
| 274 | } |
| 275 | |
| Pirama Arumuga Nainar | 68173de | 2015-01-28 12:12:36 -0800 | [diff] [blame] | 276 | mIsThreadable = mScriptExec->getThreadable(); |
| 277 | //ALOGE("Script isThreadable? %d", mIsThreadable); |
| 278 | |
| Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 279 | return true; |
| 280 | } |
| 281 | |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 282 | bool RsdCpuScriptImpl::init(char const *resName, char const *cacheDir, |
| 283 | uint8_t const *bitcode, size_t bitcodeSize, |
| Stephen Hines | 0051132 | 2014-01-31 11:20:23 -0800 | [diff] [blame] | 284 | uint32_t flags, char const *bccPluginName) { |
| Yang Ni | e8f9fba | 2015-01-30 08:55:10 -0800 | [diff] [blame] | 285 | //ALOGE("rsdScriptCreate %p %p %p %p %i %i %p", rsc, resName, cacheDir, |
| 286 | // bitcode, bitcodeSize, flags, lookupFunc); |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 287 | //ALOGE("rsdScriptInit %p %p", rsc, script); |
| 288 | |
| 289 | mCtx->lockMutex(); |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 290 | #ifndef RS_COMPATIBILITY_LIB |
| Stephen Hines | 0051132 | 2014-01-31 11:20:23 -0800 | [diff] [blame] | 291 | bool useRSDebugContext = false; |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 292 | |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 293 | mCompilerDriver = nullptr; |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 294 | |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 295 | mCompilerDriver = new bcc::RSCompilerDriver(); |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 296 | if (mCompilerDriver == nullptr) { |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 297 | ALOGE("bcc: FAILS to create compiler driver (out of memory)"); |
| 298 | mCtx->unlockMutex(); |
| 299 | return false; |
| 300 | } |
| 301 | |
| Stephen Hines | b7d9c80 | 2013-04-29 19:13:09 -0700 | [diff] [blame] | 302 | // Run any compiler setup functions we have been provided with. |
| 303 | RSSetupCompilerCallback setupCompilerCallback = |
| 304 | mCtx->getSetupCompilerCallback(); |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 305 | if (setupCompilerCallback != nullptr) { |
| Stephen Hines | b7d9c80 | 2013-04-29 19:13:09 -0700 | [diff] [blame] | 306 | setupCompilerCallback(mCompilerDriver); |
| 307 | } |
| 308 | |
| Jean-Luc Brouillet | 40e35cd | 2014-06-25 18:21:45 -0700 | [diff] [blame] | 309 | bcinfo::MetadataExtractor bitcodeMetadata((const char *) bitcode, bitcodeSize); |
| 310 | if (!bitcodeMetadata.extract()) { |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 311 | ALOGE("Could not extract metadata from bitcode"); |
| Stephen Hines | f94e8db | 2014-06-26 11:55:29 -0700 | [diff] [blame] | 312 | mCtx->unlockMutex(); |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 313 | return false; |
| 314 | } |
| 315 | |
| Jean-Luc Brouillet | 40e35cd | 2014-06-25 18:21:45 -0700 | [diff] [blame] | 316 | const char* core_lib = findCoreLib(bitcodeMetadata, (const char*)bitcode, bitcodeSize); |
| Stephen Hines | cca3d6c | 2013-04-15 01:06:39 -0700 | [diff] [blame] | 317 | |
| 318 | if (mCtx->getContext()->getContextType() == RS_CONTEXT_TYPE_DEBUG) { |
| Stephen Hines | f47e8b4 | 2013-04-18 01:06:29 -0700 | [diff] [blame] | 319 | mCompilerDriver->setDebugContext(true); |
| Stephen Hines | 0051132 | 2014-01-31 11:20:23 -0800 | [diff] [blame] | 320 | useRSDebugContext = true; |
| Stephen Hines | cca3d6c | 2013-04-15 01:06:39 -0700 | [diff] [blame] | 321 | } |
| Stephen Hines | ba17ae4 | 2013-06-05 17:18:04 -0700 | [diff] [blame] | 322 | |
| Chris Wailes | 6847e73 | 2014-08-11 17:30:51 -0700 | [diff] [blame] | 323 | std::string bcFileName(cacheDir); |
| Jean-Luc Brouillet | 40e35cd | 2014-06-25 18:21:45 -0700 | [diff] [blame] | 324 | bcFileName.append("/"); |
| 325 | bcFileName.append(resName); |
| 326 | bcFileName.append(".bc"); |
| 327 | |
| 328 | std::vector<const char*> compileArguments; |
| 329 | setCompileArguments(&compileArguments, bcFileName, cacheDir, resName, core_lib, |
| 330 | useRSDebugContext, bccPluginName); |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 331 | |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 332 | mChecksumNeeded = isChecksumNeeded(); |
| 333 | if (mChecksumNeeded) { |
| 334 | std::vector<const char *> bccFiles = { BCC_EXE_PATH, |
| 335 | core_lib, |
| 336 | }; |
| Pirama Arumuga Nainar | 2fa8a23 | 2015-03-25 17:21:40 -0700 | [diff] [blame] | 337 | |
| 338 | // The last argument of compileArguments is a nullptr, so remove 1 from |
| 339 | // the size. |
| 340 | std::unique_ptr<const char> compileCommandLine( |
| 341 | rsuJoinStrings(compileArguments.size()-1, compileArguments.data())); |
| 342 | |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 343 | mBuildChecksum = constructBuildChecksum(bitcode, bitcodeSize, |
| 344 | compileCommandLine.get(), |
| Yang Ni | cb17015 | 2015-04-16 10:27:02 -0700 | [diff] [blame] | 345 | bccFiles.data(), bccFiles.size()); |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 346 | |
| Yang Ni | cb17015 | 2015-04-16 10:27:02 -0700 | [diff] [blame] | 347 | if (mBuildChecksum == 0) { |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 348 | // cannot compute checksum but verification is enabled |
| 349 | mCtx->unlockMutex(); |
| 350 | return false; |
| 351 | } |
| 352 | } |
| 353 | else { |
| 354 | // add a dummy/constant as a checksum if verification is disabled |
| Yang Ni | cb17015 | 2015-04-16 10:27:02 -0700 | [diff] [blame] | 355 | mBuildChecksum = 0xabadcafe; |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | // Append build checksum to commandline |
| 359 | // Handle the terminal nullptr in compileArguments |
| 360 | compileArguments.pop_back(); |
| 361 | compileArguments.push_back("-build-checksum"); |
| Yang Ni | cb17015 | 2015-04-16 10:27:02 -0700 | [diff] [blame] | 362 | std::stringstream ss; |
| 363 | ss << std::hex << mBuildChecksum; |
| 364 | compileArguments.push_back(ss.str().c_str()); |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 365 | compileArguments.push_back(nullptr); |
| 366 | |
| Tim Murray | bf96a52 | 2015-01-23 15:37:03 -0800 | [diff] [blame] | 367 | if (!is_force_recompile() && !useRSDebugContext) { |
| Yang Ni | 1c44cb6 | 2015-01-22 12:02:27 -0800 | [diff] [blame] | 368 | mScriptSO = SharedLibraryUtils::loadSharedLibrary(cacheDir, resName); |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 369 | |
| 370 | // Read RS info from the shared object to detect checksum mismatch |
| 371 | if (mScriptSO != nullptr && !storeRSInfoFromSO()) { |
| 372 | dlclose(mScriptSO); |
| 373 | mScriptSO = nullptr; |
| 374 | } |
| Jean-Luc Brouillet | 40e35cd | 2014-06-25 18:21:45 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | // If we can't, it's either not there or out of date. We compile the bit code and try loading |
| 378 | // again. |
| Stephen Hines | 45e753a | 2015-01-19 20:58:44 -0800 | [diff] [blame] | 379 | if (mScriptSO == nullptr) { |
| 380 | if (!compileBitcode(bcFileName, (const char*)bitcode, bitcodeSize, |
| Pirama Arumuga Nainar | 2fa8a23 | 2015-03-25 17:21:40 -0700 | [diff] [blame] | 381 | compileArguments)) |
| Stephen Hines | 45e753a | 2015-01-19 20:58:44 -0800 | [diff] [blame] | 382 | { |
| Jean-Luc Brouillet | 40e35cd | 2014-06-25 18:21:45 -0700 | [diff] [blame] | 383 | ALOGE("bcc: FAILS to compile '%s'", resName); |
| 384 | mCtx->unlockMutex(); |
| 385 | return false; |
| 386 | } |
| Stephen Hines | 45e753a | 2015-01-19 20:58:44 -0800 | [diff] [blame] | 387 | |
| Yang Ni | 1c44cb6 | 2015-01-22 12:02:27 -0800 | [diff] [blame] | 388 | if (!SharedLibraryUtils::createSharedLibrary(cacheDir, resName)) { |
| Stephen Hines | 45e753a | 2015-01-19 20:58:44 -0800 | [diff] [blame] | 389 | ALOGE("Linker: Failed to link object file '%s'", resName); |
| 390 | mCtx->unlockMutex(); |
| 391 | return false; |
| 392 | } |
| 393 | |
| Yang Ni | 1c44cb6 | 2015-01-22 12:02:27 -0800 | [diff] [blame] | 394 | mScriptSO = SharedLibraryUtils::loadSharedLibrary(cacheDir, resName); |
| Stephen Hines | 45e753a | 2015-01-19 20:58:44 -0800 | [diff] [blame] | 395 | if (mScriptSO == nullptr) { |
| 396 | ALOGE("Unable to load '%s'", resName); |
| Jean-Luc Brouillet | 40e35cd | 2014-06-25 18:21:45 -0700 | [diff] [blame] | 397 | mCtx->unlockMutex(); |
| 398 | return false; |
| Stephen Hines | ba17ae4 | 2013-06-05 17:18:04 -0700 | [diff] [blame] | 399 | } |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 400 | |
| 401 | // Read RS symbol information from the .so. |
| 402 | if (!storeRSInfoFromSO()) { |
| 403 | goto error; |
| 404 | } |
| Stephen Hines | ba17ae4 | 2013-06-05 17:18:04 -0700 | [diff] [blame] | 405 | } |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 406 | |
| Yang Ni | c31585b | 2015-02-15 11:43:50 -0800 | [diff] [blame] | 407 | mBitcodeFilePath.setTo(bcFileName.c_str()); |
| Yang Ni | da0f069 | 2015-01-12 13:03:40 -0800 | [diff] [blame] | 408 | |
| Jean-Luc Brouillet | f4d216e | 2014-06-09 18:04:16 -0700 | [diff] [blame] | 409 | #else // RS_COMPATIBILITY_LIB is defined |
| Miao Wang | f3213d7 | 2015-01-14 10:03:07 -0800 | [diff] [blame] | 410 | const char *nativeLibDir = mCtx->getContext()->getNativeLibDir(); |
| 411 | mScriptSO = SharedLibraryUtils::loadSharedLibrary(cacheDir, resName, nativeLibDir); |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 412 | |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 413 | if (!mScriptSO) { |
| 414 | goto error; |
| 415 | } |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 416 | |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 417 | if (!storeRSInfoFromSO()) { |
| Stephen Hines | c2c11cc | 2013-07-19 01:07:42 -0700 | [diff] [blame] | 418 | goto error; |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 419 | } |
| 420 | #endif |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 421 | mCtx->unlockMutex(); |
| 422 | return true; |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 423 | |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 424 | error: |
| 425 | |
| 426 | mCtx->unlockMutex(); |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 427 | if (mScriptSO) { |
| 428 | dlclose(mScriptSO); |
| Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 429 | mScriptSO = nullptr; |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 430 | } |
| 431 | return false; |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 432 | } |
| 433 | |
| Jean-Luc Brouillet | 9ab5094 | 2014-06-18 18:10:32 -0700 | [diff] [blame] | 434 | #ifndef RS_COMPATIBILITY_LIB |
| 435 | |
| Jean-Luc Brouillet | 9ab5094 | 2014-06-18 18:10:32 -0700 | [diff] [blame] | 436 | const char* RsdCpuScriptImpl::findCoreLib(const bcinfo::MetadataExtractor& ME, const char* bitcode, |
| 437 | size_t bitcodeSize) { |
| 438 | const char* defaultLib = SYSLIBPATH"/libclcore.bc"; |
| 439 | |
| 440 | // If we're debugging, use the debug library. |
| 441 | if (mCtx->getContext()->getContextType() == RS_CONTEXT_TYPE_DEBUG) { |
| 442 | return SYSLIBPATH"/libclcore_debug.bc"; |
| 443 | } |
| 444 | |
| 445 | // If a callback has been registered to specify a library, use that. |
| 446 | RSSelectRTCallback selectRTCallback = mCtx->getSelectRTCallback(); |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 447 | if (selectRTCallback != nullptr) { |
| Jean-Luc Brouillet | 9ab5094 | 2014-06-18 18:10:32 -0700 | [diff] [blame] | 448 | return selectRTCallback((const char*)bitcode, bitcodeSize); |
| 449 | } |
| 450 | |
| 451 | // Check for a platform specific library |
| 452 | #if defined(ARCH_ARM_HAVE_NEON) && !defined(DISABLE_CLCORE_NEON) |
| 453 | enum bcinfo::RSFloatPrecision prec = ME.getRSFloatPrecision(); |
| Jean-Luc Brouillet | f4d3836 | 2014-07-09 17:46:03 -0700 | [diff] [blame] | 454 | if (prec == bcinfo::RS_FP_Relaxed) { |
| Jean-Luc Brouillet | 9ab5094 | 2014-06-18 18:10:32 -0700 | [diff] [blame] | 455 | // NEON-capable ARMv7a devices can use an accelerated math library |
| 456 | // for all reduced precision scripts. |
| 457 | // ARMv8 does not use NEON, as ASIMD can be used with all precision |
| 458 | // levels. |
| 459 | return SYSLIBPATH"/libclcore_neon.bc"; |
| 460 | } else { |
| 461 | return defaultLib; |
| 462 | } |
| 463 | #elif defined(__i386__) || defined(__x86_64__) |
| 464 | // x86 devices will use an optimized library. |
| 465 | return SYSLIBPATH"/libclcore_x86.bc"; |
| 466 | #else |
| 467 | return defaultLib; |
| 468 | #endif |
| 469 | } |
| 470 | |
| 471 | #endif |
| 472 | |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 473 | void RsdCpuScriptImpl::populateScript(Script *script) { |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 474 | // Copy info over to runtime |
| Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 475 | script->mHal.info.exportedFunctionCount = mScriptExec->getExportedFunctionCount(); |
| 476 | script->mHal.info.exportedVariableCount = mScriptExec->getExportedVariableCount(); |
| Pirama Arumuga Nainar | 577194a | 2015-01-23 14:27:33 -0800 | [diff] [blame] | 477 | script->mHal.info.exportedPragmaCount = mScriptExec->getPragmaCount();; |
| Yang Ni | e8f9fba | 2015-01-30 08:55:10 -0800 | [diff] [blame] | 478 | script->mHal.info.exportedPragmaKeyList = mScriptExec->getPragmaKeys(); |
| 479 | script->mHal.info.exportedPragmaValueList = mScriptExec->getPragmaValues(); |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 480 | |
| 481 | // Bug, need to stash in metadata |
| 482 | if (mRootExpand) { |
| 483 | script->mHal.info.root = mRootExpand; |
| 484 | } else { |
| 485 | script->mHal.info.root = mRoot; |
| 486 | } |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 487 | } |
| 488 | |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 489 | |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 490 | bool RsdCpuScriptImpl::forEachMtlsSetup(const Allocation ** ains, |
| Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 491 | uint32_t inLen, |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 492 | Allocation * aout, |
| 493 | const void * usr, uint32_t usrLen, |
| 494 | const RsScriptCall *sc, |
| 495 | MTLaunchStruct *mtls) { |
| 496 | |
| 497 | memset(mtls, 0, sizeof(MTLaunchStruct)); |
| 498 | |
| Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 499 | for (int index = inLen; --index >= 0;) { |
| 500 | const Allocation* ain = ains[index]; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 501 | |
| Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 502 | // possible for this to occur if IO_OUTPUT/IO_INPUT with no bound surface |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 503 | if (ain != nullptr && |
| 504 | (const uint8_t *)ain->mHal.drvState.lod[0].mallocPtr == nullptr) { |
| 505 | |
| Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 506 | mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, |
| 507 | "rsForEach called with null in allocations"); |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 508 | return false; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 509 | } |
| 510 | } |
| 511 | |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 512 | if (aout && |
| 513 | (const uint8_t *)aout->mHal.drvState.lod[0].mallocPtr == nullptr) { |
| 514 | |
| Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 515 | mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, |
| 516 | "rsForEach called with null out allocations"); |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 517 | return false; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 518 | } |
| 519 | |
| Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 520 | if (inLen > 0) { |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 521 | const Allocation *ain0 = ains[0]; |
| 522 | const Type *inType = ain0->getType(); |
| 523 | |
| Jason Sams | c0d6847 | 2015-01-20 14:29:52 -0800 | [diff] [blame] | 524 | mtls->fep.dim.x = inType->getDimX(); |
| 525 | mtls->fep.dim.y = inType->getDimY(); |
| 526 | mtls->fep.dim.z = inType->getDimZ(); |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 527 | |
| 528 | for (int Index = inLen; --Index >= 1;) { |
| 529 | if (!ain0->hasSameDims(ains[Index])) { |
| 530 | mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, |
| Yang Ni | e8f9fba | 2015-01-30 08:55:10 -0800 | [diff] [blame] | 531 | "Failed to launch kernel; dimensions of input and output" |
| 532 | "allocations do not match."); |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 533 | |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 534 | return false; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 535 | } |
| 536 | } |
| 537 | |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 538 | } else if (aout != nullptr) { |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 539 | const Type *outType = aout->getType(); |
| 540 | |
| Jason Sams | c0d6847 | 2015-01-20 14:29:52 -0800 | [diff] [blame] | 541 | mtls->fep.dim.x = outType->getDimX(); |
| 542 | mtls->fep.dim.y = outType->getDimY(); |
| 543 | mtls->fep.dim.z = outType->getDimZ(); |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 544 | |
| Jason Sams | a9139c7 | 2015-04-16 15:11:04 -0700 | [diff] [blame] | 545 | } else if (sc != nullptr) { |
| 546 | mtls->fep.dim.x = sc->xEnd; |
| 547 | mtls->fep.dim.y = sc->yEnd; |
| 548 | mtls->fep.dim.z = 0; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 549 | } else { |
| Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 550 | mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, |
| 551 | "rsForEach called with null allocations"); |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 552 | return false; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 553 | } |
| 554 | |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 555 | if (inLen > 0 && aout != nullptr) { |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 556 | if (!ains[0]->hasSameDims(aout)) { |
| 557 | mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, |
| 558 | "Failed to launch kernel; dimensions of input and output allocations do not match."); |
| 559 | |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 560 | return false; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 561 | } |
| 562 | } |
| 563 | |
| 564 | if (!sc || (sc->xEnd == 0)) { |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 565 | mtls->end.x = mtls->fep.dim.x; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 566 | } else { |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 567 | mtls->start.x = rsMin(mtls->fep.dim.x, sc->xStart); |
| 568 | mtls->end.x = rsMin(mtls->fep.dim.x, sc->xEnd); |
| Pirama Arumuga Nainar | 80afd42 | 2015-04-28 15:41:48 -0700 | [diff] [blame^] | 569 | if (mtls->start.x >= mtls->end.x) { |
| 570 | mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, |
| 571 | "Failed to launch kernel; Invalid xStart or xEnd."); |
| 572 | return false; |
| 573 | } |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | if (!sc || (sc->yEnd == 0)) { |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 577 | mtls->end.y = mtls->fep.dim.y; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 578 | } else { |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 579 | mtls->start.y = rsMin(mtls->fep.dim.y, sc->yStart); |
| 580 | mtls->end.y = rsMin(mtls->fep.dim.y, sc->yEnd); |
| Pirama Arumuga Nainar | 80afd42 | 2015-04-28 15:41:48 -0700 | [diff] [blame^] | 581 | if (mtls->start.y >= mtls->end.y) { |
| 582 | mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, |
| 583 | "Failed to launch kernel; Invalid yStart or yEnd."); |
| 584 | return false; |
| 585 | } |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | if (!sc || (sc->zEnd == 0)) { |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 589 | mtls->end.z = mtls->fep.dim.z; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 590 | } else { |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 591 | mtls->start.z = rsMin(mtls->fep.dim.z, sc->zStart); |
| 592 | mtls->end.z = rsMin(mtls->fep.dim.z, sc->zEnd); |
| Pirama Arumuga Nainar | 80afd42 | 2015-04-28 15:41:48 -0700 | [diff] [blame^] | 593 | if (mtls->start.z >= mtls->end.z) { |
| 594 | mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, |
| 595 | "Failed to launch kernel; Invalid zStart or zEnd."); |
| 596 | return false; |
| 597 | } |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 598 | } |
| 599 | |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 600 | if (!sc || (sc->arrayEnd == 0)) { |
| 601 | mtls->end.array[0] = mtls->fep.dim.array[0]; |
| 602 | } else { |
| 603 | mtls->start.array[0] = rsMin(mtls->fep.dim.array[0], sc->arrayStart); |
| 604 | mtls->end.array[0] = rsMin(mtls->fep.dim.array[0], sc->arrayEnd); |
| Pirama Arumuga Nainar | 80afd42 | 2015-04-28 15:41:48 -0700 | [diff] [blame^] | 605 | if (mtls->start.array[0] >= mtls->end.array[0]) { |
| 606 | mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, |
| 607 | "Failed to launch kernel; Invalid arrayStart or arrayEnd."); |
| 608 | return false; |
| 609 | } |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 610 | } |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 611 | |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 612 | if (!sc || (sc->array2End == 0)) { |
| 613 | mtls->end.array[1] = mtls->fep.dim.array[1]; |
| 614 | } else { |
| 615 | mtls->start.array[1] = rsMin(mtls->fep.dim.array[1], sc->array2Start); |
| 616 | mtls->end.array[1] = rsMin(mtls->fep.dim.array[1], sc->array2End); |
| Pirama Arumuga Nainar | 80afd42 | 2015-04-28 15:41:48 -0700 | [diff] [blame^] | 617 | if (mtls->start.array[1] >= mtls->end.array[1]) { |
| 618 | mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, |
| 619 | "Failed to launch kernel; Invalid array2Start or array2End."); |
| 620 | return false; |
| 621 | } |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | if (!sc || (sc->array3End == 0)) { |
| 625 | mtls->end.array[2] = mtls->fep.dim.array[2]; |
| 626 | } else { |
| 627 | mtls->start.array[2] = rsMin(mtls->fep.dim.array[2], sc->array3Start); |
| 628 | mtls->end.array[2] = rsMin(mtls->fep.dim.array[2], sc->array3End); |
| Pirama Arumuga Nainar | 80afd42 | 2015-04-28 15:41:48 -0700 | [diff] [blame^] | 629 | if (mtls->start.array[2] >= mtls->end.array[2]) { |
| 630 | mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, |
| 631 | "Failed to launch kernel; Invalid array3Start or array3End."); |
| 632 | return false; |
| 633 | } |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | if (!sc || (sc->array4End == 0)) { |
| 637 | mtls->end.array[3] = mtls->fep.dim.array[3]; |
| 638 | } else { |
| 639 | mtls->start.array[3] = rsMin(mtls->fep.dim.array[3], sc->array4Start); |
| 640 | mtls->end.array[3] = rsMin(mtls->fep.dim.array[3], sc->array4End); |
| Pirama Arumuga Nainar | 80afd42 | 2015-04-28 15:41:48 -0700 | [diff] [blame^] | 641 | if (mtls->start.array[3] >= mtls->end.array[3]) { |
| 642 | mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, |
| 643 | "Failed to launch kernel; Invalid array4Start or array4End."); |
| 644 | return false; |
| 645 | } |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | |
| 649 | // The X & Y walkers always want 0-1 min even if dim is not present |
| 650 | mtls->end.x = rsMax((uint32_t)1, mtls->end.x); |
| 651 | mtls->end.y = rsMax((uint32_t)1, mtls->end.y); |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 652 | |
| 653 | mtls->rsc = mCtx; |
| Jason Sams | c0d6847 | 2015-01-20 14:29:52 -0800 | [diff] [blame] | 654 | if (ains) { |
| 655 | memcpy(mtls->ains, ains, inLen * sizeof(ains[0])); |
| 656 | } |
| 657 | mtls->aout[0] = aout; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 658 | mtls->fep.usr = usr; |
| 659 | mtls->fep.usrLen = usrLen; |
| 660 | mtls->mSliceSize = 1; |
| 661 | mtls->mSliceNum = 0; |
| 662 | |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 663 | mtls->isThreadable = mIsThreadable; |
| 664 | |
| Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 665 | if (inLen > 0) { |
| Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 666 | mtls->fep.inLen = inLen; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 667 | for (int index = inLen; --index >= 0;) { |
| Jason Sams | c0d6847 | 2015-01-20 14:29:52 -0800 | [diff] [blame] | 668 | mtls->fep.inPtr[index] = (const uint8_t*)ains[index]->mHal.drvState.lod[0].mallocPtr; |
| 669 | mtls->fep.inStride[index] = ains[index]->getType()->getElementSizeBytes(); |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 670 | } |
| 671 | } |
| 672 | |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 673 | if (aout != nullptr) { |
| Jason Sams | c0d6847 | 2015-01-20 14:29:52 -0800 | [diff] [blame] | 674 | mtls->fep.outPtr[0] = (uint8_t *)aout->mHal.drvState.lod[0].mallocPtr; |
| 675 | mtls->fep.outStride[0] = aout->getType()->getElementSizeBytes(); |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 676 | } |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 677 | |
| 678 | // All validation passed, ok to launch threads |
| 679 | return true; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 680 | } |
| 681 | |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 682 | |
| 683 | void RsdCpuScriptImpl::invokeForEach(uint32_t slot, |
| Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 684 | const Allocation ** ains, |
| 685 | uint32_t inLen, |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 686 | Allocation * aout, |
| 687 | const void * usr, |
| 688 | uint32_t usrLen, |
| 689 | const RsScriptCall *sc) { |
| 690 | |
| 691 | MTLaunchStruct mtls; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 692 | |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 693 | if (forEachMtlsSetup(ains, inLen, aout, usr, usrLen, sc, &mtls)) { |
| 694 | forEachKernelSetup(slot, &mtls); |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 695 | |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 696 | RsdCpuScriptImpl * oldTLS = mCtx->setTLS(this); |
| 697 | mCtx->launchThreads(ains, inLen, aout, sc, &mtls); |
| 698 | mCtx->setTLS(oldTLS); |
| 699 | } |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 700 | } |
| 701 | |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 702 | void RsdCpuScriptImpl::forEachKernelSetup(uint32_t slot, MTLaunchStruct *mtls) { |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 703 | mtls->script = this; |
| 704 | mtls->fep.slot = slot; |
| Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 705 | mtls->kernel = mScriptExec->getForEachFunction(slot); |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 706 | rsAssert(mtls->kernel != nullptr); |
| Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 707 | mtls->sig = mScriptExec->getForEachSignature(slot); |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | int RsdCpuScriptImpl::invokeRoot() { |
| 711 | RsdCpuScriptImpl * oldTLS = mCtx->setTLS(this); |
| 712 | int ret = mRoot(); |
| 713 | mCtx->setTLS(oldTLS); |
| 714 | return ret; |
| 715 | } |
| 716 | |
| 717 | void RsdCpuScriptImpl::invokeInit() { |
| 718 | if (mInit) { |
| 719 | mInit(); |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | void RsdCpuScriptImpl::invokeFreeChildren() { |
| 724 | if (mFreeChildren) { |
| 725 | mFreeChildren(); |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | void RsdCpuScriptImpl::invokeFunction(uint32_t slot, const void *params, |
| 730 | size_t paramLength) { |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 731 | //ALOGE("invoke %i %p %zu", slot, params, paramLength); |
| Yong Chen | eaba5a3 | 2014-12-12 13:25:18 +0800 | [diff] [blame] | 732 | void * ap = nullptr; |
| 733 | |
| 734 | #if defined(__x86_64__) |
| 735 | // The invoked function could have input parameter of vector type for example float4 which |
| 736 | // requires void* params to be 16 bytes aligned when using SSE instructions for x86_64 platform. |
| 737 | // So try to align void* params before passing them into RS exported function. |
| 738 | |
| 739 | if ((uint8_t)(uint64_t)params & 0x0F) { |
| 740 | if ((ap = (void*)memalign(16, paramLength)) != nullptr) { |
| 741 | memcpy(ap, params, paramLength); |
| 742 | } else { |
| Yang Ni | e8f9fba | 2015-01-30 08:55:10 -0800 | [diff] [blame] | 743 | ALOGE("x86_64: invokeFunction memalign error, still use params which" |
| 744 | " is not 16 bytes aligned."); |
| Yong Chen | eaba5a3 | 2014-12-12 13:25:18 +0800 | [diff] [blame] | 745 | } |
| 746 | } |
| 747 | #endif |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 748 | |
| 749 | RsdCpuScriptImpl * oldTLS = mCtx->setTLS(this); |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 750 | reinterpret_cast<void (*)(const void *, uint32_t)>( |
| Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 751 | mScriptExec->getInvokeFunction(slot))(ap? (const void *) ap: params, paramLength); |
| Yong Chen | eaba5a3 | 2014-12-12 13:25:18 +0800 | [diff] [blame] | 752 | |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 753 | mCtx->setTLS(oldTLS); |
| 754 | } |
| 755 | |
| 756 | void RsdCpuScriptImpl::setGlobalVar(uint32_t slot, const void *data, size_t dataLength) { |
| 757 | //rsAssert(!script->mFieldIsObject[slot]); |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 758 | //ALOGE("setGlobalVar %i %p %zu", slot, data, dataLength); |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 759 | |
| 760 | //if (mIntrinsicID) { |
| 761 | //mIntrinsicFuncs.setVar(dc, script, drv->mIntrinsicData, slot, data, dataLength); |
| 762 | //return; |
| 763 | //} |
| 764 | |
| Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 765 | int32_t *destPtr = reinterpret_cast<int32_t *>(mScriptExec->getFieldAddress(slot)); |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 766 | if (!destPtr) { |
| 767 | //ALOGV("Calling setVar on slot = %i which is null", slot); |
| 768 | return; |
| 769 | } |
| 770 | |
| 771 | memcpy(destPtr, data, dataLength); |
| 772 | } |
| 773 | |
| Tim Murray | 9c64239 | 2013-04-11 13:29:59 -0700 | [diff] [blame] | 774 | void RsdCpuScriptImpl::getGlobalVar(uint32_t slot, void *data, size_t dataLength) { |
| 775 | //rsAssert(!script->mFieldIsObject[slot]); |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 776 | //ALOGE("getGlobalVar %i %p %zu", slot, data, dataLength); |
| Tim Murray | 9c64239 | 2013-04-11 13:29:59 -0700 | [diff] [blame] | 777 | |
| Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 778 | int32_t *srcPtr = reinterpret_cast<int32_t *>(mScriptExec->getFieldAddress(slot)); |
| Tim Murray | 9c64239 | 2013-04-11 13:29:59 -0700 | [diff] [blame] | 779 | if (!srcPtr) { |
| 780 | //ALOGV("Calling setVar on slot = %i which is null", slot); |
| 781 | return; |
| 782 | } |
| 783 | memcpy(data, srcPtr, dataLength); |
| 784 | } |
| 785 | |
| 786 | |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 787 | void RsdCpuScriptImpl::setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength, |
| 788 | const Element *elem, |
| Stephen Hines | ac8d146 | 2014-06-25 00:01:23 -0700 | [diff] [blame] | 789 | const uint32_t *dims, size_t dimLength) { |
| Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 790 | int32_t *destPtr = reinterpret_cast<int32_t *>(mScriptExec->getFieldAddress(slot)); |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 791 | if (!destPtr) { |
| 792 | //ALOGV("Calling setVar on slot = %i which is null", slot); |
| 793 | return; |
| 794 | } |
| 795 | |
| 796 | // We want to look at dimension in terms of integer components, |
| 797 | // but dimLength is given in terms of bytes. |
| 798 | dimLength /= sizeof(int); |
| 799 | |
| 800 | // Only a single dimension is currently supported. |
| 801 | rsAssert(dimLength == 1); |
| 802 | if (dimLength == 1) { |
| 803 | // First do the increment loop. |
| 804 | size_t stride = elem->getSizeBytes(); |
| 805 | const char *cVal = reinterpret_cast<const char *>(data); |
| Stephen Hines | ac8d146 | 2014-06-25 00:01:23 -0700 | [diff] [blame] | 806 | for (uint32_t i = 0; i < dims[0]; i++) { |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 807 | elem->incRefs(cVal); |
| 808 | cVal += stride; |
| 809 | } |
| 810 | |
| 811 | // Decrement loop comes after (to prevent race conditions). |
| 812 | char *oldVal = reinterpret_cast<char *>(destPtr); |
| Stephen Hines | ac8d146 | 2014-06-25 00:01:23 -0700 | [diff] [blame] | 813 | for (uint32_t i = 0; i < dims[0]; i++) { |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 814 | elem->decRefs(oldVal); |
| 815 | oldVal += stride; |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | memcpy(destPtr, data, dataLength); |
| 820 | } |
| 821 | |
| 822 | void RsdCpuScriptImpl::setGlobalBind(uint32_t slot, Allocation *data) { |
| 823 | |
| 824 | //rsAssert(!script->mFieldIsObject[slot]); |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 825 | //ALOGE("setGlobalBind %i %p", slot, data); |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 826 | |
| Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 827 | int32_t *destPtr = reinterpret_cast<int32_t *>(mScriptExec->getFieldAddress(slot)); |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 828 | if (!destPtr) { |
| 829 | //ALOGV("Calling setVar on slot = %i which is null", slot); |
| 830 | return; |
| 831 | } |
| 832 | |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 833 | void *ptr = nullptr; |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 834 | mBoundAllocs[slot] = data; |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 835 | if (data) { |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 836 | ptr = data->mHal.drvState.lod[0].mallocPtr; |
| 837 | } |
| 838 | memcpy(destPtr, &ptr, sizeof(void *)); |
| 839 | } |
| 840 | |
| 841 | void RsdCpuScriptImpl::setGlobalObj(uint32_t slot, ObjectBase *data) { |
| 842 | |
| 843 | //rsAssert(script->mFieldIsObject[slot]); |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 844 | //ALOGE("setGlobalObj %i %p", slot, data); |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 845 | |
| Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 846 | int32_t *destPtr = reinterpret_cast<int32_t *>(mScriptExec->getFieldAddress(slot)); |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 847 | if (!destPtr) { |
| 848 | //ALOGV("Calling setVar on slot = %i which is null", slot); |
| 849 | return; |
| 850 | } |
| 851 | |
| Jason Sams | 05ef73f | 2014-08-05 14:59:22 -0700 | [diff] [blame] | 852 | rsrSetObject(mCtx->getContext(), (rs_object_base *)destPtr, data); |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 853 | } |
| 854 | |
| Yang Ni | 062c287 | 2015-02-20 15:20:00 -0800 | [diff] [blame] | 855 | const char* RsdCpuScriptImpl::getFieldName(uint32_t slot) const { |
| 856 | return mScriptExec->getFieldName(slot); |
| 857 | } |
| 858 | |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 859 | RsdCpuScriptImpl::~RsdCpuScriptImpl() { |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 860 | #ifndef RS_COMPATIBILITY_LIB |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 861 | if (mCompilerDriver) { |
| 862 | delete mCompilerDriver; |
| 863 | } |
| Stephen Hines | 45e753a | 2015-01-19 20:58:44 -0800 | [diff] [blame] | 864 | #endif |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 865 | |
| Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 866 | if (mScriptExec != nullptr) { |
| 867 | delete mScriptExec; |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 868 | } |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 869 | if (mBoundAllocs) delete[] mBoundAllocs; |
| 870 | if (mScriptSO) { |
| 871 | dlclose(mScriptSO); |
| 872 | } |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | Allocation * RsdCpuScriptImpl::getAllocationForPointer(const void *ptr) const { |
| 876 | if (!ptr) { |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 877 | return nullptr; |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | for (uint32_t ct=0; ct < mScript->mHal.info.exportedVariableCount; ct++) { |
| 881 | Allocation *a = mBoundAllocs[ct]; |
| 882 | if (!a) continue; |
| 883 | if (a->mHal.drvState.lod[0].mallocPtr == ptr) { |
| 884 | return a; |
| 885 | } |
| 886 | } |
| 887 | ALOGE("rsGetAllocation, failed to find %p", ptr); |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 888 | return nullptr; |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 889 | } |
| 890 | |
| Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 891 | void RsdCpuScriptImpl::preLaunch(uint32_t slot, const Allocation ** ains, |
| 892 | uint32_t inLen, Allocation * aout, |
| 893 | const void * usr, uint32_t usrLen, |
| 894 | const RsScriptCall *sc) {} |
| Jason Sams | 17e3cdc | 2013-09-09 17:32:16 -0700 | [diff] [blame] | 895 | |
| Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 896 | void RsdCpuScriptImpl::postLaunch(uint32_t slot, const Allocation ** ains, |
| 897 | uint32_t inLen, Allocation * aout, |
| 898 | const void * usr, uint32_t usrLen, |
| 899 | const RsScriptCall *sc) {} |
| Jason Sams | 17e3cdc | 2013-09-09 17:32:16 -0700 | [diff] [blame] | 900 | |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 901 | |
| 902 | } |
| 903 | } |