1709a0978ae141198018ca9769f8d96292a8928e6Jason Sams/* 2709a0978ae141198018ca9769f8d96292a8928e6Jason Sams * Copyright (C) 2012 The Android Open Source Project 3709a0978ae141198018ca9769f8d96292a8928e6Jason Sams * 4709a0978ae141198018ca9769f8d96292a8928e6Jason Sams * Licensed under the Apache License, Version 2.0 (the "License"); 5709a0978ae141198018ca9769f8d96292a8928e6Jason Sams * you may not use this file except in compliance with the License. 6709a0978ae141198018ca9769f8d96292a8928e6Jason Sams * You may obtain a copy of the License at 7709a0978ae141198018ca9769f8d96292a8928e6Jason Sams * 8709a0978ae141198018ca9769f8d96292a8928e6Jason Sams * http://www.apache.org/licenses/LICENSE-2.0 9709a0978ae141198018ca9769f8d96292a8928e6Jason Sams * 10709a0978ae141198018ca9769f8d96292a8928e6Jason Sams * Unless required by applicable law or agreed to in writing, software 11709a0978ae141198018ca9769f8d96292a8928e6Jason Sams * distributed under the License is distributed on an "AS IS" BASIS, 12709a0978ae141198018ca9769f8d96292a8928e6Jason Sams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13709a0978ae141198018ca9769f8d96292a8928e6Jason Sams * See the License for the specific language governing permissions and 14709a0978ae141198018ca9769f8d96292a8928e6Jason Sams * limitations under the License. 15709a0978ae141198018ca9769f8d96292a8928e6Jason Sams */ 16709a0978ae141198018ca9769f8d96292a8928e6Jason Sams 17709a0978ae141198018ca9769f8d96292a8928e6Jason Sams#ifndef RSD_CPU_H 18709a0978ae141198018ca9769f8d96292a8928e6Jason Sams#define RSD_CPU_H 19709a0978ae141198018ca9769f8d96292a8928e6Jason Sams 20709a0978ae141198018ca9769f8d96292a8928e6Jason Sams#include "rsAllocation.h" 21709a0978ae141198018ca9769f8d96292a8928e6Jason Sams 22f218bf115af4ae4fd79adbb8842608b308a4cf07Stephen Hinesnamespace llvm { 23f218bf115af4ae4fd79adbb8842608b308a4cf07Stephen Hines 24f218bf115af4ae4fd79adbb8842608b308a4cf07Stephen Hinesclass Module; 25f218bf115af4ae4fd79adbb8842608b308a4cf07Stephen Hines 26f218bf115af4ae4fd79adbb8842608b308a4cf07Stephen Hines} // end namespace llvm 27f218bf115af4ae4fd79adbb8842608b308a4cf07Stephen Hines 28f218bf115af4ae4fd79adbb8842608b308a4cf07Stephen Hinesnamespace bcc { 29f218bf115af4ae4fd79adbb8842608b308a4cf07Stephen Hines 30b7d9c80c98fc96aa7c638e3124be24f13a6436b2Stephen Hinesclass RSCompilerDriver; 31f218bf115af4ae4fd79adbb8842608b308a4cf07Stephen Hinesclass RSScript; 32b7d9c80c98fc96aa7c638e3124be24f13a6436b2Stephen Hinestypedef llvm::Module* (*RSLinkRuntimeCallback) 33b7d9c80c98fc96aa7c638e3124be24f13a6436b2Stephen Hines (bcc::RSScript *, llvm::Module *, llvm::Module *); 34f218bf115af4ae4fd79adbb8842608b308a4cf07Stephen Hines 35f218bf115af4ae4fd79adbb8842608b308a4cf07Stephen Hines} // end namespace bcc; 361d476620399d54774e4fd386c1d23cc583d49522Stephen Hines 371d476620399d54774e4fd386c1d23cc583d49522Stephen Hinestypedef const char* (*RSSelectRTCallback) (const char*, size_t); 38b7d9c80c98fc96aa7c638e3124be24f13a6436b2Stephen Hines 39b7d9c80c98fc96aa7c638e3124be24f13a6436b2Stephen Hinestypedef void (*RSSetupCompilerCallback) (bcc::RSCompilerDriver *); 40709a0978ae141198018ca9769f8d96292a8928e6Jason Sams 41709a0978ae141198018ca9769f8d96292a8928e6Jason Samsnamespace android { 42709a0978ae141198018ca9769f8d96292a8928e6Jason Samsnamespace renderscript { 43709a0978ae141198018ca9769f8d96292a8928e6Jason Sams 44709a0978ae141198018ca9769f8d96292a8928e6Jason Samsclass ScriptC; 45709a0978ae141198018ca9769f8d96292a8928e6Jason Samsclass Script; 461ffd86b448d78366190c540f98f8b6d641cdb6cfYang Niclass ScriptGroupBase; 47709a0978ae141198018ca9769f8d96292a8928e6Jason Samsclass ScriptKernelID; 48709a0978ae141198018ca9769f8d96292a8928e6Jason Sams 49709a0978ae141198018ca9769f8d96292a8928e6Jason Sams 50709a0978ae141198018ca9769f8d96292a8928e6Jason Samsclass RsdCpuReference { 51709a0978ae141198018ca9769f8d96292a8928e6Jason Samspublic: 52709a0978ae141198018ca9769f8d96292a8928e6Jason Sams struct CpuSymbol { 53709a0978ae141198018ca9769f8d96292a8928e6Jason Sams const char * name; 54709a0978ae141198018ca9769f8d96292a8928e6Jason Sams void * fnPtr; 55709a0978ae141198018ca9769f8d96292a8928e6Jason Sams bool threadable; 56709a0978ae141198018ca9769f8d96292a8928e6Jason Sams }; 57709a0978ae141198018ca9769f8d96292a8928e6Jason Sams 58709a0978ae141198018ca9769f8d96292a8928e6Jason Sams typedef const CpuSymbol * (* sym_lookup_t)(Context *, const char *name); 59709a0978ae141198018ca9769f8d96292a8928e6Jason Sams 60709a0978ae141198018ca9769f8d96292a8928e6Jason Sams struct CpuTls { 61709a0978ae141198018ca9769f8d96292a8928e6Jason Sams Context *rsc; 62709a0978ae141198018ca9769f8d96292a8928e6Jason Sams const ScriptC * sc; 63709a0978ae141198018ca9769f8d96292a8928e6Jason Sams }; 64709a0978ae141198018ca9769f8d96292a8928e6Jason Sams 65709a0978ae141198018ca9769f8d96292a8928e6Jason Sams class CpuScript { 66709a0978ae141198018ca9769f8d96292a8928e6Jason Sams public: 67709a0978ae141198018ca9769f8d96292a8928e6Jason Sams virtual void populateScript(Script *) = 0; 68709a0978ae141198018ca9769f8d96292a8928e6Jason Sams virtual void invokeFunction(uint32_t slot, const void *params, size_t paramLength) = 0; 69709a0978ae141198018ca9769f8d96292a8928e6Jason Sams virtual int invokeRoot() = 0; 70f37121300217d3b39ab66dd9c8881bcbcad932dfChris Wailes 71709a0978ae141198018ca9769f8d96292a8928e6Jason Sams virtual void invokeForEach(uint32_t slot, 72f37121300217d3b39ab66dd9c8881bcbcad932dfChris Wailes const Allocation ** ains, 73f37121300217d3b39ab66dd9c8881bcbcad932dfChris Wailes uint32_t inLen, 74f37121300217d3b39ab66dd9c8881bcbcad932dfChris Wailes Allocation * aout, 75f37121300217d3b39ab66dd9c8881bcbcad932dfChris Wailes const void * usr, 76f37121300217d3b39ab66dd9c8881bcbcad932dfChris Wailes uint32_t usrLen, 77f37121300217d3b39ab66dd9c8881bcbcad932dfChris Wailes const RsScriptCall *sc) = 0; 78f37121300217d3b39ab66dd9c8881bcbcad932dfChris Wailes 79709a0978ae141198018ca9769f8d96292a8928e6Jason Sams virtual void invokeInit() = 0; 80709a0978ae141198018ca9769f8d96292a8928e6Jason Sams virtual void invokeFreeChildren() = 0; 81709a0978ae141198018ca9769f8d96292a8928e6Jason Sams 82709a0978ae141198018ca9769f8d96292a8928e6Jason Sams virtual void setGlobalVar(uint32_t slot, const void *data, size_t dataLength) = 0; 839c64239ebbfa4170190ede812e69150035e008e0Tim Murray virtual void getGlobalVar(uint32_t slot, void *data, size_t dataLength) = 0; 84709a0978ae141198018ca9769f8d96292a8928e6Jason Sams virtual void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength, 85ac8d146a41f18afad5314ac8af440d6aedbe20bfStephen Hines const Element *e, const uint32_t *dims, size_t dimLength) = 0; 86709a0978ae141198018ca9769f8d96292a8928e6Jason Sams virtual void setGlobalBind(uint32_t slot, Allocation *data) = 0; 87709a0978ae141198018ca9769f8d96292a8928e6Jason Sams virtual void setGlobalObj(uint32_t slot, ObjectBase *obj) = 0; 88709a0978ae141198018ca9769f8d96292a8928e6Jason Sams 89709a0978ae141198018ca9769f8d96292a8928e6Jason Sams virtual Allocation * getAllocationForPointer(const void *ptr) const = 0; 90a874c96bef8428131b83345dd92f37d8ce246d4eStephen Hines 91a874c96bef8428131b83345dd92f37d8ce246d4eStephen Hines // Returns number of global variables in this Script (may be 0 if 92a874c96bef8428131b83345dd92f37d8ce246d4eStephen Hines // compiler is not configured to emit this information). 93a874c96bef8428131b83345dd92f37d8ce246d4eStephen Hines virtual int getGlobalEntries() const = 0; 94a874c96bef8428131b83345dd92f37d8ce246d4eStephen Hines // Returns the name of the global variable at index i. 95a874c96bef8428131b83345dd92f37d8ce246d4eStephen Hines virtual const char * getGlobalName(int i) const = 0; 96a874c96bef8428131b83345dd92f37d8ce246d4eStephen Hines // Returns the CPU address of the global variable at index i. 97a874c96bef8428131b83345dd92f37d8ce246d4eStephen Hines virtual const void * getGlobalAddress(int i) const = 0; 98a874c96bef8428131b83345dd92f37d8ce246d4eStephen Hines // Returns the size (in bytes) of the global variable at index i. 99a874c96bef8428131b83345dd92f37d8ce246d4eStephen Hines virtual size_t getGlobalSize(int i) const = 0; 1000e5d9f637a9ed4207582edb51e200912d8bf54cbStephen Hines // Returns the properties of the global variable at index i. 1010e5d9f637a9ed4207582edb51e200912d8bf54cbStephen Hines virtual uint32_t getGlobalProperties(int i) const = 0; 102a874c96bef8428131b83345dd92f37d8ce246d4eStephen Hines 103709a0978ae141198018ca9769f8d96292a8928e6Jason Sams virtual ~CpuScript() {} 104709a0978ae141198018ca9769f8d96292a8928e6Jason Sams }; 105709a0978ae141198018ca9769f8d96292a8928e6Jason Sams typedef CpuScript * (* script_lookup_t)(Context *, const Script *s); 106709a0978ae141198018ca9769f8d96292a8928e6Jason Sams 1071ffd86b448d78366190c540f98f8b6d641cdb6cfYang Ni class CpuScriptGroupBase { 1081ffd86b448d78366190c540f98f8b6d641cdb6cfYang Ni public: 1091ffd86b448d78366190c540f98f8b6d641cdb6cfYang Ni virtual void execute() = 0; 1101ffd86b448d78366190c540f98f8b6d641cdb6cfYang Ni virtual ~CpuScriptGroupBase() {} 1111ffd86b448d78366190c540f98f8b6d641cdb6cfYang Ni }; 1121ffd86b448d78366190c540f98f8b6d641cdb6cfYang Ni 1131ffd86b448d78366190c540f98f8b6d641cdb6cfYang Ni class CpuScriptGroup : public CpuScriptGroupBase { 114709a0978ae141198018ca9769f8d96292a8928e6Jason Sams public: 115709a0978ae141198018ca9769f8d96292a8928e6Jason Sams virtual void setInput(const ScriptKernelID *kid, Allocation *) = 0; 116709a0978ae141198018ca9769f8d96292a8928e6Jason Sams virtual void setOutput(const ScriptKernelID *kid, Allocation *) = 0; 117a66bf6ae6b8dc17f445090ebefd3c6cf9f4685c0Stephen Hines ~CpuScriptGroup() override {}; 118709a0978ae141198018ca9769f8d96292a8928e6Jason Sams }; 119709a0978ae141198018ca9769f8d96292a8928e6Jason Sams 1201ffd86b448d78366190c540f98f8b6d641cdb6cfYang Ni class CpuScriptGroup2 : public CpuScriptGroupBase { 1211ffd86b448d78366190c540f98f8b6d641cdb6cfYang Ni public: 122a66bf6ae6b8dc17f445090ebefd3c6cf9f4685c0Stephen Hines ~CpuScriptGroup2() override {} 1231ffd86b448d78366190c540f98f8b6d641cdb6cfYang Ni }; 1241ffd86b448d78366190c540f98f8b6d641cdb6cfYang Ni 125709a0978ae141198018ca9769f8d96292a8928e6Jason Sams static Context * getTlsContext(); 126709a0978ae141198018ca9769f8d96292a8928e6Jason Sams static const Script * getTlsScript(); 127f218bf115af4ae4fd79adbb8842608b308a4cf07Stephen Hines static pthread_key_t getThreadTLSKey(); 128709a0978ae141198018ca9769f8d96292a8928e6Jason Sams 129709a0978ae141198018ca9769f8d96292a8928e6Jason Sams static RsdCpuReference * create(Context *c, uint32_t version_major, 130cadfac411e6690e39de36c4f9e94deb9b7d2d08eJason Sams uint32_t version_minor, sym_lookup_t lfn, script_lookup_t slfn 13144bef6fba6244292b751387f3d6c31cca96c28adChris Wailes , bcc::RSLinkRuntimeCallback pLinkRuntimeCallback = nullptr, 13244bef6fba6244292b751387f3d6c31cca96c28adChris Wailes RSSelectRTCallback pSelectRTCallback = nullptr, 13344bef6fba6244292b751387f3d6c31cca96c28adChris Wailes const char *pBccPluginName = nullptr 134cadfac411e6690e39de36c4f9e94deb9b7d2d08eJason Sams ); 135709a0978ae141198018ca9769f8d96292a8928e6Jason Sams virtual ~RsdCpuReference(); 136709a0978ae141198018ca9769f8d96292a8928e6Jason Sams virtual void setPriority(int32_t priority) = 0; 137709a0978ae141198018ca9769f8d96292a8928e6Jason Sams 138709a0978ae141198018ca9769f8d96292a8928e6Jason Sams virtual CpuScript * createScript(const ScriptC *s, char const *resName, char const *cacheDir, 139709a0978ae141198018ca9769f8d96292a8928e6Jason Sams uint8_t const *bitcode, size_t bitcodeSize, 140709a0978ae141198018ca9769f8d96292a8928e6Jason Sams uint32_t flags) = 0; 141709a0978ae141198018ca9769f8d96292a8928e6Jason Sams virtual CpuScript * createIntrinsic(const Script *s, RsScriptIntrinsicID iid, Element *e) = 0; 1421ffd86b448d78366190c540f98f8b6d641cdb6cfYang Ni virtual void* createScriptGroup(const ScriptGroupBase *sg) = 0; 143f218bf115af4ae4fd79adbb8842608b308a4cf07Stephen Hines virtual bool getInForEach() = 0; 144f218bf115af4ae4fd79adbb8842608b308a4cf07Stephen Hines 145b7d9c80c98fc96aa7c638e3124be24f13a6436b2Stephen Hines#ifndef RS_COMPATIBILITY_LIB 146b7d9c80c98fc96aa7c638e3124be24f13a6436b2Stephen Hines virtual void setSetupCompilerCallback( 147b7d9c80c98fc96aa7c638e3124be24f13a6436b2Stephen Hines RSSetupCompilerCallback pSetupCompilerCallback) = 0; 148b7d9c80c98fc96aa7c638e3124be24f13a6436b2Stephen Hines virtual RSSetupCompilerCallback getSetupCompilerCallback() const = 0; 149b7d9c80c98fc96aa7c638e3124be24f13a6436b2Stephen Hines#endif 150160622bf1ea33f56e6b2b02591a1301e223ed54ePirama Arumuga Nainar 151160622bf1ea33f56e6b2b02591a1301e223ed54ePirama Arumuga Nainar // Set to true if we should embed global variable information in the code. 152160622bf1ea33f56e6b2b02591a1301e223ed54ePirama Arumuga Nainar virtual void setEmbedGlobalInfo(bool v) = 0; 153160622bf1ea33f56e6b2b02591a1301e223ed54ePirama Arumuga Nainar 154160622bf1ea33f56e6b2b02591a1301e223ed54ePirama Arumuga Nainar // Returns true if we should embed global variable information in the code. 155160622bf1ea33f56e6b2b02591a1301e223ed54ePirama Arumuga Nainar virtual bool getEmbedGlobalInfo() const = 0; 156160622bf1ea33f56e6b2b02591a1301e223ed54ePirama Arumuga Nainar 157160622bf1ea33f56e6b2b02591a1301e223ed54ePirama Arumuga Nainar // Set to true if we should skip constant (immutable) global variables when 158160622bf1ea33f56e6b2b02591a1301e223ed54ePirama Arumuga Nainar // potentially embedding information about globals. 159160622bf1ea33f56e6b2b02591a1301e223ed54ePirama Arumuga Nainar virtual void setEmbedGlobalInfoSkipConstant(bool v) = 0; 160160622bf1ea33f56e6b2b02591a1301e223ed54ePirama Arumuga Nainar 161160622bf1ea33f56e6b2b02591a1301e223ed54ePirama Arumuga Nainar // Returns true if we should skip constant (immutable) global variables when 162160622bf1ea33f56e6b2b02591a1301e223ed54ePirama Arumuga Nainar // potentially embedding information about globals. 163160622bf1ea33f56e6b2b02591a1301e223ed54ePirama Arumuga Nainar virtual bool getEmbedGlobalInfoSkipConstant() const = 0; 164709a0978ae141198018ca9769f8d96292a8928e6Jason Sams}; 165709a0978ae141198018ca9769f8d96292a8928e6Jason Sams 166709a0978ae141198018ca9769f8d96292a8928e6Jason Sams 167709a0978ae141198018ca9769f8d96292a8928e6Jason Sams} 168709a0978ae141198018ca9769f8d96292a8928e6Jason Sams} 169709a0978ae141198018ca9769f8d96292a8928e6Jason Sams 170709a0978ae141198018ca9769f8d96292a8928e6Jason Sams#endif 171