Skip to content

Commit

Permalink
VertexMap test changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robadob committed Oct 10, 2023
1 parent f4e7d62 commit a2fd081
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class HostEnvironmentDirectedGraph {
template<typename T, flamegpu::size_type N = 0>
T getProperty(const std::string& property_name, unsigned int element_index) const;
template<typename T, flamegpu::size_type N>
std::array<T, N> getVertexProperty(const std::string& property_name) const;
std::array<T, N> getProperty(const std::string& property_name) const;
};
};
};
Expand Down Expand Up @@ -421,15 +421,15 @@ void HostEnvironmentDirectedGraph::VertexMap::Vertex::setProperty(const std::str
// Get index
const unsigned int vertex_index = directed_graph->getVertexIndex(vertex_id);
size_type element_ct = 1;
const T* rtn = const_cast<const detail::CUDAEnvironmentDirectedGraphBuffers *>(directed_graph.get())->getVertexPropertyBuffer<T>(property_name, element_ct, stream);
T* rtn = directed_graph->getVertexPropertyBuffer<T>(property_name, element_ct, stream);
rtn[vertex_index] = property_value;
}
template<typename T, flamegpu::size_type N>
void HostEnvironmentDirectedGraph::VertexMap::Vertex::setProperty(const std::string& property_name, flamegpu::size_type element_index, T property_value) {
// Get index
const unsigned int vertex_index = directed_graph->getVertexIndex(vertex_id);
size_type element_ct = N;
const T* rtn = const_cast<const detail::CUDAEnvironmentDirectedGraphBuffers*>(directed_graph.get())->getVertexPropertyBuffer<T>(property_name, element_ct, stream);
T* rtn = directed_graph->getVertexPropertyBuffer<T>(property_name, element_ct, stream);
if (element_index > element_ct) {
THROW exception::OutOfBoundsException("Element index %u is out of range %u, in VertexMap::Vertex::setProperty()\n",
element_index, element_ct);
Expand All @@ -441,8 +441,8 @@ void HostEnvironmentDirectedGraph::VertexMap::Vertex::setProperty(const std::str
// Get index
const unsigned int vertex_index = directed_graph->getVertexIndex(vertex_id);
size_type element_ct = N;
const T* rtn = const_cast<const detail::CUDAEnvironmentDirectedGraphBuffers*>(directed_graph.get())->getVertexPropertyBuffer<T>(property_name, element_ct, stream);
const std::array<T, N>* rtn2 = reinterpret_cast<const std::array<T, N>*>(rtn);
T* rtn = directed_graph->getVertexPropertyBuffer<T>(property_name, element_ct, stream);
std::array<T, N>* rtn2 = reinterpret_cast<std::array<T, N>*>(rtn);
rtn2[vertex_index] = property_value;
}
template<typename T>
Expand All @@ -466,7 +466,7 @@ T HostEnvironmentDirectedGraph::VertexMap::Vertex::getProperty(const std::string
return rtn[vertex_index * element_ct + element_index];
}
template<typename T, size_type N>
std::array<T, N> HostEnvironmentDirectedGraph::VertexMap::Vertex::getVertexProperty(const std::string& property_name) const {
std::array<T, N> HostEnvironmentDirectedGraph::VertexMap::Vertex::getProperty(const std::string& property_name) const {
// Get index
const unsigned int vertex_index = directed_graph->getVertexIndex(vertex_id);
size_type element_ct = N;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,9 @@ void CUDAEnvironmentDirectedGraphBuffers::setVertexID(unsigned int vertex_index,
if (vertex_index >= vertex_count) {
THROW exception::OutOfBoundsException("Vertex index exceeds bounds %u >= %u, "
"in CUDAEnvironmentDirectedGraphBuffers::setVertexID()\n", vertex_index, vertex_count);
} else if (vertex_id == ID_NOT_SET) {
THROW exception::IDOutOfBounds("Vertex ID of %u is not valid, "
"in CUDAEnvironmentDirectedGraphBuffers::setVertexID()\n", ID_NOT_SET);
}
// Purge old vertex ID from host map
auto& vb = vertex_buffers.at(ID_VARIABLE_NAME);
Expand All @@ -601,7 +604,7 @@ void CUDAEnvironmentDirectedGraphBuffers::setVertexID(unsigned int vertex_index,
}
unsigned int CUDAEnvironmentDirectedGraphBuffers::getVertexIndex(id_t vertex_id) const {
const auto find = h_vertex_index_map.find(vertex_id);
if (find != h_vertex_index_map.end()) {
if (find == h_vertex_index_map.end()) {
THROW exception::InvalidID("No vertex found with ID %u, in CUDAEnvironmentDirectedGraphBuffers::getVertexIndex()\n", vertex_id);
}
return find->second;
Expand Down Expand Up @@ -649,11 +652,15 @@ unsigned int CUDAEnvironmentDirectedGraphBuffers::getEdgeIndex(id_t src_vertex_i
}

unsigned int CUDAEnvironmentDirectedGraphBuffers::createIfNotExistVertex(id_t vertex_id, const cudaStream_t stream) {
if (vertex_id == ID_NOT_SET) {
THROW exception::IDOutOfBounds("Vertex ID of %u is not valid, "
"in CUDAEnvironmentDirectedGraphBuffers::setVertexID()\n", ID_NOT_SET);
}
const auto it = h_vertex_index_map.find(vertex_id);
if (it != h_vertex_index_map.end()) {
return it->second;
}
if (h_vertex_index_map.size() + 1 < vertex_count) {
if (h_vertex_index_map.size() < vertex_count) {
const unsigned int vertex_index = static_cast<unsigned int>(h_vertex_index_map.size());
h_vertex_index_map.emplace(vertex_id, vertex_index);
// Update vertex's ID in buffer
Expand Down
Loading

0 comments on commit a2fd081

Please sign in to comment.