rsCpuScript.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. #ifndef RSD_CPU_SCRIPT_H
  17. #define RSD_CPU_SCRIPT_H
  18. #include <rs_hal.h>
  19. #include <rsRuntime.h>
  20. #ifndef RS_COMPATIBILITY_LIB
  21. #include <utility>
  22. #endif
  23. #include "rsCpuCore.h"
  24. #include <string>
  25. namespace bcinfo {
  26. class MetadataExtractor;
  27. } // namespace bcinfo
  28. namespace android {
  29. namespace renderscript {
  30. class ScriptExecutable;
  31. class RsdCpuScriptImpl : public RsdCpuReferenceImpl::CpuScript {
  32. public:
  33. bool init(char const *resName, char const *cacheDir,
  34. uint8_t const *bitcode, size_t bitcodeSize, uint32_t flags,
  35. char const *bccPluginName = nullptr);
  36. void populateScript(Script *) override;
  37. void invokeFunction(uint32_t slot, const void *params, size_t paramLength) override;
  38. int invokeRoot() override;
  39. virtual void preLaunch(uint32_t slot, const Allocation ** ains,
  40. uint32_t inLen, Allocation * aout, const void * usr,
  41. uint32_t usrLen, const RsScriptCall *sc);
  42. virtual void postLaunch(uint32_t slot, const Allocation ** ains,
  43. uint32_t inLen, Allocation * aout,
  44. const void * usr, uint32_t usrLen,
  45. const RsScriptCall *sc);
  46. void invokeForEach(uint32_t slot,
  47. const Allocation ** ains,
  48. uint32_t inLen,
  49. Allocation* aout,
  50. const void* usr,
  51. uint32_t usrLen,
  52. const RsScriptCall* sc) override;
  53. void invokeReduce(uint32_t slot,
  54. const Allocation ** ains, uint32_t inLen,
  55. Allocation* aout,
  56. const RsScriptCall* sc) override;
  57. void invokeInit() override;
  58. void invokeFreeChildren() override;
  59. void setGlobalVar(uint32_t slot, const void *data, size_t dataLength) override;
  60. void getGlobalVar(uint32_t slot, void *data, size_t dataLength) override;
  61. void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength,
  62. const Element *e, const uint32_t *dims,
  63. size_t dimLength) override;
  64. void setGlobalBind(uint32_t slot, Allocation *data) override;
  65. void setGlobalObj(uint32_t slot, ObjectBase *data) override;
  66. const char* getFieldName(uint32_t slot) const;
  67. ~RsdCpuScriptImpl() override;
  68. RsdCpuScriptImpl(RsdCpuReferenceImpl *ctx, const Script *s);
  69. const Script * getScript() {return mScript;}
  70. bool forEachMtlsSetup(const Allocation ** ains, uint32_t inLen,
  71. Allocation * aout, const void * usr, uint32_t usrLen,
  72. const RsScriptCall *sc, MTLaunchStructForEach *mtls);
  73. virtual void forEachKernelSetup(uint32_t slot, MTLaunchStructForEach *mtls);
  74. // Build an MTLaunchStruct suitable for launching a general reduce-style kernel.
  75. bool reduceMtlsSetup(const Allocation ** ains, uint32_t inLen, const Allocation *aout,
  76. const RsScriptCall *sc, MTLaunchStructReduce *mtls);
  77. // Finalize an MTLaunchStruct for launching a general reduce-style kernel.
  78. virtual void reduceKernelSetup(uint32_t slot, MTLaunchStructReduce *mtls);
  79. const RsdCpuReference::CpuSymbol * lookupSymbolMath(const char *sym);
  80. static void * lookupRuntimeStub(void* pContext, char const* name);
  81. Allocation * getAllocationForPointer(const void *ptr) const override;
  82. bool storeRSInfoFromSO();
  83. int getGlobalEntries() const override;
  84. const char * getGlobalName(int i) const override;
  85. const void * getGlobalAddress(int i) const override;
  86. size_t getGlobalSize(int i) const override;
  87. uint32_t getGlobalProperties(int i) const override;
  88. protected:
  89. RsdCpuReferenceImpl *mCtx;
  90. const Script *mScript;
  91. void *mScriptSO;
  92. #ifndef RS_COMPATIBILITY_LIB
  93. // Returns the path to the core library we'll use.
  94. const char* findCoreLib(const bcinfo::MetadataExtractor& bitCodeMetaData, const char* bitcode,
  95. size_t bitcodeSize);
  96. #endif
  97. RootFunc_t mRoot;
  98. RootFunc_t mRootExpand;
  99. InitOrDtorFunc_t mInit;
  100. InitOrDtorFunc_t mFreeChildren;
  101. ScriptExecutable* mScriptExec;
  102. Allocation **mBoundAllocs;
  103. void * mIntrinsicData;
  104. bool mIsThreadable;
  105. public:
  106. static const char* BCC_EXE_PATH;
  107. const char* getBitcodeFilePath() const { return mBitcodeFilePath.c_str(); }
  108. private:
  109. bool setUpMtlsDimensions(MTLaunchStructCommon *mtls,
  110. const RsLaunchDimensions &baseDim,
  111. const RsScriptCall *sc);
  112. std::string mBitcodeFilePath;
  113. uint32_t mBuildChecksum;
  114. bool mChecksumNeeded;
  115. };
  116. Allocation * rsdScriptGetAllocationForPointer(
  117. const Context *dc,
  118. const Script *script,
  119. const void *);
  120. uint32_t constructBuildChecksum(uint8_t const *bitcode, size_t bitcodeSize,
  121. const char *commandLine,
  122. const char ** bccFiles, size_t numFiles);
  123. } // namespace renderscript
  124. #ifdef __LP64__
  125. #define SYSLIBPATH "/system/lib64"
  126. #define SYSLIBPATH_VNDK "/system/lib64/vndk-sp"
  127. #define SYSLIBPATH_BC "/system/lib64"
  128. #define SYSLIBPATH_VENDOR "/system/vendor/lib64"
  129. #elif defined(BUILD_ARM_FOR_X86) && defined(__arm__)
  130. #define SYSLIBPATH "/system/lib/arm"
  131. #define SYSLIBPATH_VNDK "/system/lib/arm/vndk-sp"
  132. #define SYSLIBPATH_BC "/system/lib"
  133. #define SYSLIBPATH_VENDOR "/system/vendor/lib/arm"
  134. #else
  135. #define SYSLIBPATH "/system/lib"
  136. #define SYSLIBPATH_VNDK "/system/lib/vndk-sp"
  137. #define SYSLIBPATH_BC "/system/lib"
  138. #define SYSLIBPATH_VENDOR "/system/vendor/lib"
  139. #endif
  140. } // namespace android
  141. namespace {
  142. inline bool is_force_recompile() {
  143. char buf[PROP_VALUE_MAX];
  144. // Re-compile if floating point precision has been overridden.
  145. android::renderscript::property_get("debug.rs.precision", buf, "");
  146. if (buf[0] != '\0') {
  147. return true;
  148. }
  149. // Re-compile if debug.rs.forcerecompile is set.
  150. android::renderscript::property_get("debug.rs.forcerecompile", buf, "0");
  151. if ((::strcmp(buf, "1") == 0) || (::strcmp(buf, "true") == 0)) {
  152. return true;
  153. } else {
  154. return false;
  155. }
  156. }
  157. inline std::string getVndkSysLibPath() {
  158. char buf[PROP_VALUE_MAX];
  159. android::renderscript::property_get("ro.vndk.version", buf, "");
  160. std::string versionStr = buf;
  161. if (versionStr != "" && versionStr != "current") {
  162. return SYSLIBPATH_VNDK "-" + versionStr;
  163. }
  164. return SYSLIBPATH_VNDK;
  165. }
  166. } // anonymous namespace
  167. #endif // RSD_CPU_SCRIPT_H