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