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