blob: 2909dab1e516ef509cb0eddfbd6571e1cbb2263f [file] [log] [blame]
Jason Sams709a0972012-11-15 18:18:04 -08001/*
2 * Copyright (C) 2011-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
Stephen Hines6a236ad2015-06-22 14:51:30 -070017#ifndef RSD_CPU_SCRIPT_H
18#define RSD_CPU_SCRIPT_H
Jason Sams709a0972012-11-15 18:18:04 -080019
20#include <rs_hal.h>
21#include <rsRuntime.h>
22
Stephen Hines25e3af52014-05-21 21:23:08 -070023#ifndef RS_COMPATIBILITY_LIB
Tim Murray29809d12014-05-28 12:04:19 -070024#include <utility>
Stephen Hines25e3af52014-05-21 21:23:08 -070025#endif
26
Jason Sams709a0972012-11-15 18:18:04 -080027#include "rsCpuCore.h"
28
Jean-Luc Brouillet9ab50942014-06-18 18:10:32 -070029namespace bcinfo {
30 class MetadataExtractor;
31}
32
Jason Sams709a0972012-11-15 18:18:04 -080033namespace android {
34namespace renderscript {
35
Yang Ni2abfcc62015-02-17 16:05:19 -080036class ScriptExecutable;
Jason Sams709a0972012-11-15 18:18:04 -080037
38class RsdCpuScriptImpl : public RsdCpuReferenceImpl::CpuScript {
39public:
Jason Sams709a0972012-11-15 18:18:04 -080040 bool init(char const *resName, char const *cacheDir,
Stephen Hines00511322014-01-31 11:20:23 -080041 uint8_t const *bitcode, size_t bitcodeSize, uint32_t flags,
Chris Wailes44bef6f2014-08-12 13:51:10 -070042 char const *bccPluginName = nullptr);
Stephen Hinesc060f142015-05-13 19:26:09 -070043 void populateScript(Script *) override;
Jason Sams709a0972012-11-15 18:18:04 -080044
Stephen Hinesc060f142015-05-13 19:26:09 -070045 void invokeFunction(uint32_t slot, const void *params, size_t paramLength) override;
46 int invokeRoot() override;
Chris Wailesf3712132014-07-16 15:18:30 -070047 virtual void preLaunch(uint32_t slot, const Allocation ** ains,
48 uint32_t inLen, Allocation * aout, const void * usr,
Jason Sams17e3cdc2013-09-09 17:32:16 -070049 uint32_t usrLen, const RsScriptCall *sc);
Chris Wailesf3712132014-07-16 15:18:30 -070050 virtual void postLaunch(uint32_t slot, const Allocation ** ains,
51 uint32_t inLen, Allocation * aout,
52 const void * usr, uint32_t usrLen,
53 const RsScriptCall *sc);
Chris Wailes818cfa02014-07-16 15:18:30 -070054
Stephen Hinesc060f142015-05-13 19:26:09 -070055 void invokeForEach(uint32_t slot,
56 const Allocation ** ains,
57 uint32_t inLen,
58 Allocation* aout,
59 const void* usr,
60 uint32_t usrLen,
61 const RsScriptCall* sc) override;
Chris Wailesf3712132014-07-16 15:18:30 -070062
Matt Wala14ce0072015-07-30 17:30:25 -070063 void invokeReduce(uint32_t slot,
64 const Allocation* ain,
65 Allocation* aout,
66 const RsScriptCall* sc) override;
67
David Gross6c1876b2016-01-15 11:52:14 -080068 void invokeReduceNew(uint32_t slot,
69 const Allocation ** ains, uint32_t inLen,
70 Allocation* aout,
71 const RsScriptCall* sc) override;
72
Stephen Hinesc060f142015-05-13 19:26:09 -070073 void invokeInit() override;
74 void invokeFreeChildren() override;
Jason Sams709a0972012-11-15 18:18:04 -080075
Stephen Hinesc060f142015-05-13 19:26:09 -070076 void setGlobalVar(uint32_t slot, const void *data, size_t dataLength) override;
77 void getGlobalVar(uint32_t slot, void *data, size_t dataLength) override;
78 void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength,
79 const Element *e, const uint32_t *dims,
80 size_t dimLength) override;
81 void setGlobalBind(uint32_t slot, Allocation *data) override;
82 void setGlobalObj(uint32_t slot, ObjectBase *data) override;
Jason Sams709a0972012-11-15 18:18:04 -080083
Yang Ni062c2872015-02-20 15:20:00 -080084 const char* getFieldName(uint32_t slot) const;
Jason Sams709a0972012-11-15 18:18:04 -080085
Stephen Hinesc060f142015-05-13 19:26:09 -070086 ~RsdCpuScriptImpl() override;
Jason Sams709a0972012-11-15 18:18:04 -080087 RsdCpuScriptImpl(RsdCpuReferenceImpl *ctx, const Script *s);
88
89 const Script * getScript() {return mScript;}
90
Jason Samsbf2111d2015-01-26 18:13:41 -080091 bool forEachMtlsSetup(const Allocation ** ains, uint32_t inLen,
Chris Wailes4b3c34e2014-06-11 12:00:29 -070092 Allocation * aout, const void * usr, uint32_t usrLen,
Matt Wala14ce0072015-07-30 17:30:25 -070093 const RsScriptCall *sc, MTLaunchStructForEach *mtls);
Chris Wailes4b3c34e2014-06-11 12:00:29 -070094
Matt Wala14ce0072015-07-30 17:30:25 -070095 virtual void forEachKernelSetup(uint32_t slot, MTLaunchStructForEach *mtls);
Jason Sams709a0972012-11-15 18:18:04 -080096
David Gross6c1876b2016-01-15 11:52:14 -080097 // Build an MTLaunchStruct suitable for launching a simple reduce-style kernel.
Matt Wala14ce0072015-07-30 17:30:25 -070098 bool reduceMtlsSetup(const Allocation *ain, const Allocation *aout,
99 const RsScriptCall *sc, MTLaunchStructReduce *mtls);
David Gross6c1876b2016-01-15 11:52:14 -0800100 // Finalize an MTLaunchStruct for launching a simple reduce-style kernel.
Matt Wala14ce0072015-07-30 17:30:25 -0700101 virtual void reduceKernelSetup(uint32_t slot, MTLaunchStructReduce *mtls);
Jason Sams709a0972012-11-15 18:18:04 -0800102
David Gross6c1876b2016-01-15 11:52:14 -0800103 // Build an MTLaunchStruct suitable for launching a general reduce-style kernel.
104 bool reduceNewMtlsSetup(const Allocation ** ains, uint32_t inLen, const Allocation *aout,
105 const RsScriptCall *sc, MTLaunchStructReduceNew *mtls);
106 // Finalize an MTLaunchStruct for launching a general reduce-style kernel.
107 virtual void reduceNewKernelSetup(uint32_t slot, MTLaunchStructReduceNew *mtls);
108
Jason Sams709a0972012-11-15 18:18:04 -0800109 const RsdCpuReference::CpuSymbol * lookupSymbolMath(const char *sym);
110 static void * lookupRuntimeStub(void* pContext, char const* name);
111
Stephen Hinesc060f142015-05-13 19:26:09 -0700112 Allocation * getAllocationForPointer(const void *ptr) const override;
Pirama Arumuga Nainardc0d8f72014-12-02 15:23:38 -0800113 bool storeRSInfoFromSO();
Jason Sams709a0972012-11-15 18:18:04 -0800114
Stephen Hines8409d642015-04-28 18:49:56 -0700115 int getGlobalEntries() const override;
116 const char * getGlobalName(int i) const override;
117 const void * getGlobalAddress(int i) const override;
118 size_t getGlobalSize(int i) const override;
Stephen Hines5aa018c2015-05-20 18:09:57 -0700119 uint32_t getGlobalProperties(int i) const override;
Stephen Hines8409d642015-04-28 18:49:56 -0700120
Jason Sams709a0972012-11-15 18:18:04 -0800121protected:
122 RsdCpuReferenceImpl *mCtx;
123 const Script *mScript;
Pirama Arumuga Nainardc0d8f72014-12-02 15:23:38 -0800124 void *mScriptSO;
Jason Sams709a0972012-11-15 18:18:04 -0800125
Jason Sams110f1812013-03-14 16:02:18 -0700126#ifndef RS_COMPATIBILITY_LIB
Jean-Luc Brouillet40e35cd2014-06-25 18:21:45 -0700127 // Returns the path to the core library we'll use.
128 const char* findCoreLib(const bcinfo::MetadataExtractor& bitCodeMetaData, const char* bitcode,
Jean-Luc Brouillet9ab50942014-06-18 18:10:32 -0700129 size_t bitcodeSize);
Stephen Hines45e753a2015-01-19 20:58:44 -0800130#endif
131
Jason Sams110f1812013-03-14 16:02:18 -0700132 RootFunc_t mRoot;
133 RootFunc_t mRootExpand;
Matt Wala14ce0072015-07-30 17:30:25 -0700134 InitOrDtorFunc_t mInit;
135 InitOrDtorFunc_t mFreeChildren;
Yang Nid9bae682015-01-20 15:31:15 -0800136 ScriptExecutable* mScriptExec;
Jason Sams709a0972012-11-15 18:18:04 -0800137
138 Allocation **mBoundAllocs;
139 void * mIntrinsicData;
140 bool mIsThreadable;
Yang Nida0f0692015-01-12 13:03:40 -0800141
Yang Ni2abfcc62015-02-17 16:05:19 -0800142public:
143 static const char* BCC_EXE_PATH;
144 const char* getBitcodeFilePath() const { return mBitcodeFilePath.string(); }
Yang Nida0f0692015-01-12 13:03:40 -0800145
Yang Ni2abfcc62015-02-17 16:05:19 -0800146private:
Matt Wala14ce0072015-07-30 17:30:25 -0700147 bool setUpMtlsDimensions(MTLaunchStructCommon *mtls,
148 const RsLaunchDimensions &baseDim,
149 const RsScriptCall *sc);
150
Yang Ni2abfcc62015-02-17 16:05:19 -0800151 String8 mBitcodeFilePath;
Yang Nicb170152015-04-16 10:27:02 -0700152 uint32_t mBuildChecksum;
Pirama Arumuga Nainaraa6757f2015-02-13 20:02:50 -0800153 bool mChecksumNeeded;
Jason Sams709a0972012-11-15 18:18:04 -0800154};
155
Jason Sams709a0972012-11-15 18:18:04 -0800156Allocation * rsdScriptGetAllocationForPointer(
157 const Context *dc,
158 const Script *script,
159 const void *);
160
Yang Nicb170152015-04-16 10:27:02 -0700161uint32_t constructBuildChecksum(uint8_t const *bitcode, size_t bitcodeSize,
162 const char *commandLine,
163 const char ** bccFiles, size_t numFiles);
Yang Nif02a2b02015-04-07 16:00:31 -0700164
Jason Sams709a0972012-11-15 18:18:04 -0800165}
Yang Nid9bae682015-01-20 15:31:15 -0800166
Yang Nida0f0692015-01-12 13:03:40 -0800167#ifdef __LP64__
168#define SYSLIBPATH "/system/lib64"
Pirama Arumuga Nainar682672e2015-05-07 15:52:48 -0700169#define SYSLIBPATH_VENDOR "/system/vendor/lib64"
Yang Nida0f0692015-01-12 13:03:40 -0800170#else
171#define SYSLIBPATH "/system/lib"
Pirama Arumuga Nainar682672e2015-05-07 15:52:48 -0700172#define SYSLIBPATH_VENDOR "/system/vendor/lib"
Yang Nida0f0692015-01-12 13:03:40 -0800173#endif
174
Jason Sams709a0972012-11-15 18:18:04 -0800175}
176
Stephen Hines6a236ad2015-06-22 14:51:30 -0700177#endif // RSD_CPU_SCRIPT_H