blob: 248e5c73812d912b9460943a415a5c27984b05dd [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
Stephen Hinesc060f142015-05-13 19:26:09 -070068 void invokeInit() override;
69 void invokeFreeChildren() override;
Jason Sams709a0972012-11-15 18:18:04 -080070
Stephen Hinesc060f142015-05-13 19:26:09 -070071 void setGlobalVar(uint32_t slot, const void *data, size_t dataLength) override;
72 void getGlobalVar(uint32_t slot, void *data, size_t dataLength) override;
73 void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength,
74 const Element *e, const uint32_t *dims,
75 size_t dimLength) override;
76 void setGlobalBind(uint32_t slot, Allocation *data) override;
77 void setGlobalObj(uint32_t slot, ObjectBase *data) override;
Jason Sams709a0972012-11-15 18:18:04 -080078
Yang Ni062c2872015-02-20 15:20:00 -080079 const char* getFieldName(uint32_t slot) const;
Jason Sams709a0972012-11-15 18:18:04 -080080
Stephen Hinesc060f142015-05-13 19:26:09 -070081 ~RsdCpuScriptImpl() override;
Jason Sams709a0972012-11-15 18:18:04 -080082 RsdCpuScriptImpl(RsdCpuReferenceImpl *ctx, const Script *s);
83
84 const Script * getScript() {return mScript;}
85
Jason Samsbf2111d2015-01-26 18:13:41 -080086 bool forEachMtlsSetup(const Allocation ** ains, uint32_t inLen,
Chris Wailes4b3c34e2014-06-11 12:00:29 -070087 Allocation * aout, const void * usr, uint32_t usrLen,
Matt Wala14ce0072015-07-30 17:30:25 -070088 const RsScriptCall *sc, MTLaunchStructForEach *mtls);
Chris Wailes4b3c34e2014-06-11 12:00:29 -070089
Matt Wala14ce0072015-07-30 17:30:25 -070090 virtual void forEachKernelSetup(uint32_t slot, MTLaunchStructForEach *mtls);
Jason Sams709a0972012-11-15 18:18:04 -080091
Matt Wala14ce0072015-07-30 17:30:25 -070092 // Build an MTLaunchStruct suitable for launching a reduce-style kernel.
93 bool reduceMtlsSetup(const Allocation *ain, const Allocation *aout,
94 const RsScriptCall *sc, MTLaunchStructReduce *mtls);
95 // Finalize an MTLaunchStruct for launching a reduce-style kernel.
96 virtual void reduceKernelSetup(uint32_t slot, MTLaunchStructReduce *mtls);
Jason Sams709a0972012-11-15 18:18:04 -080097
98 const RsdCpuReference::CpuSymbol * lookupSymbolMath(const char *sym);
99 static void * lookupRuntimeStub(void* pContext, char const* name);
100
Stephen Hinesc060f142015-05-13 19:26:09 -0700101 Allocation * getAllocationForPointer(const void *ptr) const override;
Pirama Arumuga Nainardc0d8f72014-12-02 15:23:38 -0800102 bool storeRSInfoFromSO();
Jason Sams709a0972012-11-15 18:18:04 -0800103
Stephen Hines8409d642015-04-28 18:49:56 -0700104 int getGlobalEntries() const override;
105 const char * getGlobalName(int i) const override;
106 const void * getGlobalAddress(int i) const override;
107 size_t getGlobalSize(int i) const override;
Stephen Hines5aa018c2015-05-20 18:09:57 -0700108 uint32_t getGlobalProperties(int i) const override;
Stephen Hines8409d642015-04-28 18:49:56 -0700109
Jason Sams709a0972012-11-15 18:18:04 -0800110protected:
111 RsdCpuReferenceImpl *mCtx;
112 const Script *mScript;
Pirama Arumuga Nainardc0d8f72014-12-02 15:23:38 -0800113 void *mScriptSO;
Jason Sams709a0972012-11-15 18:18:04 -0800114
Jason Sams110f1812013-03-14 16:02:18 -0700115#ifndef RS_COMPATIBILITY_LIB
Jean-Luc Brouillet40e35cd2014-06-25 18:21:45 -0700116 // Returns the path to the core library we'll use.
117 const char* findCoreLib(const bcinfo::MetadataExtractor& bitCodeMetaData, const char* bitcode,
Jean-Luc Brouillet9ab50942014-06-18 18:10:32 -0700118 size_t bitcodeSize);
Stephen Hines45e753a2015-01-19 20:58:44 -0800119#endif
120
Jason Sams110f1812013-03-14 16:02:18 -0700121 RootFunc_t mRoot;
122 RootFunc_t mRootExpand;
Matt Wala14ce0072015-07-30 17:30:25 -0700123 InitOrDtorFunc_t mInit;
124 InitOrDtorFunc_t mFreeChildren;
Yang Nid9bae682015-01-20 15:31:15 -0800125 ScriptExecutable* mScriptExec;
Jason Sams709a0972012-11-15 18:18:04 -0800126
127 Allocation **mBoundAllocs;
128 void * mIntrinsicData;
129 bool mIsThreadable;
Yang Nida0f0692015-01-12 13:03:40 -0800130
Yang Ni2abfcc62015-02-17 16:05:19 -0800131public:
132 static const char* BCC_EXE_PATH;
133 const char* getBitcodeFilePath() const { return mBitcodeFilePath.string(); }
Yang Nida0f0692015-01-12 13:03:40 -0800134
Yang Ni2abfcc62015-02-17 16:05:19 -0800135private:
Matt Wala14ce0072015-07-30 17:30:25 -0700136 bool setUpMtlsDimensions(MTLaunchStructCommon *mtls,
137 const RsLaunchDimensions &baseDim,
138 const RsScriptCall *sc);
139
Yang Ni2abfcc62015-02-17 16:05:19 -0800140 String8 mBitcodeFilePath;
Yang Nicb170152015-04-16 10:27:02 -0700141 uint32_t mBuildChecksum;
Pirama Arumuga Nainaraa6757f2015-02-13 20:02:50 -0800142 bool mChecksumNeeded;
Jason Sams709a0972012-11-15 18:18:04 -0800143};
144
Jason Sams709a0972012-11-15 18:18:04 -0800145Allocation * rsdScriptGetAllocationForPointer(
146 const Context *dc,
147 const Script *script,
148 const void *);
149
Yang Nicb170152015-04-16 10:27:02 -0700150uint32_t constructBuildChecksum(uint8_t const *bitcode, size_t bitcodeSize,
151 const char *commandLine,
152 const char ** bccFiles, size_t numFiles);
Yang Nif02a2b02015-04-07 16:00:31 -0700153
Jason Sams709a0972012-11-15 18:18:04 -0800154}
Yang Nid9bae682015-01-20 15:31:15 -0800155
Yang Nida0f0692015-01-12 13:03:40 -0800156#ifdef __LP64__
157#define SYSLIBPATH "/system/lib64"
Pirama Arumuga Nainar682672e2015-05-07 15:52:48 -0700158#define SYSLIBPATH_VENDOR "/system/vendor/lib64"
Yang Nida0f0692015-01-12 13:03:40 -0800159#else
160#define SYSLIBPATH "/system/lib"
Pirama Arumuga Nainar682672e2015-05-07 15:52:48 -0700161#define SYSLIBPATH_VENDOR "/system/vendor/lib"
Yang Nida0f0692015-01-12 13:03:40 -0800162#endif
163
Jason Sams709a0972012-11-15 18:18:04 -0800164}
165
Stephen Hines6a236ad2015-06-22 14:51:30 -0700166#endif // RSD_CPU_SCRIPT_H