Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ variables:
##### LC GITLAB CONFIGURATION
# Use an LLNL service user to run CI. This prevents from running pipelines as
# an actual user.
LLNL_SERVICE_USER: "koparasy"
LLNL_SERVICE_USER: "pottier1"
# Use the service user workspace. Solves permission issues, stores everything
# at the same location whoever triggers a pipeline.
CUSTOM_CI_BUILDS_DIR: "/usr/workspace/AMS/gitlab-runner"
Expand Down
24 changes: 12 additions & 12 deletions .gitlab/subscribed-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@
###

# Dane
dane-up-check:
variables:
CI_MACHINE: "dane"
extends: [.machine-check]
# dane-up-check:
# variables:
# CI_MACHINE: "dane"
# extends: [.machine-check]

dane-build-and-test:
variables:
CI_MACHINE: "dane"
JOB_CMD:
value: "scripts/gitlab/ci-build-test.sh"
expand: false
needs: [dane-up-check]
extends: [.build-and-test]
# dane-build-and-test:
# variables:
# CI_MACHINE: "dane"
# JOB_CMD:
# value: "scripts/gitlab/ci-build-test.sh"
# expand: false
# needs: [dane-up-check]
# extends: [.build-and-test]

# TIOGA
tioga-up-check:
Expand Down
2 changes: 1 addition & 1 deletion examples/ideal_gas/app/eos_ams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void AMSEOS<FPType>::Eval(const int length,
inputs.push_back(
std::move(AMSTensor::view(density, {length, 1}, {1, 1}, res_)));
inputs.push_back(
std::move(AMSTensor::view(density, {length, 1}, {1, 1}, res_)));
std::move(AMSTensor::view(energy, {length, 1}, {1, 1}, res_)));

SmallVector<AMSTensor> inout;
SmallVector<AMSTensor> outputs;
Expand Down
180 changes: 180 additions & 0 deletions src/AMSlib/AMSGraph.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
#include "AMSGraph.hpp"

#include <stdexcept>

namespace ams
{
namespace
{

static std::size_t hashCombine(std::size_t seed, std::size_t value) noexcept
{
seed ^= value + 0x9e3779b9u + (seed << 6) + (seed >> 2);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the goal of that function / magic number? Can't we use a classic hashing function?

return seed;
}

} // namespace

EdgeType::EdgeType(std::string src_, std::string rel_, std::string dst_)
: src(std::move(src_)), rel(std::move(rel_)), dst(std::move(dst_))
{
}

bool EdgeType::operator==(const EdgeType& other) const noexcept
{
return src == other.src && rel == other.rel && dst == other.dst;
}

std::size_t EdgeTypeHash::operator()(const EdgeType& e) const noexcept
{
std::size_t seed = std::hash<std::string>{}(e.src);
seed = hashCombine(seed, std::hash<std::string>{}(e.rel));
seed = hashCombine(seed, std::hash<std::string>{}(e.dst));
return seed;
}

std::string edgeTypeToString(const EdgeType& e)
{
return e.src + "__" + e.rel + "__" + e.dst;
}

ams::EdgeType edgeTypeFromString(const std::string& key)
{
const std::string delim = "__";

auto p1 = key.find(delim);
if (p1 == std::string::npos) {
throw std::runtime_error("edgeTypeFromString: missing first delimiter");
}

auto p2 = key.find(delim, p1 + delim.size());
if (p2 == std::string::npos) {
throw std::runtime_error("edgeTypeFromString: missing second delimiter");
}

if (key.find(delim, p2 + delim.size()) != std::string::npos) {
throw std::runtime_error("edgeTypeFromString: too many delimiters");
}

std::string src = key.substr(0, p1);
std::string rel = key.substr(p1 + delim.size(), p2 - (p1 + delim.size()));
std::string dst = key.substr(p2 + delim.size());

if (src.empty() || rel.empty() || dst.empty()) {
throw std::runtime_error("edgeTypeFromString: empty src/rel/dst component");
}

return ams::EdgeType{std::move(src), std::move(rel), std::move(dst)};
}

bool containsTensor(const AMSTensorMap& store, const std::string& name)
{
return store.find(name) != store.end();
}

AMSTensor* findTensor(AMSTensorMap& store, const std::string& name) noexcept
{
auto it = store.find(name);
if (it == store.end()) {
return nullptr;
}
return &it->second;
}

const AMSTensor* findTensor(const AMSTensorMap& store,
const std::string& name) noexcept
{
auto it = store.find(name);
if (it == store.end()) {
return nullptr;
}
return &it->second;
}

void insertTensor(AMSTensorMap& store, std::string name, AMSTensor&& tensor)
{
auto [it, inserted] = store.emplace(std::move(name), std::move(tensor));
if (!inserted) {
throw std::runtime_error("insertTensor: tensor name already exists");
}
}

void insertOrAssignTensor(AMSTensorMap& store,
std::string name,
AMSTensor&& tensor)
{
auto it = store.find(name);
if (it == store.end()) {
store.emplace(std::move(name), std::move(tensor));
} else {
it->second = std::move(tensor);
}
}

bool AMSHeterogeneousGraph::containsNodeStore(const std::string& name) const
{
return node_stores.find(name) != node_stores.end();
}

bool AMSHeterogeneousGraph::containsEdgeStore(const EdgeType& edge_type) const
{
return edge_stores.find(edge_type) != edge_stores.end();
}

AMSTensorMap& AMSHeterogeneousGraph::getOrCreateNodeStore(std::string name)
{
auto [it, inserted] =
node_stores.try_emplace(std::move(name), AMSTensorMap{});
(void)inserted;
return it->second;
}

AMSTensorMap& AMSHeterogeneousGraph::getOrCreateEdgeStore(EdgeType edge_type)
{
auto [it, inserted] =
edge_stores.try_emplace(std::move(edge_type), AMSTensorMap{});
(void)inserted;
return it->second;
}

AMSTensorMap* AMSHeterogeneousGraph::findNodeStore(
const std::string& name) noexcept
{
auto it = node_stores.find(name);
if (it == node_stores.end()) {
return nullptr;
}
return &it->second;
}

const AMSTensorMap* AMSHeterogeneousGraph::findNodeStore(
const std::string& name) const noexcept
{
auto it = node_stores.find(name);
if (it == node_stores.end()) {
return nullptr;
}
return &it->second;
}

AMSTensorMap* AMSHeterogeneousGraph::findEdgeStore(
const EdgeType& edge_type) noexcept
{
auto it = edge_stores.find(edge_type);
if (it == edge_stores.end()) {
return nullptr;
}
return &it->second;
}

const AMSTensorMap* AMSHeterogeneousGraph::findEdgeStore(
const EdgeType& edge_type) const noexcept
{
auto it = edge_stores.find(edge_type);
if (it == edge_stores.end()) {
return nullptr;
}
return &it->second;
}

} // namespace ams
Loading
Loading