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 | 1d47662 | 2013-03-29 22:08:49 -0700 | [diff] [blame] | 22 | typedef const char* (*RSSelectRTCallback) (const char*, size_t); |
Stephen Hines | b7d9c80 | 2013-04-29 19:13:09 -0700 | [diff] [blame] | 23 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 24 | namespace android { |
| 25 | namespace renderscript { |
| 26 | |
| 27 | class ScriptC; |
| 28 | class Script; |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 29 | class ScriptGroupBase; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 30 | class ScriptKernelID; |
| 31 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 32 | class RsdCpuReference { |
| 33 | public: |
| 34 | struct CpuSymbol { |
| 35 | const char * name; |
| 36 | void * fnPtr; |
| 37 | bool threadable; |
| 38 | }; |
| 39 | |
| 40 | typedef const CpuSymbol * (* sym_lookup_t)(Context *, const char *name); |
| 41 | |
| 42 | struct CpuTls { |
| 43 | Context *rsc; |
| 44 | const ScriptC * sc; |
| 45 | }; |
| 46 | |
| 47 | class CpuScript { |
| 48 | public: |
| 49 | virtual void populateScript(Script *) = 0; |
| 50 | virtual void invokeFunction(uint32_t slot, const void *params, size_t paramLength) = 0; |
| 51 | virtual int invokeRoot() = 0; |
Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 52 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 53 | virtual void invokeForEach(uint32_t slot, |
Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 54 | const Allocation ** ains, |
| 55 | uint32_t inLen, |
| 56 | Allocation * aout, |
| 57 | const void * usr, |
| 58 | uint32_t usrLen, |
| 59 | const RsScriptCall *sc) = 0; |
| 60 | |
Matt Wala | 14ce007 | 2015-07-30 17:30:25 -0700 | [diff] [blame] | 61 | virtual void invokeReduce(uint32_t slot, |
| 62 | const Allocation *ain, |
| 63 | Allocation *aout, |
| 64 | const RsScriptCall *sc) = 0; |
| 65 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 66 | virtual void invokeInit() = 0; |
| 67 | virtual void invokeFreeChildren() = 0; |
| 68 | |
| 69 | 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] | 70 | virtual void getGlobalVar(uint32_t slot, void *data, size_t dataLength) = 0; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 71 | virtual void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength, |
Stephen Hines | ac8d146 | 2014-06-25 00:01:23 -0700 | [diff] [blame] | 72 | const Element *e, const uint32_t *dims, size_t dimLength) = 0; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 73 | virtual void setGlobalBind(uint32_t slot, Allocation *data) = 0; |
| 74 | virtual void setGlobalObj(uint32_t slot, ObjectBase *obj) = 0; |
| 75 | |
| 76 | virtual Allocation * getAllocationForPointer(const void *ptr) const = 0; |
Stephen Hines | 8409d64 | 2015-04-28 18:49:56 -0700 | [diff] [blame] | 77 | |
| 78 | // Returns number of global variables in this Script (may be 0 if |
| 79 | // compiler is not configured to emit this information). |
| 80 | virtual int getGlobalEntries() const = 0; |
| 81 | // Returns the name of the global variable at index i. |
| 82 | virtual const char * getGlobalName(int i) const = 0; |
| 83 | // Returns the CPU address of the global variable at index i. |
| 84 | virtual const void * getGlobalAddress(int i) const = 0; |
| 85 | // Returns the size (in bytes) of the global variable at index i. |
| 86 | virtual size_t getGlobalSize(int i) const = 0; |
Stephen Hines | 5aa018c | 2015-05-20 18:09:57 -0700 | [diff] [blame] | 87 | // Returns the properties of the global variable at index i. |
| 88 | virtual uint32_t getGlobalProperties(int i) const = 0; |
Stephen Hines | 8409d64 | 2015-04-28 18:49:56 -0700 | [diff] [blame] | 89 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 90 | virtual ~CpuScript() {} |
| 91 | }; |
| 92 | typedef CpuScript * (* script_lookup_t)(Context *, const Script *s); |
| 93 | |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 94 | class CpuScriptGroupBase { |
| 95 | public: |
| 96 | virtual void execute() = 0; |
| 97 | virtual ~CpuScriptGroupBase() {} |
| 98 | }; |
| 99 | |
| 100 | class CpuScriptGroup : public CpuScriptGroupBase { |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 101 | public: |
| 102 | virtual void setInput(const ScriptKernelID *kid, Allocation *) = 0; |
| 103 | virtual void setOutput(const ScriptKernelID *kid, Allocation *) = 0; |
Stephen Hines | c060f14 | 2015-05-13 19:26:09 -0700 | [diff] [blame] | 104 | ~CpuScriptGroup() override {}; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 105 | }; |
| 106 | |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 107 | class CpuScriptGroup2 : public CpuScriptGroupBase { |
| 108 | public: |
Stephen Hines | c060f14 | 2015-05-13 19:26:09 -0700 | [diff] [blame] | 109 | ~CpuScriptGroup2() override {} |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 110 | }; |
| 111 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 112 | static Context * getTlsContext(); |
| 113 | static const Script * getTlsScript(); |
Stephen Hines | f218bf1 | 2013-02-12 19:32:38 -0800 | [diff] [blame] | 114 | static pthread_key_t getThreadTLSKey(); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 115 | |
| 116 | static RsdCpuReference * create(Context *c, uint32_t version_major, |
Jason Sams | cadfac4 | 2013-03-06 18:09:08 -0800 | [diff] [blame] | 117 | uint32_t version_minor, sym_lookup_t lfn, script_lookup_t slfn |
David Gross | b043df0 | 2015-05-29 11:38:15 -0700 | [diff] [blame] | 118 | , RSSelectRTCallback pSelectRTCallback = nullptr, |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 119 | const char *pBccPluginName = nullptr |
Jason Sams | cadfac4 | 2013-03-06 18:09:08 -0800 | [diff] [blame] | 120 | ); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 121 | virtual ~RsdCpuReference(); |
| 122 | virtual void setPriority(int32_t priority) = 0; |
| 123 | |
| 124 | virtual CpuScript * createScript(const ScriptC *s, char const *resName, char const *cacheDir, |
| 125 | uint8_t const *bitcode, size_t bitcodeSize, |
| 126 | uint32_t flags) = 0; |
| 127 | virtual CpuScript * createIntrinsic(const Script *s, RsScriptIntrinsicID iid, Element *e) = 0; |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 128 | virtual void* createScriptGroup(const ScriptGroupBase *sg) = 0; |
Stephen Hines | f218bf1 | 2013-02-12 19:32:38 -0800 | [diff] [blame] | 129 | virtual bool getInForEach() = 0; |
| 130 | |
Pirama Arumuga Nainar | 5cb19fd | 2015-05-12 11:06:58 -0700 | [diff] [blame] | 131 | // Set to true if we should embed global variable information in the code. |
| 132 | virtual void setEmbedGlobalInfo(bool v) = 0; |
| 133 | |
| 134 | // Returns true if we should embed global variable information in the code. |
| 135 | virtual bool getEmbedGlobalInfo() const = 0; |
| 136 | |
| 137 | // Set to true if we should skip constant (immutable) global variables when |
| 138 | // potentially embedding information about globals. |
| 139 | virtual void setEmbedGlobalInfoSkipConstant(bool v) = 0; |
| 140 | |
| 141 | // Returns true if we should skip constant (immutable) global variables when |
| 142 | // potentially embedding information about globals. |
| 143 | virtual bool getEmbedGlobalInfoSkipConstant() const = 0; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | #endif |