• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020 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 
17 #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_OPT_PRE_CACHE_VALIDATION_PASS_
18 #define MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_OPT_PRE_CACHE_VALIDATION_PASS_
19 
20 #include <memory>
21 #include <stack>
22 #include <utility>
23 #include "minddata/dataset/engine/opt/pass.h"
24 
25 namespace mindspore {
26 namespace dataset {
27 
28 /// \class CacheValidationPass cache_validation_pass.h
29 /// \brief This is a NodePass who's job is to catch invalid tree configurations related to cache and generate failures.
30 class CacheValidationPass : public IRNodePass {
31  public:
32   /// \brief Constructor
33   CacheValidationPass();
34 
35   /// \brief Destructor
36   ~CacheValidationPass() = default;
37 
38   /// \brief Returns an error if BatchNode exists under a cache
39   /// \param[in] node The node being visited
40   /// \param[in,out] modified Indicator if the node was changed at all
41   /// \return Status The status code returned
42   Status Visit(std::shared_ptr<BatchNode> node, bool *const modified) override;
43 
44   /// \brief Returns an error if ConcatNode exists under a cache
45   /// \param[in] node The node being visited
46   /// \param[in,out] modified Indicator if the node was changed at all
47   /// \return Status The status code returned
48   Status Visit(std::shared_ptr<ConcatNode> node, bool *const modified) override;
49 
50   /// \brief Returns an error if FilterNode exists under a cache
51   /// \param[in] node The node being visited
52   /// \param[in,out] modified Indicator if the node was changed at all
53   /// \return Status The status code returned
54   Status Visit(std::shared_ptr<FilterNode> node, bool *const modified) override;
55 
56   /// \brief Returns an error if SkipNode exists under a cache
57   /// \param[in] node The node being visited
58   /// \param[in,out] modified Indicator if the node was changed at all
59   /// \return Status The status code returned
60   Status Visit(std::shared_ptr<SkipNode> node, bool *const modified) override;
61 
62   /// \brief Returns an error if TakeNode exists under a cache
63   /// \param[in] node The node being visited
64   /// \param[in,out] modified Indicator if the node was changed at all
65   /// \return Status The status code returned
66   Status Visit(std::shared_ptr<TakeNode> node, bool *const modified) override;
67 
68   /// \brief Returns an error if ZipNode exists under a cache
69   /// \param[in] node The node being visited
70   /// \param[in,out] modified Indicator if the node was changed at all
71   /// \return Status The status code returned
72   Status Visit(std::shared_ptr<ZipNode> node, bool *const modified) override;
73 
74   /// \brief Returns an error if MapNode with non-deterministic tensor operations exists under a cache
75   /// \param[in] node The node being visited
76   /// \param[in,out] modified Indicator if the node was changed at all
77   /// \return Status The status code returned
78   Status Visit(std::shared_ptr<MapNode> node, bool *const modified) override;
79 
80   /// \brief Returns an error if there is a cache over another cache
81   /// \param[in] node The node being visited
82   /// \param[in,out] modified Indicator if the node was changed at all
83   /// \return Status The status code returned
84   Status Visit(std::shared_ptr<DatasetNode> node, bool *const modified) override;
85 
86   /// \brief Identifies and block repeat under cache scenarios
87   /// \param[in] node The node being visited
88   /// \param[in,out] modified Indicator if the node was changed at all
89   /// \return Status The status code returned
90   Status VisitAfter(std::shared_ptr<RepeatNode> node, bool *const modified) override;
91 
92   /// \brief Identifies the subtree above this node as not being cached
93   /// \param[in] node The node being visited
94   /// \param[in,out] modified Indicator if the node was changed at all
95   /// \return Status The status code returned
96   Status VisitAfter(std::shared_ptr<TFRecordNode> node, bool *const modified) override;
97 
98   /// \brief Identifies the subtree above this node as not being cached
99   /// \param[in] node The node being visited
100   /// \param[in,out] modified Indicator if the node was changed at all
101   /// \return Status The status code returned
102   Status VisitAfter(std::shared_ptr<DatasetNode> node, bool *const modified) override;
103 
104  private:
105   bool is_cached_;
106   bool is_mappable_;
107 };
108 }  // namespace dataset
109 }  // namespace mindspore
110 
111 #endif  // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_OPT_PRE_CACHE_VALIDATION_PASS_
112