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