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

RunPlanVector file IO #1230

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
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
3 changes: 1 addition & 2 deletions include/flamegpu/detail/Any.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct Any {
memcpy(ptr, _ptr, length);
}
template<typename T>
explicit Any(const T other)
explicit Any(const T &other)
: ptr(malloc(sizeof(T)))
, length(sizeof(T))
, type(typeid(T))
Expand Down Expand Up @@ -87,7 +87,6 @@ struct Any {
*/
const unsigned int elements;
};

} // namespace detail
} // namespace flamegpu

Expand Down
2 changes: 2 additions & 0 deletions include/flamegpu/flamegpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
#include "flamegpu/simulation/LogFrame.h"
#include "flamegpu/util/cleanup.h"
#include "flamegpu/io/Telemetry.h"
#include "flamegpu/io/JSONRunPlanWriter.h"
#include "flamegpu/io/JSONRunPlanReader.h"

// This include has no impact if FLAMEGPU_VISUALISATION is not defined
#include "flamegpu/visualiser/visualiser_api.h"
Expand Down
27 changes: 27 additions & 0 deletions include/flamegpu/io/JSONRunPlanReader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef INCLUDE_FLAMEGPU_IO_JSONRUNPLANREADER_H_
#define INCLUDE_FLAMEGPU_IO_JSONRUNPLANREADER_H_

#include <string>

#include "flamegpu/simulation/RunPlanVector.h"

namespace flamegpu {
class ModelDescription;
namespace io {

/**
* JSON format reader of RunPlanVector
*/
class JSONRunPlanReader {
public:
/**
* Loads and returns the specified JSON file if contains a RunPlanVector
* @param input_filepath Path on disk to read the file from
* @param model The model used to initialise the RunPlanVector
*/
static RunPlanVector load(const std::string &input_filepath, const ModelDescription &model);
};
} // namespace io
} // namespace flamegpu

#endif // INCLUDE_FLAMEGPU_IO_JSONRUNPLANREADER_H_
44 changes: 44 additions & 0 deletions include/flamegpu/io/JSONRunPlanWriter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef INCLUDE_FLAMEGPU_IO_JSONRUNPLANWRITER_H_
#define INCLUDE_FLAMEGPU_IO_JSONRUNPLANWRITER_H_

#include <memory>
#include <string>

#include "flamegpu/simulation/RunPlanVector.h"

namespace flamegpu {
namespace io {
/**
* JSON format writer of RunPlanVector
*/
class JSONRunPlanWriter {
/**
* Utility method for writing out the outer structure of a RunPlanVector
* @param writer An initialised RapidJSON writer.
* @param rpv RunPlanVector to be written
* @tparam T Should be rapidjson::Writer or rapidjson::PrettyWriter (one does not inherit the other)
*/
template <typename T>
static void writeCommon(std::unique_ptr<T> &writer, const RunPlanVector &rpv);
/**
* Utility method for writing out a single RunPlan
* @param writer An initialised RapidJSON writer.
* @param rp RunPlan to be writer
* @tparam T Should be rapidjson::Writer or rapidjson::PrettyWriter (one does not inherit the other)
*/
template <typename T>
static void writeRunPlan(std::unique_ptr<T> &writer, const RunPlan &rp);

public:
/**
* Exports the provided RunPlanVector in JSON format to the specified output_filepath
* @param rpv The RunPlanVector to be exported
* @param output_filepath Location on disk to export the file
* @param pretty Whether the exported JSON is "prettified" (true) or "minified" (false), defaults true.
*/
static void save(const RunPlanVector &rpv, const std::string &output_filepath, bool pretty = true);
};
} // namespace io
} // namespace flamegpu

