13 #include <onnxruntime_cxx_api.h>
14 #include <torch/script.h>
21 std::unique_ptr<const Logger>
logger)
23 m_env = std::make_unique<Ort::Env>(ORT_LOGGING_LEVEL_WARNING,
24 "ExaTrkX - metric learning");
26 Ort::SessionOptions session_options;
27 session_options.SetIntraOpNumThreads(1);
28 session_options.SetGraphOptimizationLevel(
29 GraphOptimizationLevel::ORT_ENABLE_EXTENDED);
38 std::vector<int64_t>& edgeList,
39 int64_t numSpacepoints,
41 torch::Device device(torch::kCUDA);
43 torch::TensorOptions().dtype(torch::kFloat32).device(torch::kCUDA);
45 torch::Tensor embedTensor =
46 torch::tensor(embedFeatures,
options)
51 stackedEdges = stackedEdges.toType(torch::kInt64).to(torch::kCPU);
54 std::copy(stackedEdges.data_ptr<int64_t>(),
55 stackedEdges.data_ptr<int64_t>() + stackedEdges.numel(),
56 std::back_inserter(edgeList));
60 std::vector<float>& inputValues, std::size_t,
int) {
61 Ort::AllocatorWithDefaultOptions allocator;
62 auto memoryInfo = Ort::MemoryInfo::CreateCpu(
63 OrtAllocatorType::OrtArenaAllocator, OrtMemType::OrtMemTypeDefault);
72 std::vector<const char*> eInputNames{
"sp_features"};
73 std::vector<Ort::Value> eInputTensor;
74 eInputTensor.push_back(Ort::Value::CreateTensor<float>(
75 memoryInfo, inputValues.data(), inputValues.size(), eInputShape.data(),
79 std::vector<const char*> eOutputNames{
"embedding_output"};
81 std::vector<Ort::Value> eOutputTensor;
82 eOutputTensor.push_back(Ort::Value::CreateTensor<float>(
83 memoryInfo, eOutputData.data(), eOutputData.size(), eOutputShape.data(),
84 eOutputShape.size()));
89 for (
size_t i = 0;
i < 3;
i++) {
96 std::vector<int64_t> edgeList;
98 int64_t numEdges = edgeList.size() / 2;
99 ACTS_DEBUG(
"Graph construction: built " << numEdges <<
" edges.");
101 for (
size_t i = 0;
i < 10;
i++) {
104 for (
size_t i = 0;
i < 10;
i++) {
108 return {std::make_shared<Ort::Value>(
std::move(eInputTensor[0])), edgeList};