• 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_DATASETOPS_SOURCE_SAMPLER_MINDRECORD_SAMPLER_H_
17 #define MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_DATASETOPS_SOURCE_SAMPLER_MINDRECORD_SAMPLER_H_
18 
19 #include <limits>
20 #include <memory>
21 #include <vector>
22 
23 #include "minddata/dataset/engine/datasetops/source/sampler/sampler.h"
24 #include "minddata/mindrecord/include/shard_reader.h"
25 
26 namespace mindspore {
27 namespace dataset {
28 class MindRecordSamplerRT : public SamplerRT {
29  public:
30   // Constructor
31   // @param shard_reader - shard_reader
32   // @param int64_t samples_per_tensor - Num of Sampler Ids to fetch via 1 GetNextSample call
33   MindRecordSamplerRT(mindrecord::ShardReader *shard_reader,
34                       int64_t samples_per_tensor = std::numeric_limits<int64_t>::max());
35 
36   // Destructor.
37   ~MindRecordSamplerRT() = default;
38 
39   // Op calls this to get next set of sampleIds
40   // @param out - Tensor of sample ids to be returned to caller
41   // @return Status The status code returned
42   Status GetNextSample(TensorRow *out) override;
43 
44   // meant to be called by base class or python
45   Status InitSampler() override;
46 
47   /// \brief Reset for next epoch.
48   /// \param[in] failover_reset A boolean to show whether we are resetting the pipeline
49   /// \return Status The status code returned
50   Status ResetSampler(const bool failover_reset = false) override;
51 
52   void SamplerPrint(std::ostream &out, bool show_all) const override;
53 
54   /// \brief Get the arguments of node
55   /// \param[out] out_json JSON string of all attributes
56   /// \return Status of the function
57   Status to_json(nlohmann::json *out_json) override;
58 
59  private:
60   mindrecord::ShardReader *shard_reader_;   // back pointer to the shard reader
61   const std::vector<int64_t> *sample_ids_;  // read-only back pointer into mind record sampler ids
62   int64_t next_id_;
63 };
64 }  // namespace dataset
65 }  // namespace mindspore
66 #endif  // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_DATASETOPS_SOURCE_SAMPLER_MINDRECORD_SAMPLER_H_
67