/* * 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. */ #include "LimitedSupportDevice.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace android::nn::sample { LimitedSupportDevice::LimitedSupportDevice(SharedDevice device, Capabilities capabilities, SupportedOperationsFunction supportedOperationsFunction) : kDevice(std::move(device)), kCapabilities(std::move(capabilities)), kSupportedOperationsFunction(std::move(supportedOperationsFunction)) { CHECK(kDevice != nullptr); CHECK(kSupportedOperationsFunction != nullptr); const auto result = validate(kCapabilities); CHECK(result.has_value()) << result.error(); } const std::string& LimitedSupportDevice::getName() const { return kDevice->getName(); } const std::string& LimitedSupportDevice::getVersionString() const { return kDevice->getVersionString(); } Version LimitedSupportDevice::getFeatureLevel() const { return kDevice->getFeatureLevel(); } DeviceType LimitedSupportDevice::getType() const { return kDevice->getType(); } const std::vector& LimitedSupportDevice::getSupportedExtensions() const { return kDevice->getSupportedExtensions(); } const Capabilities& LimitedSupportDevice::getCapabilities() const { return kCapabilities; } std::pair LimitedSupportDevice::getNumberOfCacheFilesNeeded() const { return kDevice->getNumberOfCacheFilesNeeded(); } GeneralResult LimitedSupportDevice::wait() const { return kDevice->wait(); } GeneralResult> LimitedSupportDevice::getSupportedOperations( const Model& model) const { return kSupportedOperationsFunction(model); } GeneralResult LimitedSupportDevice::prepareModel( const Model& model, ExecutionPreference preference, Priority priority, OptionalTimePoint deadline, const std::vector& modelCache, const std::vector& dataCache, const CacheToken& token) const { const auto supportedOperations = NN_TRY(kSupportedOperationsFunction(model)); constexpr auto id = [](auto v) { return v; }; if (!std::all_of(supportedOperations.begin(), supportedOperations.end(), id)) { return NN_ERROR(nn::ErrorStatus::INVALID_ARGUMENT) << "Not all operations are supported"; } return kDevice->prepareModel(model, preference, priority, deadline, modelCache, dataCache, token); } GeneralResult LimitedSupportDevice::prepareModelFromCache( OptionalTimePoint deadline, const std::vector& modelCache, const std::vector& dataCache, const CacheToken& token) const { return kDevice->prepareModelFromCache(deadline, modelCache, dataCache, token); } GeneralResult LimitedSupportDevice::allocate( const BufferDesc& desc, const std::vector& preparedModels, const std::vector& inputRoles, const std::vector& outputRoles) const { return kDevice->allocate(desc, preparedModels, inputRoles, outputRoles); } } // namespace android::nn::sample