-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Directed graphs can be defined on the Host and accessed and traversed on device (edges in/out of a given vertex). Vertices and Edges are referred to by vertex index on device, however a function exists to convert between vertex ID and vertex index. This approach is the compromise to minimise indirection whilst retaining usability. Graphs can be exported/imported to a JSON format compatible with d3.js via a dedicated HostAPI function. Tests added for all current functionality (C/Python/AgentPython). Also fixed a few GLM_ON build issues, likely a side effect of refactors prior to release. FLAMEGPU_ENABLE_ADVANCED_API CMake option has been added, this currently exposes a few additional (undocumented) HostAPI features such as a function that returns the CUDA stream handle.
- Loading branch information
Showing
53 changed files
with
8,325 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef INCLUDE_FLAMEGPU_IO_JSONGRAPHREADER_H_ | ||
#define INCLUDE_FLAMEGPU_IO_JSONGRAPHREADER_H_ | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "flamegpu/detail/cuda.cuh" | ||
|
||
namespace flamegpu { | ||
namespace detail { | ||
class CUDAEnvironmentDirectedGraphBuffers; | ||
} // namespace detail | ||
namespace io { | ||
|
||
class JSONGraphReader { | ||
public: | ||
/** | ||
* Imports the provided graph from the json "adjacency like" format, supported by NetworkX/d3.js | ||
* | ||
* @param filepath The path to load the graph from | ||
* @param directed_graph The graph buffers to import into | ||
* @param stream CUDA stream (required by directed_graph for synchronising device buffers) | ||
* | ||
* @throws exception::InvalidFilePath If the file cannot be opened for reading | ||
* @throws exception::RapidJSONError If JSON fails for any reason (e.g. structure does not match expectations) | ||
*/ | ||
static void loadAdjacencyLike(const std::string &filepath, const std::shared_ptr<detail::CUDAEnvironmentDirectedGraphBuffers> &directed_graph, cudaStream_t stream); | ||
}; | ||
|
||
} // namespace io | ||
} // namespace flamegpu | ||
|
||
#endif // INCLUDE_FLAMEGPU_IO_JSONGRAPHREADER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#ifndef INCLUDE_FLAMEGPU_IO_JSONGRAPHWRITER_H_ | ||
#define INCLUDE_FLAMEGPU_IO_JSONGRAPHWRITER_H_ | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "flamegpu/detail/cuda.cuh" | ||
|
||
namespace flamegpu { | ||
namespace detail { | ||
class CUDAEnvironmentDirectedGraphBuffers; | ||
} // namespace detail | ||
namespace io { | ||
|
||
class JSONGraphWriter { | ||
public: | ||
/** | ||
* Exports the provided graph in the json "adjacency like" format, supported by NetworkX/d3.js | ||
* | ||
* @param filepath The path to save the graph to | ||
* @param directed_graph The graph buffers to export | ||
* @param stream CUDA stream (required by directed_graph for synchronising device buffers) | ||
* @param pretty_print Whether JSON should be human readable (vs minified) | ||
* | ||
* @throws exception::InvalidFilePath If the file cannot be opened for writing | ||
* @throws exception::RapidJSONError If conversion to JSON fails for any reason | ||
*/ | ||
static void saveAdjacencyLike(const std::string &filepath, const std::shared_ptr<const detail::CUDAEnvironmentDirectedGraphBuffers> &directed_graph, cudaStream_t stream, bool pretty_print = true); | ||
}; | ||
|
||
} // namespace io | ||
} // namespace flamegpu | ||
|
||
#endif // INCLUDE_FLAMEGPU_IO_JSONGRAPHWRITER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#ifndef INCLUDE_FLAMEGPU_MODEL_ENVIRONMENTDIRECTEDGRAPHDATA_CUH_ | ||
#define INCLUDE_FLAMEGPU_MODEL_ENVIRONMENTDIRECTEDGRAPHDATA_CUH_ | ||
|
||
#include <string> | ||
#include <memory> | ||
|
||
#include "flamegpu/model/Variable.h" | ||
#include "flamegpu/model/ModelData.h" | ||
|
||
namespace flamegpu { | ||
|
||
class EnvironmentDescription; | ||
|
||
/** | ||
* This is the internal data store for EnvironmentDirectedGraphDescription | ||
* Users should only access that data stored within via an instance of EnvironmentDirectedGraphDescription | ||
*/ | ||
struct EnvironmentDirectedGraphData { | ||
friend class EnvironmentDescription; | ||
friend struct EnvironmentData; | ||
/** | ||
* Parent model | ||
*/ | ||
std::weak_ptr<const ModelData> model; | ||
/** | ||
* Holds all of the graphs's vertex property definitions | ||
*/ | ||
VariableMap vertexProperties{}; | ||
/** | ||
* Holds all of the graphs's edge property definitions | ||
*/ | ||
VariableMap edgeProperties{}; | ||
/** | ||
* Name of the graph, used to refer to the graph in many functions | ||
*/ | ||
std::string name; | ||
/** | ||
* Equality operator, checks whether EnvironmentDirectedGraphData hierarchies are functionally the same | ||
* @param rhs Right hand side | ||
* @returns True when directed graphs are the same | ||
* @note Instead compare pointers if you wish to check that they are the same instance | ||
*/ | ||
bool operator==(const EnvironmentDirectedGraphData& rhs) const; | ||
/** | ||
* Equality operator, checks whether EnvironmentDirectedGraphData hierarchies are functionally different | ||
* @param rhs Right hand side | ||
* @returns True when directed graphs are not the same | ||
* @note Instead compare pointers if you wish to check that they are not the same instance | ||
*/ | ||
bool operator!=(const EnvironmentDirectedGraphData& rhs) const; | ||
/** | ||
* Default copy constructor should not be used | ||
*/ | ||
explicit EnvironmentDirectedGraphData(const EnvironmentDirectedGraphData& other) = delete; | ||
|
||
protected: | ||
/** | ||
* Copy constructor | ||
* This is unsafe, should only be used internally, use clone() instead | ||
* @param model The parent model of the graph | ||
* @param other Other EnvironmentDirectedGraphData to copy data from | ||
*/ | ||
explicit EnvironmentDirectedGraphData(const std::shared_ptr<const ModelData>& model, const EnvironmentDirectedGraphData& other); | ||
/** | ||
* Normal constructor, only to be called by ModelDescription | ||
* @param parent The environment which owns the graph | ||
* @param graph_name Name of the graph | ||
*/ | ||
explicit EnvironmentDirectedGraphData(const std::shared_ptr<const EnvironmentData>& parent, const std::string& graph_name); | ||
}; | ||
} // namespace flamegpu | ||
|
||
#endif // INCLUDE_FLAMEGPU_MODEL_ENVIRONMENTDIRECTEDGRAPHDATA_CUH_ |
Oops, something went wrong.