rsCpuScript.h revision 6c1876bbef1b2c89975dce91230a168bd2d2ce4c
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_CPU_SCRIPT_H 18#define RSD_CPU_SCRIPT_H 19 20#include <rs_hal.h> 21#include <rsRuntime.h> 22 23#ifndef RS_COMPATIBILITY_LIB 24#include <utility> 25#endif 26 27#include "rsCpuCore.h" 28 29namespace bcinfo { 30 class MetadataExtractor; 31} 32 33namespace android { 34namespace renderscript { 35 36class ScriptExecutable; 37 38class RsdCpuScriptImpl : public RsdCpuReferenceImpl::CpuScript { 39public: 40 bool init(char const *resName, char const *cacheDir, 41 uint8_t const *bitcode, size_t bitcodeSize, uint32_t flags, 42 char const *bccPluginName = nullptr); 43 void populateScript(Script *) override; 44 45 void invokeFunction(uint32_t slot, const void *params, size_t paramLength) override; 46 int invokeRoot() override; 47 virtual void preLaunch(uint32_t slot, const Allocation ** ains, 48 uint32_t inLen, Allocation * aout, const void * usr, 49 uint32_t usrLen, const RsScriptCall *sc); 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); 54 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; 62 63 void invokeReduce(uint32_t slot, 64 const Allocation* ain, 65 Allocation* aout, 66 const RsScriptCall* sc) override; 67 68 void invokeReduceNew(uint32_t slot, 69 const Allocation ** ains, uint32_t inLen, 70 Allocation* aout, 71 const RsScriptCall* sc) override; 72 73 void invokeInit() override; 74 void invokeFreeChildren() override; 75 76 void setGlobalVar(uint32_t slot, const void *data, size_t dataLength) override; 77 void getGlobalVar(uint32_t slot, void *data, size_t dataLength) override; 78 void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength, 79 const Element *e, const uint32_t *dims, 80 size_t dimLength) override; 81 void setGlobalBind(uint32_t slot, Allocation *data) override; 82 void setGlobalObj(uint32_t slot, ObjectBase *data) override; 83 84 const char* getFieldName(uint32_t slot) const; 85 86 ~RsdCpuScriptImpl() override; 87 RsdCpuScriptImpl(RsdCpuReferenceImpl *ctx, const Script *s); 88 89 const Script * getScript() {return mScript;} 90 91 bool forEachMtlsSetup(const Allocation ** ains, uint32_t inLen, 92 Allocation * aout, const void * usr, uint32_t usrLen, 93 const RsScriptCall *sc, MTLaunchStructForEach *mtls); 94 95 virtual void forEachKernelSetup(uint32_t slot, MTLaunchStructForEach *mtls); 96 97 // Build an MTLaunchStruct suitable for launching a simple reduce-style kernel. 98 bool reduceMtlsSetup(const Allocation *ain, const Allocation *aout, 99 const RsScriptCall *sc, MTLaunchStructReduce *mtls); 100 // Finalize an MTLaunchStruct for launching a simple reduce-style kernel. 101 virtual void reduceKernelSetup(uint32_t slot, MTLaunchStructReduce *mtls); 102 103 // Build an MTLaunchStruct suitable for launching a general reduce-style kernel. 104 bool reduceNewMtlsSetup(const Allocation ** ains, uint32_t inLen, const Allocation *aout, 105 const RsScriptCall *sc, MTLaunchStructReduceNew *mtls); 106 // Finalize an MTLaunchStruct for launching a general reduce-style kernel. 107 virtual void reduceNewKernelSetup(uint32_t slot, MTLaunchStructReduceNew *mtls); 108 109 const RsdCpuReference::CpuSymbol * lookupSymbolMath(const char *sym); 110 static void * lookupRuntimeStub(void* pContext, char const* name); 111 112 Allocation * getAllocationForPointer(const void *ptr) const override; 113 bool storeRSInfoFromSO(); 114 115 int getGlobalEntries() const override; 116 const char * getGlobalName(int i) const override; 117 const void * getGlobalAddress(int i) const override; 118 size_t getGlobalSize(int i) const override; 119 uint32_t getGlobalProperties(int i) const override; 120 121protected: 122 RsdCpuReferenceImpl *mCtx; 123 const Script *mScript; 124 void *mScriptSO; 125 126#ifndef RS_COMPATIBILITY_LIB 127 // Returns the path to the core library we'll use. 128 const char* findCoreLib(const bcinfo::MetadataExtractor& bitCodeMetaData, const char* bitcode, 129 size_t bitcodeSize); 130#endif 131 132 RootFunc_t mRoot; 133 RootFunc_t mRootExpand; 134 InitOrDtorFunc_t mInit; 135 InitOrDtorFunc_t mFreeChildren; 136 ScriptExecutable* mScriptExec; 137 138 Allocation **mBoundAllocs; 139 void * mIntrinsicData; 140 bool mIsThreadable; 141 142public: 143 static const char* BCC_EXE_PATH; 144 const char* getBitcodeFilePath() const { return mBitcodeFilePath.string(); } 145 146private: 147 bool setUpMtlsDimensions(MTLaunchStructCommon *mtls, 148 const RsLaunchDimensions &baseDim, 149 const RsScriptCall *sc); 150 151 String8 mBitcodeFilePath; 152 uint32_t mBuildChecksum; 153 bool mChecksumNeeded; 154}; 155 156Allocation * rsdScriptGetAllocationForPointer( 157 const Context *dc, 158 const Script *script, 159 const void *); 160 161uint32_t constructBuildChecksum(uint8_t const *bitcode, size_t bitcodeSize, 162 const char *commandLine, 163 const char ** bccFiles, size_t numFiles); 164 165} 166 167#ifdef __LP64__ 168#define SYSLIBPATH "/system/lib64" 169#define SYSLIBPATH_VENDOR "/system/vendor/lib64" 170#else 171#define SYSLIBPATH "/system/lib" 172#define SYSLIBPATH_VENDOR "/system/vendor/lib" 173#endif 174 175} 176 177#endif // RSD_CPU_SCRIPT_H 178