GPRidge v1.0.0
GPR-accelerated saddle point searches on potential energy surfaces
☾
Toggle main menu visibility
Loading...
Searching...
No Matches
RuntimeManifest.cpp
Go to the documentation of this file.
1
// SPDX-License-Identifier: MIT
2
// Copyright (c) gpridge developers
3
// See LICENSE for details.
4
5
#include "
RuntimeManifest.h
"
6
7
#include <algorithm>
8
#include <mutex>
9
#include <sstream>
10
#include <tuple>
11
#include <utility>
12
13
#include "
AbiReport.h
"
14
#include "
auxiliary/Sha256.h
"
15
16
namespace
gpr::runtime
{
17
namespace
{
18
19
std::mutex registry_mutex;
20
std::vector<Component> registry;
21
22
std::string quote(
const
std::string& value)
23
{
24
std::string
out
=
"\""
;
25
for
(
const
char
c: value) {
26
switch
(c) {
27
case
'\\'
:
28
out
+=
"\\\\"
;
29
break
;
30
case
'"'
:
31
out
+=
"\\\""
;
32
break
;
33
case
'\n'
:
34
out
+=
"\\n"
;
35
break
;
36
case
'\r'
:
37
out
+=
"\\r"
;
38
break
;
39
case
'\t'
:
40
out
+=
"\\t"
;
41
break
;
42
default
:
43
out
+= c;
44
}
45
}
46
return
out
+
'"'
;
47
}
48
49
std::vector<Component> linkedComponents()
50
{
51
std::vector<Component>
out
;
52
for
(
const
auto
& library:
abi::libraries
())
53
out
.push_back({library.name,
54
library.library,
55
library.name,
56
"linked"
,
57
{},
58
{},
59
library.verified});
60
return
out
;
61
}
62
63
std::vector<Component> sortedSnapshot()
64
{
65
auto
out
= linkedComponents();
66
{
67
const
std::lock_guard<std::mutex> lock(registry_mutex);
68
for
(
const
auto
& component: registry) {
69
const
auto
match = std::find_if(
70
out
.begin(),
out
.end(), [&](
const
Component
& current) {
71
return current.role == component.role &&
72
current.name == component.name;
73
});
74
if
(match ==
out
.end())
75
out
.push_back(component);
76
else
77
*match = component;
78
}
79
}
80
std::sort(
81
out
.begin(),
out
.end(),
82
[](
const
Component
& left,
const
Component
& right) {
83
return std::tie(left.role, left.name, left.version, left.path) <
84
std::tie(right.role, right.name, right.version, right.path);
85
});
86
return
out
;
87
}
88
89
std::string componentJson(
const
Component
& component)
90
{
91
std::ostringstream
out
;
92
out
<<
"{\"load\":"
<< quote(component.
load
)
93
<<
",\"name\":"
<< quote(component.
name
)
94
<<
",\"path\":"
<< quote(component.
path
)
95
<<
",\"role\":"
<< quote(component.
role
)
96
<<
",\"sha256\":"
<< quote(component.
sha256
)
97
<<
",\"verified\":"
<< (component.
verified
?
"true"
:
"false"
)
98
<<
",\"version\":"
<< quote(component.
version
) <<
"}"
;
99
return
out
.str();
100
}
101
102
std::string manifestJsonWithoutDigest(
const
std::vector<Component>& snapshot)
103
{
104
std::ostringstream
out
;
105
out
<<
"{\"components\":["
;
106
for
(std::size_t i = 0; i < snapshot.size(); ++i) {
107
if
(i)
out
<<
','
;
108
out
<< componentJson(snapshot[i]);
109
}
110
out
<<
"],\"format\":\"gpridge-runtime-components\",\"version\":1}"
;
111
return
out
.str();
112
}
113
}
// namespace
114
115
void
registerComponent
(
Component
component)
116
{
117
const
std::lock_guard<std::mutex> lock(registry_mutex);
118
const
auto
existing = std::find_if(
119
registry.begin(), registry.end(), [&](
const
Component
& current) {
120
return current.role == component.role &&
121
current.name == component.name;
122
});
123
if
(existing == registry.end())
124
registry.push_back(std::move(component));
125
else
126
*existing = std::move(component);
127
}
128
129
std::vector<Component>
components
()
130
{
131
return
sortedSnapshot();
132
}
133
134
std::string
manifestJson
()
135
{
136
const
auto
snapshot = sortedSnapshot();
137
const
auto
payload = manifestJsonWithoutDigest(snapshot);
138
const
auto
digest =
sha256Hex
(payload.data(), payload.size());
139
std::ostringstream
out
;
140
out
<<
"{\"components\":["
;
141
for
(std::size_t i = 0; i < snapshot.size(); ++i) {
142
if
(i)
out
<<
','
;
143
out
<< componentJson(snapshot[i]);
144
}
145
out
<<
"],\"format\":\"gpridge-runtime-components\",\"sha256\":"
146
<< quote(digest) <<
",\"version\":1}"
;
147
return
out
.str();
148
}
149
150
std::string
manifestSha256
()
151
{
152
const
auto
manifest = manifestJsonWithoutDigest(sortedSnapshot());
153
return
sha256Hex
(manifest.data(), manifest.size());
154
}
155
156
}
// namespace gpr::runtime
AbiReport.h
RuntimeManifest.h
Sha256.h
out
eon_relax_band_t eon_relax_surface_fn void eon_relax_outcome_t * out
Definition
eon_relax_engine.h:240
gpr::abi::libraries
std::vector< LibraryStatus > libraries()
Definition
AbiReport.h:62
gpr::runtime
Definition
RuntimeManifest.cpp:16
gpr::runtime::registerComponent
void registerComponent(Component component)
Definition
RuntimeManifest.cpp:115
gpr::runtime::manifestJson
std::string manifestJson()
Definition
RuntimeManifest.cpp:134
gpr::runtime::components
std::vector< Component > components()
A stable snapshot including the linked ABI dependencies.
Definition
RuntimeManifest.cpp:129
gpr::runtime::manifestSha256
std::string manifestSha256()
Definition
RuntimeManifest.cpp:150
gpr::sha256Hex
std::string sha256Hex(const void *data, std::size_t size)
Lowercase hexadecimal SHA-256 digest of a byte range (FIPS 180-4).
Definition
Sha256.cpp:127
gpr::runtime::Component
Definition
RuntimeManifest.h:15
gpr::runtime::Component::version
std::string version
Definition
RuntimeManifest.h:17
gpr::runtime::Component::path
std::string path
Definition
RuntimeManifest.h:20
gpr::runtime::Component::role
std::string role
Definition
RuntimeManifest.h:18
gpr::runtime::Component::sha256
std::string sha256
Definition
RuntimeManifest.h:21
gpr::runtime::Component::load
std::string load
linked, dlopen, or inprocess
Definition
RuntimeManifest.h:19
gpr::runtime::Component::verified
bool verified
Definition
RuntimeManifest.h:22
gpr::runtime::Component::name
std::string name
Definition
RuntimeManifest.h:16
gpr
RuntimeManifest.cpp
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf