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 | |
| 17 | #ifndef RSD_BCC_H |
| 18 | #define RSD_BCC_H |
| 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 | |
| 29 | namespace bcc { |
| 30 | class BCCContext; |
| 31 | class RSCompilerDriver; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 32 | } |
| 33 | |
Jean-Luc Brouillet | 9ab5094 | 2014-06-18 18:10:32 -0700 | [diff] [blame] | 34 | namespace bcinfo { |
| 35 | class MetadataExtractor; |
| 36 | } |
| 37 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 38 | namespace android { |
| 39 | namespace renderscript { |
| 40 | |
Yang Ni | 2abfcc6 | 2015-02-17 16:05:19 -0800 | [diff] [blame] | 41 | class ScriptExecutable; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 42 | |
| 43 | class RsdCpuScriptImpl : public RsdCpuReferenceImpl::CpuScript { |
| 44 | public: |
| 45 | typedef void (*outer_foreach_t)( |
David Gross | 05935c0 | 2015-03-13 21:29:54 +0000 | [diff] [blame] | 46 | const RsExpandKernelParams *, |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 47 | uint32_t x1, uint32_t x2, |
Chris Wailes | 9ed7910 | 2014-07-25 15:53:28 -0700 | [diff] [blame] | 48 | uint32_t outstep); |
Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 49 | |
Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 50 | typedef void (* InvokeFunc_t)(void); |
| 51 | typedef void (* ForEachFunc_t)(void); |
| 52 | typedef int (* RootFunc_t)(void); |
Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 53 | #ifdef RS_COMPATIBILITY_LIB |
Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 54 | typedef void (*WorkerCallback_t)(void *usr, uint32_t idx); |
| 55 | #endif |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 56 | |
| 57 | bool init(char const *resName, char const *cacheDir, |
Stephen Hines | 0051132 | 2014-01-31 11:20:23 -0800 | [diff] [blame] | 58 | uint8_t const *bitcode, size_t bitcodeSize, uint32_t flags, |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 59 | char const *bccPluginName = nullptr); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 60 | virtual void populateScript(Script *); |
| 61 | |
| 62 | virtual void invokeFunction(uint32_t slot, const void *params, size_t paramLength); |
| 63 | virtual int invokeRoot(); |
Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 64 | virtual void preLaunch(uint32_t slot, const Allocation ** ains, |
| 65 | uint32_t inLen, Allocation * aout, const void * usr, |
Jason Sams | 17e3cdc | 2013-09-09 17:32:16 -0700 | [diff] [blame] | 66 | uint32_t usrLen, const RsScriptCall *sc); |
Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 67 | virtual void postLaunch(uint32_t slot, const Allocation ** ains, |
| 68 | uint32_t inLen, Allocation * aout, |
| 69 | const void * usr, uint32_t usrLen, |
| 70 | const RsScriptCall *sc); |
Chris Wailes | 818cfa0 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 71 | |
Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 72 | virtual void invokeForEach(uint32_t slot, |
| 73 | const Allocation ** ains, |
| 74 | uint32_t inLen, |
| 75 | Allocation* aout, |
| 76 | const void* usr, |
| 77 | uint32_t usrLen, |
| 78 | const RsScriptCall* sc); |
| 79 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 80 | virtual void invokeInit(); |
| 81 | virtual void invokeFreeChildren(); |
| 82 | |
| 83 | virtual void setGlobalVar(uint32_t slot, const void *data, size_t dataLength); |
Tim Murray | 9c64239 | 2013-04-11 13:29:59 -0700 | [diff] [blame] | 84 | virtual void getGlobalVar(uint32_t slot, void *data, size_t dataLength); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 85 | virtual void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength, |
Stephen Hines | ac8d146 | 2014-06-25 00:01:23 -0700 | [diff] [blame] | 86 | const Element *e, const uint32_t *dims, size_t dimLength); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 87 | virtual void setGlobalBind(uint32_t slot, Allocation *data); |
| 88 | virtual void setGlobalObj(uint32_t slot, ObjectBase *data); |
| 89 | |
Yang Ni | 062c287 | 2015-02-20 15:20:00 -0800 | [diff] [blame] | 90 | const char* getFieldName(uint32_t slot) const; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 91 | |
| 92 | virtual ~RsdCpuScriptImpl(); |
| 93 | RsdCpuScriptImpl(RsdCpuReferenceImpl *ctx, const Script *s); |
| 94 | |
| 95 | const Script * getScript() {return mScript;} |
| 96 | |
Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 97 | bool forEachMtlsSetup(const Allocation ** ains, uint32_t inLen, |
Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 98 | Allocation * aout, const void * usr, uint32_t usrLen, |
| 99 | const RsScriptCall *sc, MTLaunchStruct *mtls); |
| 100 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 101 | virtual void forEachKernelSetup(uint32_t slot, MTLaunchStruct *mtls); |
| 102 | |
| 103 | |
| 104 | const RsdCpuReference::CpuSymbol * lookupSymbolMath(const char *sym); |
| 105 | static void * lookupRuntimeStub(void* pContext, char const* name); |
| 106 | |
| 107 | virtual Allocation * getAllocationForPointer(const void *ptr) const; |
Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 108 | bool storeRSInfoFromSO(); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [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); |
Tim Murray | 29809d1 | 2014-05-28 12:04:19 -0700 | [diff] [blame] | 119 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 120 | bcc::RSCompilerDriver *mCompilerDriver; |
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; |
| 125 | InvokeFunc_t mInit; |
| 126 | InvokeFunc_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; |
| 135 | const char* getBitcodeFilePath() const { return mBitcodeFilePath.string(); } |
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: |
| 138 | String8 mBitcodeFilePath; |
Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 139 | const char * mBuildChecksum; |
| 140 | bool mChecksumNeeded; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 141 | }; |
| 142 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 143 | Allocation * rsdScriptGetAllocationForPointer( |
| 144 | const Context *dc, |
| 145 | const Script *script, |
| 146 | const void *); |
| 147 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 148 | } |
Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 149 | |
Yang Ni | da0f069 | 2015-01-12 13:03:40 -0800 | [diff] [blame] | 150 | #ifdef __LP64__ |
| 151 | #define SYSLIBPATH "/system/lib64" |
| 152 | #else |
| 153 | #define SYSLIBPATH "/system/lib" |
| 154 | #endif |
| 155 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | #endif |