#endif // INCLUDE_FLAMEGPU_IO_JSONRUNPLANWRITER_H_
2 changes: 1 addition & 1 deletion include/flamegpu/io/JSONStateReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace io {
class JSONStateReader : public StateReader {
public:
/**
* Loads the specified XML file to an internal data-structure
* Loads the specified JSON file to an internal data-structure
* @param input_file Path to file to be read
* @param model Model description to ensure file loaded is suitable
* @param verbosity Verbosity level to use during load
Expand Down
5 changes: 4 additions & 1 deletion include/flamegpu/model/ModelDescription.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#include "flamegpu/runtime/messaging/MessageBruteForce/MessageBruteForceHost.h"

namespace flamegpu {

namespace io {
class JSONRunPlanReader;
}
class AgentDescription;
class CAgentDescription;
class CLayerDescription;
Expand Down Expand Up @@ -39,6 +41,7 @@ class ModelDescription {
friend class LoggingConfig;
friend class XMLStateReader;
friend class JSONStateReader;
friend class io::JSONRunPlanReader;
public:
/**
* Constructor
Expand Down
8 changes: 8 additions & 0 deletions include/flamegpu/simulation/RunPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class CUDASimulation;
namespace io {
class JSONLogger;
class XMLLogger;
class JSONRunPlanWriter;
class JSONRunPlanReader_impl;
} // namespace io

/**
Expand All @@ -35,6 +37,12 @@ class RunPlan {
friend class CUDASimulation;
friend class io::JSONLogger;
friend class io::XMLLogger;
friend class io::JSONRunPlanWriter;
friend class io::JSONRunPlanReader_impl;
/**
* Internal constructor used during file-io
*/
explicit RunPlan(const std::shared_ptr<const ModelData> &model);

public:
/**
Expand Down
11 changes: 10 additions & 1 deletion include/flamegpu/simulation/RunPlanVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@


namespace flamegpu {

namespace io {
class JSONRunPlanReader;
class JSONRunPlanReader_impl;
}
class ModelDescription;
class EnvironmentDescription;

Expand All @@ -27,6 +30,12 @@ class RunPlanVector : private std::vector<RunPlan> {
friend class RunPlan;
friend class detail::AbstractSimRunner;
friend unsigned int CUDAEnsemble::simulate(const RunPlanVector& plans);
friend class io::JSONRunPlanReader;
friend class io::JSONRunPlanReader_impl;
/**
* Internal constructor used during file-io
*/
explicit RunPlanVector(const std::shared_ptr<const ModelData> &model, unsigned int initial_length);

public:
/**
Expand Down
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ SET(SRC_INCLUDE
${FLAMEGPU_ROOT}/include/flamegpu/flamegpu.h
${FLAMEGPU_ROOT}/include/flamegpu/io/StateReader.h
${FLAMEGPU_ROOT}/include/flamegpu/io/StateWriter.h
${FLAMEGPU_ROOT}/include/flamegpu/io/JSONRunPlanReader.h
${FLAMEGPU_ROOT}/include/flamegpu/io/JSONRunPlanWriter.h
${FLAMEGPU_ROOT}/include/flamegpu/io/JSONStateReader.h
${FLAMEGPU_ROOT}/include/flamegpu/io/JSONStateWriter.h
${FLAMEGPU_ROOT}/include/flamegpu/io/XMLStateReader.h
Expand Down Expand Up @@ -369,6 +371,8 @@ SET(SRC_FLAMEGPU
${FLAMEGPU_ROOT}/src/flamegpu/runtime/environment/HostEnvironment.cu
${FLAMEGPU_ROOT}/src/flamegpu/runtime/environment/HostEnvironmentDirectedGraph.cu
${FLAMEGPU_ROOT}/src/flamegpu/runtime/random/HostRandom.cu
${FLAMEGPU_ROOT}/src/flamegpu/io/JSONRunPlanReader.cpp
${FLAMEGPU_ROOT}/src/flamegpu/io/JSONRunPlanWriter.cpp
${FLAMEGPU_ROOT}/src/flamegpu/io/JSONStateReader.cu
${FLAMEGPU_ROOT}/src/flamegpu/io/JSONStateWriter.cu
${FLAMEGPU_ROOT}/src/flamegpu/io/StateReader.cu
Expand Down
Loading
Loading