1 /* 2 * Copyright (C) 2021 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 17 #ifndef ANDROID_PACKAGES_MODULES_NEURALNETWORKS_DRIVER_SAMPLE_CANONICAL_BUFFER_H 18 #define ANDROID_PACKAGES_MODULES_NEURALNETWORKS_DRIVER_SAMPLE_CANONICAL_BUFFER_H 19 20 #include <BufferTracker.h> 21 #include <CpuExecutor.h> 22 #include <nnapi/IBuffer.h> 23 #include <nnapi/Result.h> 24 #include <nnapi/Types.h> 25 26 #include <memory> 27 28 namespace android::nn::sample { 29 30 class Buffer final : public IBuffer { 31 public: 32 Buffer(std::shared_ptr<ManagedBuffer> buffer, std::unique_ptr<BufferTracker::Token> token); 33 34 Request::MemoryDomainToken getToken() const override; 35 36 GeneralResult<void> copyTo(const SharedMemory& dst) const override; 37 GeneralResult<void> copyFrom(const SharedMemory& src, 38 const Dimensions& dimensions) const override; 39 40 private: 41 const std::shared_ptr<ManagedBuffer> kBuffer; 42 const std::unique_ptr<BufferTracker::Token> kToken; 43 }; 44 45 } // namespace android::nn::sample 46 47 #endif // ANDROID_PACKAGES_MODULES_NEURALNETWORKS_DRIVER_SAMPLE_CANONICAL_BUFFER_H 48