1 /** 2 * Copyright 2020-2021 Huawei Technologies Co., Ltd 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 #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_DATASETOPS_CACHE_LOOKUP_OP_H_ 17 #define MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_DATASETOPS_CACHE_LOOKUP_OP_H_ 18 19 #include <atomic> 20 #include <memory> 21 #include <string> 22 #include <utility> 23 #include <vector> 24 #include "minddata/dataset/engine/datasetops/cache_base_op.h" 25 26 namespace mindspore { 27 namespace dataset { 28 /// \brief provides a memory/disk cache that acts as a save-point within a mappable dataset. 29 /// \note For non-mappable dataset, please see CacheOp 30 /// \see CacheOp 31 class CacheLookupOp : public CacheBase, public SamplerRT { 32 public: 33 /// \brief Constructor 34 /// \note It takes the same argument as the base class. 35 /// \see CacheBase CacheLookupOp(int32_t num_workers,int32_t op_connector_size,std::shared_ptr<CacheClient> cache_client,std::shared_ptr<SamplerRT> sampler)36 CacheLookupOp(int32_t num_workers, int32_t op_connector_size, std::shared_ptr<CacheClient> cache_client, 37 std::shared_ptr<SamplerRT> sampler) 38 : CacheBase(num_workers, op_connector_size, cache_client, sampler), SamplerRT(*(sampler.get())) {} 39 ~CacheLookupOp() = default; 40 // As a parallel op, we override these two functions 41 Status operator()() override; 42 Status WorkerEntry(int32_t worker_id) override; 43 // As a sampler, we override the following functions 44 Status ResetSampler(const bool failover_reset) override; 45 Status HandshakeRandomAccessOp(const RandomAccessOp *op, const int32_t reset_count) override; 46 Status InitSampler() override; 47 Status GetNextSample(TensorRow *out) override; 48 void Print(std::ostream &out, bool show_all) const override; 49 void SamplerPrint(std::ostream &out, bool show_all) const override; AllowCacheMiss()50 bool AllowCacheMiss() override { return true; } Name()51 std::string Name() const override { return kCacheLookupOp; } 52 53 protected: 54 Status ComputeColMap() override; 55 56 private: 57 WaitPost leaf_op_wp_; 58 59 Status RegisterResources() override; 60 }; 61 } // namespace dataset 62 } // namespace mindspore 63 64 #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_DATASETOPS_CACHE_LOOKUP_OP_H_ 65