Skip to content
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
3 changes: 1 addition & 2 deletions Simulator/Connections/Connections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ void Connections::createEdgeIndexMap()

/// Update the connections status in every epoch.
///
/// @param vertices The vertex list to search from.
/// @return true if successful, false otherwise.
bool Connections::updateConnections(AllVertices &vertices)
bool Connections::updateConnections()
{
return false;
}
Expand Down
3 changes: 1 addition & 2 deletions Simulator/Connections/Connections.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ class Connections {

/// Update the connections status in every epoch.
///
/// @param vertices The vertex list to search from.
/// @return true if successful, false otherwise.
virtual bool updateConnections(AllVertices &vertices);
virtual bool updateConnections();

/// Cereal serialization method
template <class Archive> void serialize(Archive &archive);
Expand Down
3 changes: 2 additions & 1 deletion Simulator/Connections/NG911/Connections911.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void Connections911::printParameters() const

#if !defined(USE_GPU)
/// Update the connections status in every epoch.
bool Connections911::updateConnections(AllVertices &vertices)
bool Connections911::updateConnections()
{
// Only run on the first epoch
if (Simulator::getInstance().getCurrentStep() != 1) {
Expand All @@ -73,6 +73,7 @@ bool Connections911::updateConnections(AllVertices &vertices)
// Record old type map
int numVertices = Simulator::getInstance().getTotalVertices();
Layout &layout = Simulator::getInstance().getModel().getLayout();
AllVertices &vertices = layout.getVertices();
oldTypeMap_ = layout.vertexTypeMap_;

// Erase PSAPs
Expand Down
3 changes: 1 addition & 2 deletions Simulator/Connections/NG911/Connections911.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ class Connections911 : public Connections {
/// Update the connections status in every epoch.
/// Uses the parent definition for USE_GPU
///
/// @param vertices The Vertex list to search from.
/// @return true if successful, false otherwise.
virtual bool updateConnections(AllVertices &vertices) override;
virtual bool updateConnections() override;

/// Finds the outgoing edge from the given vertex to the Responder closest to
/// the emergency call location
Expand Down
6 changes: 4 additions & 2 deletions Simulator/Connections/Neuro/ConnGrowth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,12 @@ void ConnGrowth::printParameters() const

/// Update the connections status in every epoch.
///
/// @param vertices The vertex list to search from.
/// @return true if successful, false otherwise.
bool ConnGrowth::updateConnections(AllVertices &vertices)
bool ConnGrowth::updateConnections()
{
Layout &layout = Simulator::getInstance().getModel().getLayout();
AllVertices &vertices = layout.getVertices();

// Update Connections data
updateConns(vertices);

Expand Down
3 changes: 1 addition & 2 deletions Simulator/Connections/Neuro/ConnGrowth.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ class ConnGrowth : public Connections {

/// Update the connections status in every epoch.
///
/// @param vertices The vertex list to search from.
/// @return true if successful, false otherwise.
virtual bool updateConnections(AllVertices &vertices) override;
virtual bool updateConnections() override;

/// Cereal serialization method
template <class Archive> void serialize(Archive &archive);
Expand Down
10 changes: 8 additions & 2 deletions Simulator/Connections/Neuro/ConnGrowth_d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ void ConnGrowth::updateEdgesWeights(int numVertices, AllVertices &vertices, AllE

// copy device synapse count to host memory
edges.copyDeviceEdgeCountsToHost(allEdgesDevice);
// copy device synapse summation coordinate to host memory
dynamic_cast<AllSpikingSynapses &>(edges).copyDeviceEdgeSumIdxToHost(allEdgesDevice);

// copy device synapse summation coordinate and weights to host memory
AllSpikingSynapses &synapses = dynamic_cast<AllSpikingSynapses &>(edges);
synapses.copyDeviceEdgeSumIdxToHost(allEdgesDevice);
synapses.copyDeviceEdgeWeightsToHost(allEdgesDevice);

// output weight matrix every epoch
synapses.outputWeights(simulator.getCurrentStep());
}
11 changes: 11 additions & 0 deletions Simulator/Connections/Neuro/ConnStatic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,14 @@ void ConnStatic::loadParameters()
void ConnStatic::printParameters() const
{
}

/// Output the weights matrix after every epoch.
///
/// @return true if successful, false otherwise.
bool ConnStatic::updateConnections()
{
AllNeuroEdges &synapses = dynamic_cast<AllNeuroEdges &>(*edges_);
synapses.outputWeights(Simulator::getInstance().getCurrentStep());

return true;
}
5 changes: 5 additions & 0 deletions Simulator/Connections/Neuro/ConnStatic.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ class ConnStatic : public Connections {
return destVertexIndexCurrentEpoch_;
}

/// Output the weights matrix after every epoch.
///
/// @return true if successful, false otherwise.
virtual bool updateConnections() override;

/// Cereal serialization method
template <class Archive> void serialize(Archive &archive);

Expand Down
2 changes: 1 addition & 1 deletion Simulator/Core/CPUModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void CPUModel::advance()
void CPUModel::updateConnections()
{
// Update Connections data
if (connections_->updateConnections(layout_->getVertices())) {
if (connections_->updateConnections()) {
connections_->updateEdgesWeights();
// create edge inverse map
connections_->createEdgeIndexMap();
Expand Down
2 changes: 1 addition & 1 deletion Simulator/Core/GPUModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ void GPUModel::updateConnections()
vertices.copyFromDevice(allVerticesDevice_);

// Update Connections data
if (connections_->updateConnections(vertices)) {
if (connections_->updateConnections()) {
connections_->updateEdgesWeights(Simulator::getInstance().getTotalVertices(), vertices, edges,
allVerticesDevice_, allEdgesDevice_, getLayout());
// create edge index map
Expand Down
3 changes: 3 additions & 0 deletions Simulator/Edges/Neuro/AllNeuroEdges.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class AllNeuroEdges : public AllEdges {
/// Cereal serialization method
template <class Archive> void serialize(Archive &archive);

/// Output weights and srcIndex to xml
virtual void outputWeights(int epochNum) = 0;

protected:
/// Setup the internal structure of the class (allocate memories and initialize them).
///
Expand Down
58 changes: 58 additions & 0 deletions Simulator/Edges/Neuro/AllSpikingSynapses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,61 @@ void AllSpikingSynapses::printSynapsesProps() const
}
}
}

string vectorToXML(const vector<BGFLOAT> &matrix, int rows, int cols, const string &name)
{
ostringstream os;
os << "<" << name << " rows=\"" << rows << "\" columns=\"" << cols << "\">\n";

int index = 0;
for_each(matrix.begin(), matrix.end(), [&](BGFLOAT value) mutable {
os << " <value" << index << ">" << value << "</value" << index << ">\n";
index++;
});

os << "</" << name << ">\n";
return os.str();
}

string vectorToXML(const vector<int> &matrix, int rows, int cols, const string &name)
{
ostringstream os;
os << "<" << name << " rows=\"" << rows << "\" columns=\"" << cols << "\">\n";

int index = 0;
for_each(matrix.begin(), matrix.end(), [&](int value) mutable {
os << " <value" << index << ">" << value << "</value" << index << ">\n";

index++;
});

os << "</" << name << ">\n";
return os.str();
}

void AllSpikingSynapses::outputWeights(int epochNum)
{
const std::string filename = "./Output/Results/weights-epoch-" + std::to_string(epochNum)
+ ".xml"; // Hardcoded filename
int vertexCount = Simulator::getInstance().getTotalVertices();

ofstream outFile(filename);
if (!outFile) {
cerr << "Error: Unable to open file " << filename << endl;
cerr << "Error details: " << strerror(errno) << endl;
return;
}

int maxEdges = Simulator::getInstance().getMaxEdgesPerVertex();

string wContent = vectorToXML(W_, vertexCount, maxEdges, "WeightMatrix");
string srcContent = vectorToXML(sourceVertexIndex_, vertexCount, maxEdges, "SourceVertexIndex");

outFile << "<Graph>\n";
outFile << wContent;
outFile << srcContent;
outFile << "</Graph>";
outFile.close();

cout << "Weights matrix output to: " << filename << endl;
}
9 changes: 9 additions & 0 deletions Simulator/Edges/Neuro/AllSpikingSynapses.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class AllSpikingSynapses : public AllNeuroEdges {
/// Cereal serialization method
template <class Archive> void serialize(Archive &archive);

/// Output weights and srcIndex to xml
virtual void outputWeights(int epochNum);

protected:
/// Setup the internal structure of the class (allocate memories and initialize them).
///
Expand Down Expand Up @@ -196,6 +199,12 @@ class AllSpikingSynapses : public AllNeuroEdges {
/// @param allEdgesDevice GPU address of the allEdges struct on device memory.
void copyDeviceEdgeSumIdxToHost(void *allEdgesDevice);

/// Get weights matrix in AllEdges struct on device memory.
///
/// @param allEdgesDevice GPU address of the AllSpikingSynapsesDeviceProperties struct
/// on device memory.
virtual void copyDeviceEdgeWeightsToHost(void *allEdgesDevice);

protected:
/// Allocate GPU memories to store all synapses' states,
/// and copy them from host to GPU memory.
Expand Down
22 changes: 22 additions & 0 deletions Simulator/Edges/Neuro/AllSpikingSynapses_d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,28 @@ void AllSpikingSynapses::copyDeviceEdgeCountsToHost(void *allEdgesDevice)
//allEdges.countVertices_ = 0;
}

/// Get weights matrix in AllEdges struct on device memory.
///
/// @param allEdgesDevice GPU address of the AllSpikingSynapsesDeviceProperties struct
/// on device memory.
void AllSpikingSynapses::copyDeviceEdgeWeightsToHost(void *allEdgesDevice)
{
AllSpikingSynapsesDeviceProperties allEdgesDeviceProps;

int numVertices = Simulator::getInstance().getTotalVertices();
BGSIZE maxTotalSynapses = Simulator::getInstance().getMaxEdgesPerVertex() * numVertices;

HANDLE_ERROR(cudaMemcpy(&allEdgesDeviceProps, allEdgesDevice,
sizeof(AllSpikingSynapsesDeviceProperties), cudaMemcpyDeviceToHost));

// std::cout << "size: " << vertexCount * vertexCount * sizeof(BGFLOAT) << std::endl;
// std::cout << "W_.data(): " << W_.data() << std::endl;
// std::cout << "allEdgesDeviceProps.W_: " << allEdgesDeviceProps.W_ << std::endl;

HANDLE_ERROR(cudaMemcpy(W_.data(), allEdgesDeviceProps.W_, maxTotalSynapses * sizeof(BGFLOAT),
cudaMemcpyDeviceToHost));
}

/// Get summationCoord and in_use in AllEdges struct on device memory.
///
/// @param allEdgesDevice GPU address of the AllSpikingSynapsesDeviceProperties struct
Expand Down
17 changes: 17 additions & 0 deletions Tools/XMLToGraphML/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# XML to GraphML Converter

## Overview
This script was created to parse the weight matrix output from neuro simulations and generate a graphml file for input into subsequent simulations.

## `getGraphEdges`
* Must be run with Python3.9
* Takes a weight matrix xml file and existing graphml file as input
* Adds the edge weights to the graphml file

## Contributors
- Vanessa Arndorfer





Loading