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 |
| 7 | * |
| 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 | |
Stephen Hines | 6a236ad | 2015-06-22 14:51:30 -0700 | [diff] [blame] | 17 | #ifndef RSD_CPU_SCRIPT_H |
| 18 | #define RSD_CPU_SCRIPT_H |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 19 | |
| 20 | #include <rs_hal.h> |
| 21 | #include <rsRuntime.h> |
| 22 | |
Stephen Hines | 25e3af5 | 2014-05-21 21:23:08 -0700 | [diff] [blame] | 23 | #ifndef RS_COMPATIBILITY_LIB |
Tim Murray | 29809d1 | 2014-05-28 12:04:19 -0700 | [diff] [blame] | 24 | #include <utility> |
Stephen Hines | 25e3af5 | 2014-05-21 21:23:08 -0700 | [diff] [blame] | 25 | #endif |
| 26 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 27 | #include "rsCpuCore.h" |
| 28 | |
Miao Wang | 82e135c | 2017-02-27 23:35:35 -0800 | [diff] [blame] | 29 | #include <string> |
| 30 | |
Jean-Luc Brouillet | 9ab5094 | 2014-06-18 18:10:32 -0700 | [diff] [blame] | 31 | namespace bcinfo { |
| 32 | class MetadataExtractor; |
Rahul Chaudhry | 7974fc0 | 2017-02-09 12:33:28 -0800 | [diff] [blame] | 33 | } // namespace bcinfo |
Jean-Luc Brouillet | 9ab5094 | 2014-06-18 18:10:32 -0700 | [diff] [blame] | 34 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 35 | namespace android { |
| 36 | namespace renderscript { |
| 37 | |
Yang Ni | 2abfcc6 | 2015-02-17 16:05:19 -0800 | [diff] [blame] | 38 | class ScriptExecutable; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 39 | |
| 40 | class RsdCpuScriptImpl : public RsdCpuReferenceImpl::CpuScript { |
| 41 | public: |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 42 | bool init(char const *resName, char const *cacheDir, |
Stephen Hines | 0051132 | 2014-01-31 11:20:23 -0800 | [diff] [blame] | 43 | uint8_t const *bitcode, size_t bitcodeSize, uint32_t flags, |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 44 | char const *bccPluginName = nullptr); |
Stephen Hines | c060f14 | 2015-05-13 19:26:09 -0700 | [diff] [blame] | 45 | void populateScript(Script *) override; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 46 | |
Stephen Hines | c060f14 | 2015-05-13 19:26:09 -0700 | [diff] [blame] | 47 | void invokeFunction(uint32_t slot, const void *params, size_t paramLength) override; |
| 48 | int invokeRoot() override; |
Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 49 | virtual void preLaunch(uint32_t slot, const Allocation ** ains, |
| 50 | uint32_t inLen, Allocation * aout, const void * usr, |
Jason Sams | 17e3cdc | 2013-09-09 17:32:16 -0700 | [diff] [blame] | 51 | uint32_t usrLen, const RsScriptCall *sc); |
Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 52 | virtual void postLaunch(uint32_t slot, const Allocation ** ains, |
| 53 | uint32_t inLen, Allocation * aout, |
| 54 | const void * usr, uint32_t usrLen, |
| 55 | const RsScriptCall *sc); |
Chris Wailes | 818cfa0 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 56 | |
Stephen Hines | c060f14 | 2015-05-13 19:26:09 -0700 | [diff] [blame] | 57 | void invokeForEach(uint32_t slot, |
| 58 | const Allocation ** ains, |
| 59 | uint32_t inLen, |
| 60 | Allocation* aout, |
| 61 | const void* usr, |
| 62 | uint32_t usrLen, |
| 63 | const RsScriptCall* sc) override; |
Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 64 | |
Matt Wala | 14ce007 | 2015-07-30 17:30:25 -0700 | [diff] [blame] | 65 | void invokeReduce(uint32_t slot, |
David Gross | ae2ec3f | 2016-06-01 14:45:47 -0700 | [diff] [blame] | 66 | const Allocation ** ains, uint32_t inLen, |
Matt Wala | 14ce007 | 2015-07-30 17:30:25 -0700 | [diff] [blame] | 67 | Allocation* aout, |
| 68 | const RsScriptCall* sc) override; |
| 69 | |
Stephen Hines | c060f14 | 2015-05-13 19:26:09 -0700 | [diff] [blame] | 70 | void invokeInit() override; |
| 71 | void invokeFreeChildren() override; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 72 | |
Stephen Hines | c060f14 | 2015-05-13 19:26:09 -0700 | [diff] [blame] | 73 | void setGlobalVar(uint32_t slot, const void *data, size_t dataLength) override; |
| 74 | void getGlobalVar(uint32_t slot, void *data, size_t dataLength) override; |
| 75 | void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength, |
| 76 | const Element *e, const uint32_t *dims, |
| 77 | size_t dimLength) override; |
| 78 | void setGlobalBind(uint32_t slot, Allocation *data) override; |
| 79 | void setGlobalObj(uint32_t slot, ObjectBase *data) override; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 80 | |
Yang Ni | 062c287 | 2015-02-20 15:20:00 -0800 | [diff] [blame] | 81 | const char* getFieldName(uint32_t slot) const; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 82 | |
Stephen Hines | c060f14 | 2015-05-13 19:26:09 -0700 | [diff] [blame] | 83 | ~RsdCpuScriptImpl() override; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 84 | RsdCpuScriptImpl(RsdCpuReferenceImpl *ctx, const Script *s); |
| 85 | |
| 86 | const Script * getScript() {return mScript;} |
| 87 | |
Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 88 | bool forEachMtlsSetup(const Allocation ** ains, uint32_t inLen, |
Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 89 | Allocation * aout, const void * usr, uint32_t usrLen, |
Matt Wala | 14ce007 | 2015-07-30 17:30:25 -0700 | [diff] [blame] | 90 | const RsScriptCall *sc, MTLaunchStructForEach *mtls); |
Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 91 | |
Matt Wala | 14ce007 | 2015-07-30 17:30:25 -0700 | [diff] [blame] | 92 | virtual void forEachKernelSetup(uint32_t slot, MTLaunchStructForEach *mtls); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 93 | |
David Gross | 6c1876b | 2016-01-15 11:52:14 -0800 | [diff] [blame] | 94 | // Build an MTLaunchStruct suitable for launching a general reduce-style kernel. |
David Gross | ae2ec3f | 2016-06-01 14:45:47 -0700 | [diff] [blame] | 95 | bool reduceMtlsSetup(const Allocation ** ains, uint32_t inLen, const Allocation *aout, |
| 96 | const RsScriptCall *sc, MTLaunchStructReduce *mtls); |
David Gross | 6c1876b | 2016-01-15 11:52:14 -0800 | [diff] [blame] | 97 | // Finalize an MTLaunchStruct for launching a general reduce-style kernel. |
David Gross | ae2ec3f | 2016-06-01 14:45:47 -0700 | [diff] [blame] | 98 | virtual void reduceKernelSetup(uint32_t slot, MTLaunchStructReduce *mtls); |
David Gross | 6c1876b | 2016-01-15 11:52:14 -0800 | [diff] [blame] | 99 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 100 | const RsdCpuReference::CpuSymbol * lookupSymbolMath(const char *sym); |
| 101 | static void * lookupRuntimeStub(void* pContext, char const* name); |
| 102 | |
Stephen Hines | c060f14 | 2015-05-13 19:26:09 -0700 | [diff] [blame] | 103 | Allocation * getAllocationForPointer(const void *ptr) const override; |
Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 104 | bool storeRSInfoFromSO(); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 105 | |
Stephen Hines | 8409d64 | 2015-04-28 18:49:56 -0700 | [diff] [blame] | 106 | int getGlobalEntries() const override; |
| 107 | const char * getGlobalName(int i) const override; |
| 108 | const void * getGlobalAddress(int i) const override; |
| 109 | size_t getGlobalSize(int i) const override; |
Stephen Hines | 5aa018c | 2015-05-20 18:09:57 -0700 | [diff] [blame] | 110 | uint32_t getGlobalProperties(int i) const override; |
Stephen Hines | 8409d64 | 2015-04-28 18:49:56 -0700 | [diff] [blame] | 111 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 112 | protected: |
| 113 | RsdCpuReferenceImpl *mCtx; |
| 114 | const Script *mScript; |
Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 115 | void *mScriptSO; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 116 | |
Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 117 | #ifndef RS_COMPATIBILITY_LIB |
Jean-Luc Brouillet | 40e35cd | 2014-06-25 18:21:45 -0700 | [diff] [blame] | 118 | // Returns the path to the core library we'll use. |
| 119 | const char* findCoreLib(const bcinfo::MetadataExtractor& bitCodeMetaData, const char* bitcode, |
Jean-Luc Brouillet | 9ab5094 | 2014-06-18 18:10:32 -0700 | [diff] [blame] | 120 | size_t bitcodeSize); |
Stephen Hines | 45e753a | 2015-01-19 20:58:44 -0800 | [diff] [blame] | 121 | #endif |
| 122 | |
Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 123 | RootFunc_t mRoot; |
| 124 | RootFunc_t mRootExpand; |
Matt Wala | 14ce007 | 2015-07-30 17:30:25 -0700 | [diff] [blame] | 125 | InitOrDtorFunc_t mInit; |
| 126 | InitOrDtorFunc_t mFreeChildren; |
Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 127 | ScriptExecutable* mScriptExec; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 128 | |
| 129 | Allocation **mBoundAllocs; |
| 130 | void * mIntrinsicData; |
| 131 | bool mIsThreadable; |
Yang Ni | da0f069 | 2015-01-12 13:03:40 -0800 | [diff] [blame] | 132 | |
Yang Ni | 2abfcc6 | 2015-02-17 16:05:19 -0800 | [diff] [blame] | 133 | public: |
| 134 | static const char* BCC_EXE_PATH; |
Miao Wang | 82e135c | 2017-02-27 23:35:35 -0800 | [diff] [blame] | 135 | const char* getBitcodeFilePath() const { return mBitcodeFilePath.c_str(); } |
Yang Ni | da0f069 | 2015-01-12 13:03:40 -0800 | [diff] [blame] | 136 | |
Yang Ni | 2abfcc6 | 2015-02-17 16:05:19 -0800 | [diff] [blame] | 137 | private: |
Matt Wala | 14ce007 | 2015-07-30 17:30:25 -0700 | [diff] [blame] | 138 | bool setUpMtlsDimensions(MTLaunchStructCommon *mtls, |
| 139 | const RsLaunchDimensions &baseDim, |
| 140 | const RsScriptCall *sc); |
| 141 | |
Miao Wang | 82e135c | 2017-02-27 23:35:35 -0800 | [diff] [blame] | 142 | std::string mBitcodeFilePath; |
Yang Ni | cb17015 | 2015-04-16 10:27:02 -0700 | [diff] [blame] | 143 | uint32_t mBuildChecksum; |
Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 144 | bool mChecksumNeeded; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 145 | }; |
| 146 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 147 | Allocation * rsdScriptGetAllocationForPointer( |
| 148 | const Context *dc, |
| 149 | const Script *script, |
| 150 | const void *); |
| 151 | |
Yang Ni | cb17015 | 2015-04-16 10:27:02 -0700 | [diff] [blame] | 152 | uint32_t constructBuildChecksum(uint8_t const *bitcode, size_t bitcodeSize, |
| 153 | const char *commandLine, |
| 154 | const char ** bccFiles, size_t numFiles); |
Yang Ni | f02a2b0 | 2015-04-07 16:00:31 -0700 | [diff] [blame] | 155 | |
Rahul Chaudhry | 7974fc0 | 2017-02-09 12:33:28 -0800 | [diff] [blame] | 156 | } // namespace renderscript |
Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 157 | |
Victor Khimenko | bd7a52b | 2020-09-11 23:15:44 +0200 | [diff] [blame] | 158 | #ifndef __ANDROID_NATIVE_BRIDGE__ |
| 159 | |
Yang Ni | da0f069 | 2015-01-12 13:03:40 -0800 | [diff] [blame] | 160 | #ifdef __LP64__ |
| 161 | #define SYSLIBPATH "/system/lib64" |
Victor Khimenko | cfb1d0b | 2016-10-28 17:05:22 +0200 | [diff] [blame] | 162 | #define SYSLIBPATH_BC "/system/lib64" |
Pirama Arumuga Nainar | 682672e | 2015-05-07 15:52:48 -0700 | [diff] [blame] | 163 | #define SYSLIBPATH_VENDOR "/system/vendor/lib64" |
Yang Ni | da0f069 | 2015-01-12 13:03:40 -0800 | [diff] [blame] | 164 | #else |
| 165 | #define SYSLIBPATH "/system/lib" |
Victor Khimenko | cfb1d0b | 2016-10-28 17:05:22 +0200 | [diff] [blame] | 166 | #define SYSLIBPATH_BC "/system/lib" |
Pirama Arumuga Nainar | 682672e | 2015-05-07 15:52:48 -0700 | [diff] [blame] | 167 | #define SYSLIBPATH_VENDOR "/system/vendor/lib" |
Yang Ni | da0f069 | 2015-01-12 13:03:40 -0800 | [diff] [blame] | 168 | #endif |
| 169 | |
Victor Khimenko | bd7a52b | 2020-09-11 23:15:44 +0200 | [diff] [blame] | 170 | #else |
| 171 | |
| 172 | #if defined(__arm__) |
| 173 | #define SYSLIBPATH "/system/lib/arm" |
| 174 | #define SYSLIBPATH_BC "/system/lib" |
| 175 | #define SYSLIBPATH_VENDOR "/system/vendor/lib/arm" |
| 176 | #elif defined(__aarch64__) |
| 177 | #define SYSLIBPATH "/system/lib64/arm64" |
| 178 | #define SYSLIBPATH_BC "/system/lib64" |
| 179 | #define SYSLIBPATH_VENDOR "/system/vendor/lib64/arm64" |
| 180 | #else |
| 181 | #error Unknown architecture |
| 182 | #endif |
| 183 | |
| 184 | #endif |
| 185 | |
Rahul Chaudhry | 7974fc0 | 2017-02-09 12:33:28 -0800 | [diff] [blame] | 186 | } // namespace android |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 187 | |
Yang Ni | a845c35 | 2017-05-01 15:53:23 -0700 | [diff] [blame] | 188 | namespace { |
| 189 | |
| 190 | inline bool is_force_recompile() { |
| 191 | char buf[PROP_VALUE_MAX]; |
| 192 | |
| 193 | // Re-compile if floating point precision has been overridden. |
| 194 | android::renderscript::property_get("debug.rs.precision", buf, ""); |
| 195 | if (buf[0] != '\0') { |
| 196 | return true; |
| 197 | } |
| 198 | |
| 199 | // Re-compile if debug.rs.forcerecompile is set. |
| 200 | android::renderscript::property_get("debug.rs.forcerecompile", buf, "0"); |
| 201 | if ((::strcmp(buf, "1") == 0) || (::strcmp(buf, "true") == 0)) { |
| 202 | return true; |
| 203 | } else { |
| 204 | return false; |
| 205 | } |
| 206 | } |
| 207 | |
Justin Yun | e0f1e2e | 2017-12-05 18:42:57 +0900 | [diff] [blame] | 208 | inline std::string getVndkSysLibPath() { |
| 209 | char buf[PROP_VALUE_MAX]; |
| 210 | android::renderscript::property_get("ro.vndk.version", buf, ""); |
Jooyung Han | 5b80907 | 2020-03-25 21:46:54 +0900 | [diff] [blame] | 211 | std::string vndk_path = "/apex/com.android.vndk.v" + std::string(buf) + "/lib"; |
| 212 | #ifdef __LP64__ |
| 213 | vndk_path += "64"; |
| 214 | #endif |
| 215 | return vndk_path; |
Justin Yun | e0f1e2e | 2017-12-05 18:42:57 +0900 | [diff] [blame] | 216 | } |
| 217 | |
Yang Ni | a845c35 | 2017-05-01 15:53:23 -0700 | [diff] [blame] | 218 | } // anonymous namespace |
| 219 | |
Stephen Hines | 6a236ad | 2015-06-22 14:51:30 -0700 | [diff] [blame] | 220 | #endif // RSD_CPU_SCRIPT_H |