Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#ifdef ORT_ENABLE_STREAM
#pragma once
#include "core/framework/stream_handles.h"
#include "gsl/gsl"
 
namespace onnxruntime {
class SessionState;
 
class DeviceStreamCollectionImpl;
// a collection of indexed device stream instances.
// the index is the same as the logic sequence index in the execution plan.
// this collection may be cached and reused for future iterations.
class DeviceStreamCollection {
 public:
  DeviceStreamCollection(size_t num_streams, const AllocatorMap& allocators, bool is_main_graph);
  ~DeviceStreamCollection();
  // Add the device stream instance to given index.
  // and set the current collection as the owner of the device stream.
  void AddDeviceStream(size_t stream_idx, std::unique_ptr<Stream> stream);
 
  // Use an external device stream instance at given index.
  // the current collection is not the owner.
  // this is mainly used in subgraph execution, when we want the
  // subgraph nodes execute on the same stream as parent node.
  // stream could be nullptr, which means the nodes/subgraph is assigned to
  // a EP which doesn't support Stream, i.e. CPU based EPs.
  void SetDeviceStream(size_t stream_idx, Stream* stream);
 
  // override the stream for matching device.
  // only one override is allowed at a time presumably coming from
  // OrtRunOptions
  // returns an error if no matching stream
  Status SetStreamOverride(Stream* stream);
 
  // Remove the override before caching/reusing the collection.
  void ResetStreamOverride();
 
  // get the Stream instance on given stream index
  // The return value could be nullptr, which means the EP on this
  // logic sequence doesn't support Stream.
  Stream* GetStream(size_t stream_idx) const;
 
  // get the number of device stream instances.
  size_t NumStreams() const;
 
  // Since the collection may be reused for future iteration,
  // This API is used to cleanup some resources at the end of an iteration.
  Status CleanUp(bool sync_streams);
 
  Stream* GetStreamForDevice(const OrtDevice& device) const;
 
 private:
  std::unique_ptr<DeviceStreamCollectionImpl> impl_;
};
 
struct DeviceStreamCollectionHolder {
  DeviceStreamCollectionHolder(const SessionState* session_state);
  DeviceStreamCollectionHolder() = delete;
  DeviceStreamCollectionHolder(const DeviceStreamCollectionHolder&) = delete;
 
  ~DeviceStreamCollectionHolder();
 
  const SessionState* session_state_;
  std::unique_ptr<DeviceStreamCollection> p_;
};
 
}  // namespace onnxruntime
#endif