Исходный код СУБД 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#pragma once
 
#include <algorithm>
#include <cstddef>
#include <string>
#include <vector>
 
#include "core/session/onnxruntime_c_api.h"
#include "core/session/onnxruntime_cxx_api.h"
 
namespace onnxruntime {
namespace test {
 
// Shared EPContext read/write callback test doubles, used by both the EpContextDataUtils unit tests
// (ep_context_data_utils_test.cc) and the PluginEp end-to-end EPContext tests (test_execution.cc).
struct EpContextDataCallbackState {
  bool write_called = false;
  bool read_called = false;
  std::string write_file_name;
  std::string read_file_name;
  std::vector<char> payload;
  // Buffer the read callback allocated, recorded so tests can assert the reader adopted it instead of copying it.
  void* last_read_buffer = nullptr;
};
 
inline OrtStatus* ORT_API_CALL StoreEpContextDataCallback(void* state, const char* file_name, const void* buffer,
                                                          size_t buffer_size) {
  auto* callback_state = static_cast<EpContextDataCallbackState*>(state);
  callback_state->write_called = true;
  callback_state->write_file_name = file_name;
  callback_state->payload.clear();
  if (buffer_size != 0) {
    if (buffer == nullptr) {
      return Ort::GetApi().CreateStatus(ORT_INVALID_ARGUMENT,
                                        "StoreEpContextDataCallback received a null buffer for non-empty data");
    }
    callback_state->payload.assign(static_cast<const char*>(buffer), static_cast<const char*>(buffer) + buffer_size);
  }
  return nullptr;
}
 
inline OrtStatus* ORT_API_CALL LoadEpContextDataCallback(void* state, const char* file_name, OrtAllocator* allocator,
                                                         void** buffer, size_t* data_size) {
  auto* callback_state = static_cast<EpContextDataCallbackState*>(state);
  callback_state->read_called = true;
  callback_state->read_file_name = file_name;
 
  *buffer = nullptr;
  *data_size = callback_state->payload.size();
  callback_state->last_read_buffer = nullptr;
  if (callback_state->payload.empty()) {
    return nullptr;
  }
 
  OrtStatus* status = Ort::GetApi().AllocatorAlloc(allocator, callback_state->payload.size(), buffer);
  if (status != nullptr) {
    return status;
  }
 
  callback_state->last_read_buffer = *buffer;
  std::copy(callback_state->payload.begin(), callback_state->payload.end(), static_cast<char*>(*buffer));
  return nullptr;
}
 
}  // namespace test
}  // namespace onnxruntime