Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graph visualisation would only work if CUDASimulation was explicitly init() #1243

Merged
merged 2 commits into from
Oct 28, 2024
Merged
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
5 changes: 4 additions & 1 deletion include/flamegpu/io/LoggerFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <filesystem>

Check failure on line 9 in include/flamegpu/io/LoggerFactory.h

View workflow job for this annotation

GitHub Actions / cpplint (11.8, ubuntu-20.04)

<filesystem> is an unapproved C++17 header.

#include "flamegpu/io/Logger.h"
#include "flamegpu/io/JSONLogger.h"
Expand All @@ -31,9 +31,12 @@
return std::make_unique<XMLLogger>(output_path, prettyPrint, truncateFile);
} else if (extension == ".json") {
return std::make_unique<JSONLogger>(output_path, prettyPrint, truncateFile);
} else if (extension.empty()) {
THROW exception::InvalidFilePath("Filepath '%s' contains unsuitable characters or lacks a file extension, "
"in LoggerFactory::createLogger().", output_path.c_str());
}
THROW exception::UnsupportedFileType("File '%s' is not a type which can be written "
"by StateWriterFactory::createLogger().",
"by LoggerFactory::createLogger().",
output_path.c_str());
}
};
Expand Down
3 changes: 3 additions & 0 deletions include/flamegpu/io/StateReaderFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <filesystem>

Check failure on line 9 in include/flamegpu/io/StateReaderFactory.h

View workflow job for this annotation

GitHub Actions / cpplint (11.8, ubuntu-20.04)

<filesystem> is an unapproved C++17 header.
#include <vector>

#include "flamegpu/io/StateReader.h"
Expand Down Expand Up @@ -37,6 +37,9 @@
return new XMLStateReader();
} else if (extension == ".json") {
return new JSONStateReader();
} else if (extension.empty()) {
THROW exception::InvalidFilePath("Filepath '%s' contains unsuitable characters or lacks a file extension, "
"in StateReaderFactory::createLogger().", input.c_str());
}
THROW exception::UnsupportedFileType("File '%s' is not a type which can be read "
"by StateReaderFactory::createReader().",
Expand Down
3 changes: 3 additions & 0 deletions include/flamegpu/io/StateWriterFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <string>
#include <algorithm>
#include <filesystem>

Check failure on line 6 in include/flamegpu/io/StateWriterFactory.h

View workflow job for this annotation

GitHub Actions / cpplint (11.8, ubuntu-20.04)

<filesystem> is an unapproved C++17 header.

#include "flamegpu/io/StateWriter.h"
#include "flamegpu/io/XMLStateWriter.h"
Expand Down Expand Up @@ -32,6 +32,9 @@
return new XMLStateWriter();
} else if (extension == ".json") {
return new JSONStateWriter();
} else if (extension.empty()) {
THROW exception::InvalidFilePath("Filepath '%s' contains unsuitable characters or lacks a file extension, "
"in StateWriterFactory::createLogger().", output_file.c_str());
}
THROW exception::UnsupportedFileType("File '%s' is not a type which can be written "
"by StateWriterFactory::createWriter().",
Expand Down
16 changes: 10 additions & 6 deletions src/flamegpu/simulation/CUDASimulation.cu
Original file line number Diff line number Diff line change
Expand Up @@ -1542,12 +1542,6 @@ void CUDASimulation::applyConfig_derived() {

// We init Random through submodel hierarchy after singletons
reseed(getSimulationConfig().random_seed);

#ifdef FLAMEGPU_VISUALISATION
if (visualisation) {
visualisation->hookVis(visualisation, directed_graph_map);
}
#endif
}

void CUDASimulation::reseed(const uint64_t seed) {
Expand Down Expand Up @@ -1662,6 +1656,12 @@ void CUDASimulation::initialiseSingletons() {

// Ensure RTC is set up.
initialiseRTC();

#ifdef FLAMEGPU_VISUALISATION
if (visualisation) {
visualisation->hookVis(visualisation, directed_graph_map);
}
#endif
}

void CUDASimulation::initialiseRTC() {
Expand Down Expand Up @@ -1717,6 +1717,10 @@ const CUDASimulation::Config &CUDASimulation::getCUDAConfig() const {
visualiser::ModelVis CUDASimulation::getVisualisation() {
if (!visualisation) {
visualisation = std::make_shared<visualiser::ModelVisData>(*this);
// If visualisation is init after sim has been init ensure graphs are linked to vis
if (directed_graph_map.size()) {
visualisation->hookVis(visualisation, directed_graph_map);
}
}
return visualiser::ModelVis(visualisation, isSWIG);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,10 +583,12 @@ void CUDAEnvironmentDirectedGraphBuffers::syncDevice_async(detail::CUDAScatter&
if (has_changed) {
#ifdef FLAMEGPU_VISUALISATION
if (auto vis = visualisation.lock()) {
vis->visualiser->lockDynamicLinesMutex();
vis->rebuildEnvGraph(graph_description.name);
vis->visualiser->updateDynamicLine(std::string("graph_") + graph_description.name);
vis->visualiser->releaseDynamicLinesMutex();
if (vis->graphs.find(graph_description.name) != vis->graphs.end()) {
vis->visualiser->lockDynamicLinesMutex();
vis->rebuildEnvGraph(graph_description.name);
vis->visualiser->updateDynamicLine(std::string("graph_") + graph_description.name);
vis->visualiser->releaseDynamicLinesMutex();
}
}
#endif
}
Expand Down
4 changes: 3 additions & 1 deletion src/flamegpu/visualiser/ModelVis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ ModelVisData::ModelVisData(const flamegpu::CUDASimulation &_model)
, modelData(_model.getModelDescription()) { }

void ModelVisData::hookVis(std::shared_ptr<visualiser::ModelVisData>& vis, std::unordered_map<std::string, std::shared_ptr<detail::CUDAEnvironmentDirectedGraphBuffers>> &map) {
for (auto [key, buf] : map) {
buf->setVisualisation(vis);
}
for (auto [name, graph] : graphs) {
auto &graph_buffs = map.at(name);
graph_buffs->setVisualisation(vis);
graph->constructGraph(graph_buffs);
vis->rebuildEnvGraph(name);
}
Expand Down
Loading