• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
22 typedef const char* (*RSSelectRTCallback) (const char*, size_t);
23 
24 namespace android {
25 namespace renderscript {
26 
27 class ScriptC;
28 class Script;
29 class ScriptGroupBase;
30 class ScriptKernelID;
31 
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;
52 
53         virtual void invokeForEach(uint32_t slot,
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 
61         virtual void invokeReduce(uint32_t slot,
62                                   const Allocation ** ains, uint32_t inLen,
63                                   Allocation *aout,
64                                   const RsScriptCall *sc) = 0;
65 
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;
70         virtual void getGlobalVar(uint32_t slot, void *data, size_t dataLength) = 0;
71         virtual void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength,
72                                       const Element *e, const uint32_t *dims, size_t dimLength) = 0;
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;
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;
87         // Returns the properties of the global variable at index i.
88         virtual uint32_t getGlobalProperties(int i) const = 0;
89 
~CpuScript()90         virtual ~CpuScript() {}
91     };
92     typedef CpuScript * (* script_lookup_t)(Context *, const Script *s);
93 
94     class CpuScriptGroupBase {
95      public:
96       virtual void execute() = 0;
~CpuScriptGroupBase()97       virtual ~CpuScriptGroupBase() {}
98     };
99 
100     class CpuScriptGroup : public CpuScriptGroupBase {
101     public:
102         virtual void setInput(const ScriptKernelID *kid, Allocation *) = 0;
103         virtual void setOutput(const ScriptKernelID *kid, Allocation *) = 0;
~CpuScriptGroup()104         ~CpuScriptGroup() override {};
105     };
106 
107     class CpuScriptGroup2 : public CpuScriptGroupBase {
108      public:
~CpuScriptGroup2()109       ~CpuScriptGroup2() override {}
110     };
111 
112     static Context * getTlsContext();
113     static const Script * getTlsScript();
114     static pthread_key_t getThreadTLSKey();
115 
116     static RsdCpuReference * create(Context *c, uint32_t version_major,
117                                     uint32_t version_minor, sym_lookup_t lfn, script_lookup_t slfn
118                                     , RSSelectRTCallback pSelectRTCallback = nullptr,
119                                     const char *pBccPluginName = nullptr
120                                     );
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;
128     virtual void* createScriptGroup(const ScriptGroupBase *sg) = 0;
129     virtual bool getInKernel() = 0;  // Is a parallel kernel execution underway?
130 
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;
144 };
145 
146 
147 }
148 }
149 
150 #endif
151