/* * Copyright (C) 2021 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include #include #include #include #include #include "ShimDevice.h" #include "SupportLibrary.h" #include "SupportLibraryWrapper.h" namespace aidl::android::hardware::neuralnetworks { class ShimPreparedModel : public BnPreparedModel { public: ShimPreparedModel(std::shared_ptr nnapi, std::shared_ptr bufferTracker, ::android::nn::sl_wrapper::Compilation compilation, std::vector<::android::nn::sl_wrapper::Model> mainAndReferencedModels, std::vector> memoryPools, std::vector copiedOperandValues) : mNnapi(nnapi), mBufferTracker(bufferTracker), mCompilation(std::move(compilation)), mMainAndReferencedModels(std::move(mainAndReferencedModels)), mMemoryPools(std::move(memoryPools)), mCopiedOperandValues(std::move(copiedOperandValues)) { CHECK(mMainAndReferencedModels.size() > 0); }; ::ndk::ScopedAStatus executeSynchronously(const Request& request, bool measureTiming, int64_t deadlineNs, int64_t loopTimeoutDurationNs, ExecutionResult* executionResults) override; ::ndk::ScopedAStatus executeFenced(const Request& request, const std::vector<::ndk::ScopedFileDescriptor>& waitFor, bool measureTiming, int64_t deadlineNs, int64_t loopTimeoutDurationNs, int64_t durationNs, FencedExecutionResult* fencedExecutionResult) override; ndk::ScopedAStatus configureExecutionBurst(std::shared_ptr* burst) override; const ::android::nn::sl_wrapper::Compilation& getCompilation() const { return mCompilation; } const ::android::nn::sl_wrapper::Model& getMainModel() const { return mMainAndReferencedModels[0]; } private: ErrorStatus parseInputs( const Request& request, bool measure, int64_t deadlineNs, int64_t loopTimeoutDurationNs, ::android::nn::sl_wrapper::Execution* execution, std::vector>* requestMemoryPools); std::shared_ptr mNnapi; std::shared_ptr mBufferTracker; ::android::nn::sl_wrapper::Compilation mCompilation; std::vector<::android::nn::sl_wrapper::Model> mMainAndReferencedModels; std::vector> mMemoryPools; std::vector mCopiedOperandValues; }; } // namespace aidl::android::hardware::neuralnetworks