• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 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_IR_DATASETOPS_CACHE_LOOKUP_NODE_H_
17 #define MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_CACHE_LOOKUP_NODE_H_
18 
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 #include "minddata/dataset/engine/datasetops/cache_lookup_op.h"
24 #include "minddata/dataset/engine/ir/datasetops/dataset_node.h"
25 
26 namespace mindspore {
27 namespace dataset {
28 class CacheLookupNode : public DatasetNode, public SamplerObj {
29  public:
30   /// \brief Constructor
31   CacheLookupNode(std::shared_ptr<DatasetNode> child, std::shared_ptr<SamplerObj> sampler,
32                   std::shared_ptr<DatasetCache> cache);
33 
34   /// \brief Destructor
35   ~CacheLookupNode() override = default;
36 
37   /// \brief Node name getter
38   /// \return Name of the current node
Name()39   std::string Name() const override { return kCacheLookupNode; }
40 
41   /// \brief Print the description
42   /// \param out - The output stream to write output to
43   void Print(std::ostream &out) const override;
44 
45   /// \brief Copy the node to a new object
46   /// \return A shared pointer to the new copy
47   std::shared_ptr<DatasetNode> Copy() override;
48 
49   /// \brief a base class override function to convert a SamplerObj class into a runtime sampler object
50   /// \param[out] out Shared pointer to the newly created Sampler
51   /// \return The Status code of the function. It returns OK status if sampler is created successfully.
52   Status SamplerBuild(std::shared_ptr<SamplerRT> *const out) override;
53 
54   /// \brief a base class override function to copy a SamplerObj class
55   /// \return Shared pointers to the newly copied SamplerObj
56   std::shared_ptr<SamplerObj> SamplerCopy() override;
57 
58   /// \brief a base class override function to create the required runtime dataset op objects for this class
59   /// \param node_ops - A vector containing shared pointer to the Dataset Ops that this object will create
60   /// \return Status Status::OK() if build successfully
61   Status Build(std::vector<std::shared_ptr<DatasetOp>> *node_ops) override;
62 
63   /// \brief Parameters validation
64   /// \return Status Status::OK() if all the parameters are valid
65   Status ValidateParams() override;
66 
67   /// \brief Base-class override for accepting IRNodePass visitor
68   /// \param[in] p The node to visit
69   /// \param[out] modified Indicator if the node was modified
70   /// \return Status of the node visit
71   Status Accept(IRNodePass *const p, bool *const modified) override;
72 
73   /// \brief Base-class override for accepting IRNodePass visitor
74   /// \param[in] p The node to visit
75   /// \param[out] modified Indicator if the node was modified
76   /// \return Status of the node visit
77   Status AcceptAfter(IRNodePass *const p, bool *const modified) override;
78 
79   /// \brief Sampler getter
80   /// \return SamplerObj of the current node
Sampler()81   std::shared_ptr<SamplerObj> Sampler() { return sampler_; }
82 
83  private:
84   std::shared_ptr<SamplerObj> sampler_;
85   std::shared_ptr<DatasetOp> lookup_op_;
86   std::shared_ptr<CacheLookupNode> lookup_node_copy_;
87 };
88 }  // namespace dataset
89 }  // namespace mindspore
90 #endif  // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_CACHE_LOOKUP_NODE_H_
91