rsCpuCore.h revision c060f1435e7b9405f3be8974417fa6f410f03753
1/* 2 * Copyright (C) 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_CORE_H 18#define RSD_CPU_CORE_H 19 20#include "rsd_cpu.h" 21#include "rsSignal.h" 22#include "rsContext.h" 23#include "rsCppUtils.h" 24#include "rsElement.h" 25#include "rsScriptC.h" 26#include "rsCpuCoreRuntime.h" 27 28namespace bcc { 29 class BCCContext; 30 class RSCompilerDriver; 31 class RSExecutable; 32} 33 34namespace android { 35namespace renderscript { 36 37extern bool gArchUseSIMD; 38 39typedef void (* InvokeFunc_t)(void); 40typedef void (* ForEachFunc_t)(void); 41typedef void (*WorkerCallback_t)(void *usr, uint32_t idx); 42 43class RsdCpuScriptImpl; 44class RsdCpuReferenceImpl; 45 46struct ScriptTLSStruct { 47 android::renderscript::Context * mContext; 48 const android::renderscript::Script * mScript; 49 RsdCpuScriptImpl *mImpl; 50}; 51 52struct MTLaunchStruct { 53 RsExpandKernelDriverInfo fep; 54 55 RsdCpuReferenceImpl *rsc; 56 RsdCpuScriptImpl *script; 57 58 ForEachFunc_t kernel; 59 uint32_t sig; 60 const Allocation * ains[RS_KERNEL_INPUT_LIMIT]; 61 Allocation * aout[RS_KERNEL_INPUT_LIMIT]; 62 63 uint32_t mSliceSize; 64 volatile int mSliceNum; 65 bool isThreadable; 66 67 RsLaunchDimensions start; 68 RsLaunchDimensions end; 69}; 70 71class RsdCpuReferenceImpl : public RsdCpuReference { 72public: 73 ~RsdCpuReferenceImpl() override; 74 RsdCpuReferenceImpl(Context *); 75 76 void lockMutex(); 77 void unlockMutex(); 78 79 bool init(uint32_t version_major, uint32_t version_minor, sym_lookup_t, script_lookup_t); 80 void setPriority(int32_t priority) override; 81 virtual void launchThreads(WorkerCallback_t cbk, void *data); 82 static void * helperThreadProc(void *vrsc); 83 RsdCpuScriptImpl * setTLS(RsdCpuScriptImpl *sc); 84 85 Context * getContext() {return mRSC;} 86 uint32_t getThreadCount() const { 87 return mWorkers.mCount + 1; 88 } 89 90 void launchThreads(const Allocation** ains, uint32_t inLen, Allocation* aout, 91 const RsScriptCall* sc, MTLaunchStruct* mtls); 92 93 CpuScript * createScript(const ScriptC *s, char const *resName, char const *cacheDir, 94 uint8_t const *bitcode, size_t bitcodeSize, uint32_t flags) override; 95 CpuScript * createIntrinsic(const Script *s, RsScriptIntrinsicID iid, Element *e) override; 96 void* createScriptGroup(const ScriptGroupBase *sg) override; 97 98 const RsdCpuReference::CpuSymbol *symLookup(const char *); 99 100 RsdCpuReference::CpuScript * lookupScript(const Script *s) { 101 return mScriptLookupFn(mRSC, s); 102 } 103 104 void setLinkRuntimeCallback( 105 bcc::RSLinkRuntimeCallback pLinkRuntimeCallback) { 106 mLinkRuntimeCallback = pLinkRuntimeCallback; 107 } 108 bcc::RSLinkRuntimeCallback getLinkRuntimeCallback() { 109 return mLinkRuntimeCallback; 110 } 111 112 void setSelectRTCallback(RSSelectRTCallback pSelectRTCallback) { 113 mSelectRTCallback = pSelectRTCallback; 114 } 115 RSSelectRTCallback getSelectRTCallback() { 116 return mSelectRTCallback; 117 } 118 119#ifndef RS_COMPATIBILITY_LIB 120 void setSetupCompilerCallback(RSSetupCompilerCallback pSetupCompilerCallback) override { 121 mSetupCompilerCallback = pSetupCompilerCallback; 122 } 123 RSSetupCompilerCallback getSetupCompilerCallback() const override { 124 return mSetupCompilerCallback; 125 } 126#endif 127 128 virtual void setBccPluginName(const char *name) { 129 mBccPluginName.setTo(name); 130 } 131 virtual const char *getBccPluginName() const { 132 return mBccPluginName.string(); 133 } 134 bool getInForEach() override { return mInForEach; } 135 136 // Set to true if we should embed global variable information in the code. 137 void setEmbedGlobalInfo(bool v) override { 138 mEmbedGlobalInfo = v; 139 } 140 141 // Returns true if we should embed global variable information in the code. 142 bool getEmbedGlobalInfo() const override { 143 return mEmbedGlobalInfo; 144 } 145 146 // Set to true if we should skip constant (immutable) global variables when 147 // potentially embedding information about globals. 148 void setEmbedGlobalInfoSkipConstant(bool v) override { 149 mEmbedGlobalInfoSkipConstant = v; 150 } 151 152 // Returns true if we should skip constant (immutable) global variables when 153 // potentially embedding information about globals. 154 bool getEmbedGlobalInfoSkipConstant() const override { 155 return mEmbedGlobalInfoSkipConstant; 156 } 157 158protected: 159 Context *mRSC; 160 uint32_t version_major; 161 uint32_t version_minor; 162 //bool mHasGraphics; 163 bool mInForEach; 164 165 struct Workers { 166 volatile int mRunningCount; 167 volatile int mLaunchCount; 168 uint32_t mCount; 169 pthread_t *mThreadId; 170 pid_t *mNativeThreadId; 171 Signal mCompleteSignal; 172 Signal *mLaunchSignals; 173 WorkerCallback_t mLaunchCallback; 174 void *mLaunchData; 175 }; 176 Workers mWorkers; 177 bool mExit; 178 sym_lookup_t mSymLookupFn; 179 script_lookup_t mScriptLookupFn; 180 181 ScriptTLSStruct mTlsStruct; 182 183 bcc::RSLinkRuntimeCallback mLinkRuntimeCallback; 184 RSSelectRTCallback mSelectRTCallback; 185 RSSetupCompilerCallback mSetupCompilerCallback; 186 String8 mBccPluginName; 187 188 // Specifies whether we should embed global variable information in the 189 // code via special RS variables that can be examined later by the driver. 190 // Defaults to true. 191 bool mEmbedGlobalInfo; 192 193 // Specifies whether we should skip constant (immutable) global variables 194 // when potentially embedding information about globals. 195 // Defaults to true. 196 bool mEmbedGlobalInfoSkipConstant; 197}; 198 199 200} 201} 202 203#endif 204