1709a0978ae141198018ca9769f8d96292a8928e6Jason Sams/*
2709a0978ae141198018ca9769f8d96292a8928e6Jason Sams * Copyright (C) 2012 The Android Open Source Project
3709a0978ae141198018ca9769f8d96292a8928e6Jason Sams *
4709a0978ae141198018ca9769f8d96292a8928e6Jason Sams * Licensed under the Apache License, Version 2.0 (the "License");
5709a0978ae141198018ca9769f8d96292a8928e6Jason Sams * you may not use this file except in compliance with the License.
6709a0978ae141198018ca9769f8d96292a8928e6Jason Sams * You may obtain a copy of the License at
7709a0978ae141198018ca9769f8d96292a8928e6Jason Sams *
8709a0978ae141198018ca9769f8d96292a8928e6Jason Sams *      http://www.apache.org/licenses/LICENSE-2.0
9709a0978ae141198018ca9769f8d96292a8928e6Jason Sams *
10709a0978ae141198018ca9769f8d96292a8928e6Jason Sams * Unless required by applicable law or agreed to in writing, software
11709a0978ae141198018ca9769f8d96292a8928e6Jason Sams * distributed under the License is distributed on an "AS IS" BASIS,
12709a0978ae141198018ca9769f8d96292a8928e6Jason Sams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13709a0978ae141198018ca9769f8d96292a8928e6Jason Sams * See the License for the specific language governing permissions and
14709a0978ae141198018ca9769f8d96292a8928e6Jason Sams * limitations under the License.
15709a0978ae141198018ca9769f8d96292a8928e6Jason Sams */
16709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
17709a0978ae141198018ca9769f8d96292a8928e6Jason Sams#ifndef RSD_CPU_CORE_H
18709a0978ae141198018ca9769f8d96292a8928e6Jason Sams#define RSD_CPU_CORE_H
19709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
20709a0978ae141198018ca9769f8d96292a8928e6Jason Sams#include "rsd_cpu.h"
21709a0978ae141198018ca9769f8d96292a8928e6Jason Sams#include "rsSignal.h"
22709a0978ae141198018ca9769f8d96292a8928e6Jason Sams#include "rsContext.h"
23c31585b8ca865bf2b35abc79c8a8ee42de27bee8Yang Ni#include "rsCppUtils.h"
24709a0978ae141198018ca9769f8d96292a8928e6Jason Sams#include "rsElement.h"
25709a0978ae141198018ca9769f8d96292a8928e6Jason Sams#include "rsScriptC.h"
26dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross#include "rsCpuCoreRuntime.h"
27709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
28709a0978ae141198018ca9769f8d96292a8928e6Jason Samsnamespace android {
29709a0978ae141198018ca9769f8d96292a8928e6Jason Samsnamespace renderscript {
30709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
3111fd9ec1ab8dfa7ae45c6edeea48dddc4633efeaMatt Wala// Whether the CPU we're running on supports SIMD instructions
32f5ef8df639ba6363aa5d546e57ce872d04144cb6Jason Samsextern bool gArchUseSIMD;
33709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
3414ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Wala// Function types found in RenderScript code
35ae2ec3febedfc29376b9104413fb4042028f1265David Grosstypedef void (*ReduceAccumulatorFunc_t)(const RsExpandKernelDriverInfo *info, uint32_t x1, uint32_t x2, uint8_t *accum);
36ae2ec3febedfc29376b9104413fb4042028f1265David Grosstypedef void (*ReduceCombinerFunc_t)(uint8_t *accum, const uint8_t *other);
37ae2ec3febedfc29376b9104413fb4042028f1265David Grosstypedef void (*ReduceInitializerFunc_t)(uint8_t *accum);
38ae2ec3febedfc29376b9104413fb4042028f1265David Grosstypedef void (*ReduceOutConverterFunc_t)(uint8_t *out, const uint8_t *accum);
3914ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Walatypedef void (*ForEachFunc_t)(const RsExpandKernelDriverInfo *info, uint32_t x1, uint32_t x2, uint32_t outStride);
4014ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Walatypedef void (*InvokeFunc_t)(void *params);
4114ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Walatypedef void (*InitOrDtorFunc_t)(void);
4214ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Walatypedef int  (*RootFunc_t)(void);
4314ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Wala
44ae2ec3febedfc29376b9104413fb4042028f1265David Grossstruct ReduceDescription {
45ae2ec3febedfc29376b9104413fb4042028f1265David Gross    ReduceAccumulatorFunc_t  accumFunc;  // expanded accumulator function
46ae2ec3febedfc29376b9104413fb4042028f1265David Gross    ReduceInitializerFunc_t  initFunc;   // user initializer function
47ae2ec3febedfc29376b9104413fb4042028f1265David Gross    ReduceCombinerFunc_t     combFunc;   // user combiner function
48ae2ec3febedfc29376b9104413fb4042028f1265David Gross    ReduceOutConverterFunc_t outFunc;    // user outconverter function
49ae2ec3febedfc29376b9104413fb4042028f1265David Gross    size_t                   accumSize;  // accumulator datum size, in bytes
506c1876bbef1b2c89975dce91230a168bd2d2ce4cDavid Gross};
516c1876bbef1b2c89975dce91230a168bd2d2ce4cDavid Gross
5214ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Wala// Internal driver callback used to execute a kernel
53709a0978ae141198018ca9769f8d96292a8928e6Jason Samstypedef void (*WorkerCallback_t)(void *usr, uint32_t idx);
54709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
55709a0978ae141198018ca9769f8d96292a8928e6Jason Samsclass RsdCpuScriptImpl;
56709a0978ae141198018ca9769f8d96292a8928e6Jason Samsclass RsdCpuReferenceImpl;
57709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
58f37121300217d3b39ab66dd9c8881bcbcad932dfChris Wailesstruct ScriptTLSStruct {
59709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    android::renderscript::Context * mContext;
60709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    const android::renderscript::Script * mScript;
61709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    RsdCpuScriptImpl *mImpl;
62f37121300217d3b39ab66dd9c8881bcbcad932dfChris Wailes};
63709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
6414ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Wala// MTLaunchStruct passes information about a multithreaded kernel launch.
6514ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Walastruct MTLaunchStructCommon {
6614ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Wala    RsdCpuReferenceImpl *rs;
67709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    RsdCpuScriptImpl *script;
68709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
69709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    uint32_t mSliceSize;
70709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    volatile int mSliceNum;
71709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    bool isThreadable;
72709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
7314ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Wala    // Boundary information about the launch
74bf2111d3b3de310932099514f06924e48fa1d7b2Jason Sams    RsLaunchDimensions start;
75bf2111d3b3de310932099514f06924e48fa1d7b2Jason Sams    RsLaunchDimensions end;
7614ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Wala    // Points to MTLaunchStructForEach::fep::dim or
77ae2ec3febedfc29376b9104413fb4042028f1265David Gross    // MTLaunchStructReduce::redp::dim.
7814ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Wala    RsLaunchDimensions *dimPtr;
7914ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Wala};
8014ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Wala
8114ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Walastruct MTLaunchStructForEach : public MTLaunchStructCommon {
8214ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Wala    // Driver info structure
8314ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Wala    RsExpandKernelDriverInfo fep;
8414ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Wala
8514ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Wala    ForEachFunc_t kernel;
8614ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Wala    const Allocation *ains[RS_KERNEL_INPUT_LIMIT];
8714ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Wala    Allocation *aout[RS_KERNEL_INPUT_LIMIT];
8814ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Wala};
8914ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Wala
9014ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Walastruct MTLaunchStructReduce : public MTLaunchStructCommon {
916c1876bbef1b2c89975dce91230a168bd2d2ce4cDavid Gross    // Driver info structure
926c1876bbef1b2c89975dce91230a168bd2d2ce4cDavid Gross    RsExpandKernelDriverInfo redp;
936c1876bbef1b2c89975dce91230a168bd2d2ce4cDavid Gross
946c1876bbef1b2c89975dce91230a168bd2d2ce4cDavid Gross    const Allocation *ains[RS_KERNEL_INPUT_LIMIT];
956c1876bbef1b2c89975dce91230a168bd2d2ce4cDavid Gross
96ae2ec3febedfc29376b9104413fb4042028f1265David Gross    ReduceAccumulatorFunc_t accumFunc;
97ae2ec3febedfc29376b9104413fb4042028f1265David Gross    ReduceInitializerFunc_t initFunc;
98ae2ec3febedfc29376b9104413fb4042028f1265David Gross    ReduceCombinerFunc_t combFunc;
99ae2ec3febedfc29376b9104413fb4042028f1265David Gross    ReduceOutConverterFunc_t outFunc;
1006c1876bbef1b2c89975dce91230a168bd2d2ce4cDavid Gross
1016c1876bbef1b2c89975dce91230a168bd2d2ce4cDavid Gross    size_t accumSize;  // accumulator datum size in bytes
10210adb0c2029f112b5738228617d5645f6ecea0c5David Gross
10310adb0c2029f112b5738228617d5645f6ecea0c5David Gross    size_t accumStride;  // stride between accumulators in accumAlloc (below)
10410adb0c2029f112b5738228617d5645f6ecea0c5David Gross
10510adb0c2029f112b5738228617d5645f6ecea0c5David Gross    // These fields are used for managing accumulator data items in a
10610adb0c2029f112b5738228617d5645f6ecea0c5David Gross    // multithreaded execution.
10710adb0c2029f112b5738228617d5645f6ecea0c5David Gross    //
10810adb0c2029f112b5738228617d5645f6ecea0c5David Gross    // Let the number of threads be N.
10910adb0c2029f112b5738228617d5645f6ecea0c5David Gross    // Let Outc be true iff there is an outconverter.
11010adb0c2029f112b5738228617d5645f6ecea0c5David Gross    //
11110adb0c2029f112b5738228617d5645f6ecea0c5David Gross    // accumAlloc is a pointer to a single allocation of (N - !Outc)
11210adb0c2029f112b5738228617d5645f6ecea0c5David Gross    // accumulators.  (If there is no outconverter, then the output
11310adb0c2029f112b5738228617d5645f6ecea0c5David Gross    // allocation acts as an accumulator.)  It is created at kernel
11410adb0c2029f112b5738228617d5645f6ecea0c5David Gross    // launch time.  Within that allocation, the distance between the
11510adb0c2029f112b5738228617d5645f6ecea0c5David Gross    // start of adjacent accumulators is accumStride bytes -- this
11610adb0c2029f112b5738228617d5645f6ecea0c5David Gross    // might be the same as accumSize, or it might be larger, if we
11710adb0c2029f112b5738228617d5645f6ecea0c5David Gross    // are attempting to avoid false sharing.
11810adb0c2029f112b5738228617d5645f6ecea0c5David Gross    //
11910adb0c2029f112b5738228617d5645f6ecea0c5David Gross    // accumCount is an atomic counter of how many accumulators have
12010adb0c2029f112b5738228617d5645f6ecea0c5David Gross    // been grabbed by threads.  It is initialized to zero at kernel
12110adb0c2029f112b5738228617d5645f6ecea0c5David Gross    // launch time.  See accumPtr for further description.
12210adb0c2029f112b5738228617d5645f6ecea0c5David Gross    //
12310adb0c2029f112b5738228617d5645f6ecea0c5David Gross    // accumPtr is pointer to an array of N pointers to accumulators.
12410adb0c2029f112b5738228617d5645f6ecea0c5David Gross    // The array is created at kernel launch time, and each element is
12510adb0c2029f112b5738228617d5645f6ecea0c5David Gross    // initialized to nullptr.  When a particular thread goes to work,
12610adb0c2029f112b5738228617d5645f6ecea0c5David Gross    // that thread obtains its accumulator from its entry in this
12710adb0c2029f112b5738228617d5645f6ecea0c5David Gross    // array.  If the entry is nullptr, that thread needs to obtain an
12810adb0c2029f112b5738228617d5645f6ecea0c5David Gross    // accumulator, and initialize its entry in the array accordingly.
12910adb0c2029f112b5738228617d5645f6ecea0c5David Gross    // It does so via atomic access (fetch-and-add) to accumCount.
13010adb0c2029f112b5738228617d5645f6ecea0c5David Gross    // - If Outc, then the fetched value is used as an index into
13110adb0c2029f112b5738228617d5645f6ecea0c5David Gross    //   accumAlloc.
13210adb0c2029f112b5738228617d5645f6ecea0c5David Gross    // - If !Outc, then
13310adb0c2029f112b5738228617d5645f6ecea0c5David Gross    //   - If the fetched value is zero, then this thread gets the
13410adb0c2029f112b5738228617d5645f6ecea0c5David Gross    //     output allocation for its accumulator.
13510adb0c2029f112b5738228617d5645f6ecea0c5David Gross    //   - If the fetched value is nonzero, then (fetched value - 1)
13610adb0c2029f112b5738228617d5645f6ecea0c5David Gross    //     is used as an index into accumAlloc.
13710adb0c2029f112b5738228617d5645f6ecea0c5David Gross    uint8_t *accumAlloc;
13810adb0c2029f112b5738228617d5645f6ecea0c5David Gross    uint8_t **accumPtr;
13910adb0c2029f112b5738228617d5645f6ecea0c5David Gross    uint32_t accumCount;
14010adb0c2029f112b5738228617d5645f6ecea0c5David Gross
14110adb0c2029f112b5738228617d5645f6ecea0c5David Gross    // Logging control
1426760f7ba7934ddd51938a8d0206fc41c2a7cb419David Gross    uint32_t logReduce;
1436c1876bbef1b2c89975dce91230a168bd2d2ce4cDavid Gross};
1446c1876bbef1b2c89975dce91230a168bd2d2ce4cDavid Gross
145709a0978ae141198018ca9769f8d96292a8928e6Jason Samsclass RsdCpuReferenceImpl : public RsdCpuReference {
146709a0978ae141198018ca9769f8d96292a8928e6Jason Samspublic:
147c060f1435e7b9405f3be8974417fa6f410f03753Stephen Hines    ~RsdCpuReferenceImpl() override;
148709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    RsdCpuReferenceImpl(Context *);
149709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
150709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    void lockMutex();
151709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    void unlockMutex();
152709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
153709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    bool init(uint32_t version_major, uint32_t version_minor, sym_lookup_t, script_lookup_t);
154c060f1435e7b9405f3be8974417fa6f410f03753Stephen Hines    void setPriority(int32_t priority) override;
155709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    virtual void launchThreads(WorkerCallback_t cbk, void *data);
156709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    static void * helperThreadProc(void *vrsc);
157709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    RsdCpuScriptImpl * setTLS(RsdCpuScriptImpl *sc);
158709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
159709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    Context * getContext() {return mRSC;}
160c44d6706868749abe37780fc28b2cc627ddcf269Jason Sams    uint32_t getThreadCount() const {
161c44d6706868749abe37780fc28b2cc627ddcf269Jason Sams        return mWorkers.mCount + 1;
162c44d6706868749abe37780fc28b2cc627ddcf269Jason Sams    }
163709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
16414ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Wala    // Launch foreach kernel
16514ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Wala    void launchForEach(const Allocation **ains, uint32_t inLen, Allocation *aout,
16614ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Wala                       const RsScriptCall *sc, MTLaunchStructForEach *mtls);
16714ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Wala
1686c1876bbef1b2c89975dce91230a168bd2d2ce4cDavid Gross    // Launch a general reduce kernel
169ae2ec3febedfc29376b9104413fb4042028f1265David Gross    void launchReduce(const Allocation ** ains, uint32_t inLen, Allocation *aout,
170ae2ec3febedfc29376b9104413fb4042028f1265David Gross                      MTLaunchStructReduce *mtls);
1716c1876bbef1b2c89975dce91230a168bd2d2ce4cDavid Gross
172c060f1435e7b9405f3be8974417fa6f410f03753Stephen Hines    CpuScript * createScript(const ScriptC *s, char const *resName, char const *cacheDir,
173c060f1435e7b9405f3be8974417fa6f410f03753Stephen Hines                             uint8_t const *bitcode, size_t bitcodeSize, uint32_t flags) override;
174c060f1435e7b9405f3be8974417fa6f410f03753Stephen Hines    CpuScript * createIntrinsic(const Script *s, RsScriptIntrinsicID iid, Element *e) override;
175c060f1435e7b9405f3be8974417fa6f410f03753Stephen Hines    void* createScriptGroup(const ScriptGroupBase *sg) override;
176709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
177709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    const RsdCpuReference::CpuSymbol *symLookup(const char *);
178709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
17914ce007a633b10e3b9a3fae29d8f53a7e8c9b59fMatt Wala    RsdCpuReference::CpuScript *lookupScript(const Script *s) {
180709a0978ae141198018ca9769f8d96292a8928e6Jason Sams        return mScriptLookupFn(mRSC, s);
181709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    }
182709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
1831d476620399d54774e4fd386c1d23cc583d49522Stephen Hines    void setSelectRTCallback(RSSelectRTCallback pSelectRTCallback) {
1841d476620399d54774e4fd386c1d23cc583d49522Stephen Hines        mSelectRTCallback = pSelectRTCallback;
1851d476620399d54774e4fd386c1d23cc583d49522Stephen Hines    }
1861d476620399d54774e4fd386c1d23cc583d49522Stephen Hines    RSSelectRTCallback getSelectRTCallback() {
1871d476620399d54774e4fd386c1d23cc583d49522Stephen Hines        return mSelectRTCallback;
1881d476620399d54774e4fd386c1d23cc583d49522Stephen Hines    }
189b7d9c80c98fc96aa7c638e3124be24f13a6436b2Stephen Hines
190005113297b19ed256b6db9d6bc293ed9266899fcStephen Hines    virtual void setBccPluginName(const char *name) {
191c31585b8ca865bf2b35abc79c8a8ee42de27bee8Yang Ni        mBccPluginName.setTo(name);
192005113297b19ed256b6db9d6bc293ed9266899fcStephen Hines    }
193005113297b19ed256b6db9d6bc293ed9266899fcStephen Hines    virtual const char *getBccPluginName() const {
194c31585b8ca865bf2b35abc79c8a8ee42de27bee8Yang Ni        return mBccPluginName.string();
195005113297b19ed256b6db9d6bc293ed9266899fcStephen Hines    }
19610adb0c2029f112b5738228617d5645f6ecea0c5David Gross    bool getInKernel() override { return mInKernel; }
197709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
1988409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines    // Set to true if we should embed global variable information in the code.
199c060f1435e7b9405f3be8974417fa6f410f03753Stephen Hines    void setEmbedGlobalInfo(bool v) override {
2008409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines        mEmbedGlobalInfo = v;
2018409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines    }
2028409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines
2038409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines    // Returns true if we should embed global variable information in the code.
204c060f1435e7b9405f3be8974417fa6f410f03753Stephen Hines    bool getEmbedGlobalInfo() const override {
2058409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines        return mEmbedGlobalInfo;
2068409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines    }
2078409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines
2088409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines    // Set to true if we should skip constant (immutable) global variables when
2098409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines    // potentially embedding information about globals.
210c060f1435e7b9405f3be8974417fa6f410f03753Stephen Hines    void setEmbedGlobalInfoSkipConstant(bool v) override {
2118409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines        mEmbedGlobalInfoSkipConstant = v;
2128409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines    }
2138409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines
2148409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines    // Returns true if we should skip constant (immutable) global variables when
2158409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines    // potentially embedding information about globals.
216c060f1435e7b9405f3be8974417fa6f410f03753Stephen Hines    bool getEmbedGlobalInfoSkipConstant() const override {
2178409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines        return mEmbedGlobalInfoSkipConstant;
2188409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines    }
2198409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines
220709a0978ae141198018ca9769f8d96292a8928e6Jason Samsprotected:
221709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    Context *mRSC;
222709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    uint32_t version_major;
223709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    uint32_t version_minor;
224709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    //bool mHasGraphics;
22510adb0c2029f112b5738228617d5645f6ecea0c5David Gross    bool mInKernel;  // Is a parallel kernel execution underway?
226709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
227709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    struct Workers {
228709a0978ae141198018ca9769f8d96292a8928e6Jason Sams        volatile int mRunningCount;
229709a0978ae141198018ca9769f8d96292a8928e6Jason Sams        volatile int mLaunchCount;
230709a0978ae141198018ca9769f8d96292a8928e6Jason Sams        uint32_t mCount;
231709a0978ae141198018ca9769f8d96292a8928e6Jason Sams        pthread_t *mThreadId;
232709a0978ae141198018ca9769f8d96292a8928e6Jason Sams        pid_t *mNativeThreadId;
233709a0978ae141198018ca9769f8d96292a8928e6Jason Sams        Signal mCompleteSignal;
234709a0978ae141198018ca9769f8d96292a8928e6Jason Sams        Signal *mLaunchSignals;
235709a0978ae141198018ca9769f8d96292a8928e6Jason Sams        WorkerCallback_t mLaunchCallback;
236709a0978ae141198018ca9769f8d96292a8928e6Jason Sams        void *mLaunchData;
237709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    };
238709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    Workers mWorkers;
239709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    bool mExit;
240709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    sym_lookup_t mSymLookupFn;
241709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    script_lookup_t mScriptLookupFn;
242709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
243709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    ScriptTLSStruct mTlsStruct;
244f218bf115af4ae4fd79adbb8842608b308a4cf07Stephen Hines
2451d476620399d54774e4fd386c1d23cc583d49522Stephen Hines    RSSelectRTCallback mSelectRTCallback;
246c31585b8ca865bf2b35abc79c8a8ee42de27bee8Yang Ni    String8 mBccPluginName;
2478409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines
2488409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines    // Specifies whether we should embed global variable information in the
2498409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines    // code via special RS variables that can be examined later by the driver.
2508409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines    // Defaults to true.
2518409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines    bool mEmbedGlobalInfo;
2528409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines
2538409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines    // Specifies whether we should skip constant (immutable) global variables
2548409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines    // when potentially embedding information about globals.
2558409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines    // Defaults to true.
2568409d6414dd4a42aa59779fcfe9fce18648cb135Stephen Hines    bool mEmbedGlobalInfoSkipConstant;
25710adb0c2029f112b5738228617d5645f6ecea0c5David Gross
25810adb0c2029f112b5738228617d5645f6ecea0c5David Gross    long mPageSize;
25910adb0c2029f112b5738228617d5645f6ecea0c5David Gross
26010adb0c2029f112b5738228617d5645f6ecea0c5David Gross    // Launch a general reduce kernel
261ae2ec3febedfc29376b9104413fb4042028f1265David Gross    void launchReduceSerial(const Allocation ** ains, uint32_t inLen, Allocation *aout,
262ae2ec3febedfc29376b9104413fb4042028f1265David Gross                            MTLaunchStructReduce *mtls);
263ae2ec3febedfc29376b9104413fb4042028f1265David Gross    void launchReduceParallel(const Allocation ** ains, uint32_t inLen, Allocation *aout,
264ae2ec3febedfc29376b9104413fb4042028f1265David Gross                              MTLaunchStructReduce *mtls);
265709a0978ae141198018ca9769f8d96292a8928e6Jason Sams};
266709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
267709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
268709a0978ae141198018ca9769f8d96292a8928e6Jason Sams}
269709a0978ae141198018ca9769f8d96292a8928e6Jason Sams}
270709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
271709a0978ae141198018ca9769f8d96292a8928e6Jason Sams#endif
272