Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 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_H |
| 18 | #define RSD_CPU_H |
| 19 | |
| 20 | #include "rsAllocation.h" |
| 21 | |
Stephen Hines | f218bf1 | 2013-02-12 19:32:38 -0800 | [diff] [blame] | 22 | namespace llvm { |
| 23 | |
| 24 | class Module; |
| 25 | |
| 26 | } // end namespace llvm |
| 27 | |
| 28 | namespace bcc { |
| 29 | |
Stephen Hines | b7d9c80 | 2013-04-29 19:13:09 -0700 | [diff] [blame] | 30 | class RSCompilerDriver; |
Stephen Hines | f218bf1 | 2013-02-12 19:32:38 -0800 | [diff] [blame] | 31 | class RSScript; |
Stephen Hines | b7d9c80 | 2013-04-29 19:13:09 -0700 | [diff] [blame] | 32 | typedef llvm::Module* (*RSLinkRuntimeCallback) |
| 33 | (bcc::RSScript *, llvm::Module *, llvm::Module *); |
Stephen Hines | f218bf1 | 2013-02-12 19:32:38 -0800 | [diff] [blame] | 34 | |
| 35 | } // end namespace bcc; |
Stephen Hines | 1d47662 | 2013-03-29 22:08:49 -0700 | [diff] [blame] | 36 | |
| 37 | typedef const char* (*RSSelectRTCallback) (const char*, size_t); |
Stephen Hines | b7d9c80 | 2013-04-29 19:13:09 -0700 | [diff] [blame] | 38 | |
| 39 | typedef void (*RSSetupCompilerCallback) (bcc::RSCompilerDriver *); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 40 | |
| 41 | namespace android { |
| 42 | namespace renderscript { |
| 43 | |
| 44 | class ScriptC; |
| 45 | class Script; |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 46 | class ScriptGroupBase; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 47 | class ScriptKernelID; |
| 48 | |
| 49 | |
| 50 | class RsdCpuReference { |
| 51 | public: |
| 52 | struct CpuSymbol { |
| 53 | const char * name; |
| 54 | void * fnPtr; |
| 55 | bool threadable; |
| 56 | }; |
| 57 | |
| 58 | typedef const CpuSymbol * (* sym_lookup_t)(Context *, const char *name); |
| 59 | |
| 60 | struct CpuTls { |
| 61 | Context *rsc; |
| 62 | const ScriptC * sc; |
| 63 | }; |
| 64 | |
| 65 | class CpuScript { |
| 66 | public: |
| 67 | virtual void populateScript(Script *) = 0; |
| 68 | virtual void invokeFunction(uint32_t slot, const void *params, size_t paramLength) = 0; |
| 69 | virtual int invokeRoot() = 0; |
Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 70 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 71 | virtual void invokeForEach(uint32_t slot, |
Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 72 | const Allocation ** ains, |
| 73 | uint32_t inLen, |
| 74 | Allocation * aout, |
| 75 | const void * usr, |
| 76 | uint32_t usrLen, |
| 77 | const RsScriptCall *sc) = 0; |
| 78 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 79 | virtual void invokeInit() = 0; |
| 80 | virtual void invokeFreeChildren() = 0; |
| 81 | |
| 82 | virtual void setGlobalVar(uint32_t slot, const void *data, size_t dataLength) = 0; |
Tim Murray | 9c64239 | 2013-04-11 13:29:59 -0700 | [diff] [blame] | 83 | virtual void getGlobalVar(uint32_t slot, void *data, size_t dataLength) = 0; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 84 | virtual void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength, |
Stephen Hines | ac8d146 | 2014-06-25 00:01:23 -0700 | [diff] [blame] | 85 | const Element *e, const uint32_t *dims, size_t dimLength) = 0; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 86 | virtual void setGlobalBind(uint32_t slot, Allocation *data) = 0; |
| 87 | virtual void setGlobalObj(uint32_t slot, ObjectBase *obj) = 0; |
| 88 | |
| 89 | virtual Allocation * getAllocationForPointer(const void *ptr) const = 0; |
| 90 | virtual ~CpuScript() {} |
Stephen Hines | f218bf1 | 2013-02-12 19:32:38 -0800 | [diff] [blame] | 91 | |
Jason Sams | cadfac4 | 2013-03-06 18:09:08 -0800 | [diff] [blame] | 92 | #ifndef RS_COMPATIBILITY_LIB |
Stephen Hines | f218bf1 | 2013-02-12 19:32:38 -0800 | [diff] [blame] | 93 | virtual void * getRSExecutable() = 0; |
Jason Sams | cadfac4 | 2013-03-06 18:09:08 -0800 | [diff] [blame] | 94 | #endif |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 95 | }; |
| 96 | typedef CpuScript * (* script_lookup_t)(Context *, const Script *s); |
| 97 | |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 98 | class CpuScriptGroupBase { |
| 99 | public: |
| 100 | virtual void execute() = 0; |
| 101 | virtual ~CpuScriptGroupBase() {} |
| 102 | }; |
| 103 | |
| 104 | class CpuScriptGroup : public CpuScriptGroupBase { |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 105 | public: |
| 106 | virtual void setInput(const ScriptKernelID *kid, Allocation *) = 0; |
| 107 | virtual void setOutput(const ScriptKernelID *kid, Allocation *) = 0; |
| 108 | virtual void execute() = 0; |
| 109 | virtual ~CpuScriptGroup() {}; |
| 110 | }; |
| 111 | |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 112 | class CpuScriptGroup2 : public CpuScriptGroupBase { |
| 113 | public: |
| 114 | virtual void execute() = 0; |
| 115 | virtual ~CpuScriptGroup2() {} |
| 116 | }; |
| 117 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 118 | static Context * getTlsContext(); |
| 119 | static const Script * getTlsScript(); |
Stephen Hines | f218bf1 | 2013-02-12 19:32:38 -0800 | [diff] [blame] | 120 | static pthread_key_t getThreadTLSKey(); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 121 | |
| 122 | static RsdCpuReference * create(Context *c, uint32_t version_major, |
Jason Sams | cadfac4 | 2013-03-06 18:09:08 -0800 | [diff] [blame] | 123 | uint32_t version_minor, sym_lookup_t lfn, script_lookup_t slfn |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 124 | , bcc::RSLinkRuntimeCallback pLinkRuntimeCallback = nullptr, |
| 125 | RSSelectRTCallback pSelectRTCallback = nullptr, |
| 126 | const char *pBccPluginName = nullptr |
Jason Sams | cadfac4 | 2013-03-06 18:09:08 -0800 | [diff] [blame] | 127 | ); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 128 | virtual ~RsdCpuReference(); |
| 129 | virtual void setPriority(int32_t priority) = 0; |
| 130 | |
| 131 | virtual CpuScript * createScript(const ScriptC *s, char const *resName, char const *cacheDir, |
| 132 | uint8_t const *bitcode, size_t bitcodeSize, |
| 133 | uint32_t flags) = 0; |
| 134 | virtual CpuScript * createIntrinsic(const Script *s, RsScriptIntrinsicID iid, Element *e) = 0; |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 135 | virtual void* createScriptGroup(const ScriptGroupBase *sg) = 0; |
Stephen Hines | f218bf1 | 2013-02-12 19:32:38 -0800 | [diff] [blame] | 136 | virtual bool getInForEach() = 0; |
| 137 | |
Stephen Hines | b7d9c80 | 2013-04-29 19:13:09 -0700 | [diff] [blame] | 138 | #ifndef RS_COMPATIBILITY_LIB |
| 139 | virtual void setSetupCompilerCallback( |
| 140 | RSSetupCompilerCallback pSetupCompilerCallback) = 0; |
| 141 | virtual RSSetupCompilerCallback getSetupCompilerCallback() const = 0; |
| 142 | #endif |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | #endif |