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 | |
Jean-Luc Brouillet | 9ab5094 | 2014-06-18 18:10:32 -0700 | [diff] [blame] | 29 | namespace bcinfo { |
| 30 | class MetadataExtractor; |
| 31 | } |
| 32 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 33 | namespace android { |
| 34 | namespace renderscript { |
| 35 | |
Yang Ni | 2abfcc6 | 2015-02-17 16:05:19 -0800 | [diff] [blame] | 36 | class ScriptExecutable; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 37 | |
| 38 | class RsdCpuScriptImpl : public RsdCpuReferenceImpl::CpuScript { |
| 39 | public: |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 40 | bool init(char const *resName, char const *cacheDir, |
Stephen Hines | 0051132 | 2014-01-31 11:20:23 -0800 | [diff] [blame] | 41 | uint8_t const *bitcode, size_t bitcodeSize, uint32_t flags, |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 42 | char const *bccPluginName = nullptr); |
Stephen Hines | c060f14 | 2015-05-13 19:26:09 -0700 | [diff] [blame] | 43 | void populateScript(Script *) override; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 44 | |
Stephen Hines | c060f14 | 2015-05-13 19:26:09 -0700 | [diff] [blame] | 45 | void invokeFunction(uint32_t slot, const void *params, size_t paramLength) override; |
| 46 | int invokeRoot() override; |
Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 47 | virtual void preLaunch(uint32_t slot, const Allocation ** ains, |
| 48 | uint32_t inLen, Allocation * aout, const void * usr, |
Jason Sams | 17e3cdc | 2013-09-09 17:32:16 -0700 | [diff] [blame] | 49 | uint32_t usrLen, const RsScriptCall *sc); |
Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 50 | virtual void postLaunch(uint32_t slot, const Allocation ** ains, |
| 51 | uint32_t inLen, Allocation * aout, |
| 52 | const void * usr, uint32_t usrLen, |
| 53 | const RsScriptCall *sc); |
Chris Wailes | 818cfa0 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 54 | |
Stephen Hines | c060f14 | 2015-05-13 19:26:09 -0700 | [diff] [blame] | 55 | void invokeForEach(uint32_t slot, |
| 56 | const Allocation ** ains, |
| 57 | uint32_t inLen, |
| 58 | Allocation* aout, |
| 59 | const void* usr, |
| 60 | uint32_t usrLen, |
| 61 | const RsScriptCall* sc) override; |
Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 62 | |
Matt Wala | 14ce007 | 2015-07-30 17:30:25 -0700 | [diff] [blame] | 63 | void invokeReduce(uint32_t slot, |
| 64 | const Allocation* ain, |
| 65 | Allocation* aout, |
| 66 | const RsScriptCall* sc) override; |
| 67 | |
Stephen Hines | c060f14 | 2015-05-13 19:26:09 -0700 | [diff] [blame] | 68 | void invokeInit() override; |
| 69 | void invokeFreeChildren() override; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 70 | |
Stephen Hines | c060f14 | 2015-05-13 19:26:09 -0700 | [diff] [blame] | 71 | void setGlobalVar(uint32_t slot, const void *data, size_t dataLength) override; |
| 72 | void getGlobalVar(uint32_t slot, void *data, size_t dataLength) override; |
| 73 | void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength, |
| 74 | const Element *e, const uint32_t *dims, |
| 75 | size_t dimLength) override; |
| 76 | void setGlobalBind(uint32_t slot, Allocation *data) override; |
| 77 | void setGlobalObj(uint32_t slot, ObjectBase *data) override; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 78 | |
Yang Ni | 062c287 | 2015-02-20 15:20:00 -0800 | [diff] [blame] | 79 | const char* getFieldName(uint32_t slot) const; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 80 | |
Stephen Hines | c060f14 | 2015-05-13 19:26:09 -0700 | [diff] [blame] | 81 | ~RsdCpuScriptImpl() override; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 82 | RsdCpuScriptImpl(RsdCpuReferenceImpl *ctx, const Script *s); |
| 83 | |
| 84 | const Script * getScript() {return mScript;} |
| 85 | |
Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 86 | bool forEachMtlsSetup(const Allocation ** ains, uint32_t inLen, |
Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 87 | Allocation * aout, const void * usr, uint32_t usrLen, |
Matt Wala | 14ce007 | 2015-07-30 17:30:25 -0700 | [diff] [blame] | 88 | const RsScriptCall *sc, MTLaunchStructForEach *mtls); |
Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 89 | |
Matt Wala | 14ce007 | 2015-07-30 17:30:25 -0700 | [diff] [blame] | 90 | virtual void forEachKernelSetup(uint32_t slot, MTLaunchStructForEach *mtls); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 91 | |
Matt Wala | 14ce007 | 2015-07-30 17:30:25 -0700 | [diff] [blame] | 92 | // Build an MTLaunchStruct suitable for launching a reduce-style kernel. |
| 93 | bool reduceMtlsSetup(const Allocation *ain, const Allocation *aout, |
| 94 | const RsScriptCall *sc, MTLaunchStructReduce *mtls); |
| 95 | // Finalize an MTLaunchStruct for launching a reduce-style kernel. |
| 96 | virtual void reduceKernelSetup(uint32_t slot, MTLaunchStructReduce *mtls); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 97 | |
| 98 | const RsdCpuReference::CpuSymbol * lookupSymbolMath(const char *sym); |
| 99 | static void * lookupRuntimeStub(void* pContext, char const* name); |
| 100 | |
Stephen Hines | c060f14 | 2015-05-13 19:26:09 -0700 | [diff] [blame] | 101 | Allocation * getAllocationForPointer(const void *ptr) const override; |
Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 102 | bool storeRSInfoFromSO(); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 103 | |
Stephen Hines | 8409d64 | 2015-04-28 18:49:56 -0700 | [diff] [blame] | 104 | int getGlobalEntries() const override; |
| 105 | const char * getGlobalName(int i) const override; |
| 106 | const void * getGlobalAddress(int i) const override; |
| 107 | size_t getGlobalSize(int i) const override; |
Stephen Hines | 5aa018c | 2015-05-20 18:09:57 -0700 | [diff] [blame] | 108 | uint32_t getGlobalProperties(int i) const override; |
Stephen Hines | 8409d64 | 2015-04-28 18:49:56 -0700 | [diff] [blame] | 109 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 110 | protected: |
| 111 | RsdCpuReferenceImpl *mCtx; |
| 112 | const Script *mScript; |
Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 113 | void *mScriptSO; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 114 | |
Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 115 | #ifndef RS_COMPATIBILITY_LIB |
Jean-Luc Brouillet | 40e35cd | 2014-06-25 18:21:45 -0700 | [diff] [blame] | 116 | // Returns the path to the core library we'll use. |
| 117 | const char* findCoreLib(const bcinfo::MetadataExtractor& bitCodeMetaData, const char* bitcode, |
Jean-Luc Brouillet | 9ab5094 | 2014-06-18 18:10:32 -0700 | [diff] [blame] | 118 | size_t bitcodeSize); |
Stephen Hines | 45e753a | 2015-01-19 20:58:44 -0800 | [diff] [blame] | 119 | #endif |
| 120 | |
Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 121 | RootFunc_t mRoot; |
| 122 | RootFunc_t mRootExpand; |
Matt Wala | 14ce007 | 2015-07-30 17:30:25 -0700 | [diff] [blame] | 123 | InitOrDtorFunc_t mInit; |
| 124 | InitOrDtorFunc_t mFreeChildren; |
Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 125 | ScriptExecutable* mScriptExec; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 126 | |
| 127 | Allocation **mBoundAllocs; |
| 128 | void * mIntrinsicData; |
| 129 | bool mIsThreadable; |
Yang Ni | da0f069 | 2015-01-12 13:03:40 -0800 | [diff] [blame] | 130 | |
Yang Ni | 2abfcc6 | 2015-02-17 16:05:19 -0800 | [diff] [blame] | 131 | public: |
| 132 | static const char* BCC_EXE_PATH; |
| 133 | const char* getBitcodeFilePath() const { return mBitcodeFilePath.string(); } |
Yang Ni | da0f069 | 2015-01-12 13:03:40 -0800 | [diff] [blame] | 134 | |
Yang Ni | 2abfcc6 | 2015-02-17 16:05:19 -0800 | [diff] [blame] | 135 | private: |
Matt Wala | 14ce007 | 2015-07-30 17:30:25 -0700 | [diff] [blame] | 136 | bool setUpMtlsDimensions(MTLaunchStructCommon *mtls, |
| 137 | const RsLaunchDimensions &baseDim, |
| 138 | const RsScriptCall *sc); |
| 139 | |
Yang Ni | 2abfcc6 | 2015-02-17 16:05:19 -0800 | [diff] [blame] | 140 | String8 mBitcodeFilePath; |
Yang Ni | cb17015 | 2015-04-16 10:27:02 -0700 | [diff] [blame] | 141 | uint32_t mBuildChecksum; |
Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 142 | bool mChecksumNeeded; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 143 | }; |
| 144 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 145 | Allocation * rsdScriptGetAllocationForPointer( |
| 146 | const Context *dc, |
| 147 | const Script *script, |
| 148 | const void *); |
| 149 | |
Yang Ni | cb17015 | 2015-04-16 10:27:02 -0700 | [diff] [blame] | 150 | uint32_t constructBuildChecksum(uint8_t const *bitcode, size_t bitcodeSize, |
| 151 | const char *commandLine, |
| 152 | const char ** bccFiles, size_t numFiles); |
Yang Ni | f02a2b0 | 2015-04-07 16:00:31 -0700 | [diff] [blame] | 153 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 154 | } |
Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 155 | |
Yang Ni | da0f069 | 2015-01-12 13:03:40 -0800 | [diff] [blame] | 156 | #ifdef __LP64__ |
| 157 | #define SYSLIBPATH "/system/lib64" |
Pirama Arumuga Nainar | 682672e | 2015-05-07 15:52:48 -0700 | [diff] [blame] | 158 | #define SYSLIBPATH_VENDOR "/system/vendor/lib64" |
Yang Ni | da0f069 | 2015-01-12 13:03:40 -0800 | [diff] [blame] | 159 | #else |
| 160 | #define SYSLIBPATH "/system/lib" |
Pirama Arumuga Nainar | 682672e | 2015-05-07 15:52:48 -0700 | [diff] [blame] | 161 | #define SYSLIBPATH_VENDOR "/system/vendor/lib" |
Yang Ni | da0f069 | 2015-01-12 13:03:40 -0800 | [diff] [blame] | 162 | #endif |
| 163 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 164 | } |
| 165 | |
Stephen Hines | 6a236ad | 2015-06-22 14:51:30 -0700 | [diff] [blame] | 166 | #endif // RSD_CPU_SCRIPT_H |