generated from DARMA-tasking/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3: Implement and bind block data model class
- Loading branch information
1 parent
0d4e943
commit 5322a35
Showing
8 changed files
with
269 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include "block.h" | ||
|
||
namespace vt { namespace tv { | ||
|
||
Block::Block(uint64_t b_id, | ||
uint64_t h_id, | ||
double size, | ||
std::unordered_set<uint64_t> o_ids) | ||
: index(b_id) | ||
, home_id(h_id) | ||
, size(size) | ||
, attached_object_ids(o_ids) | ||
{} | ||
|
||
uint64_t Block::detach_object_id(uint64_t o_id) { | ||
try { | ||
this->attached_object_ids.erase(o_id); | ||
} | ||
catch(const nb::type_error e) { | ||
std::cerr << e.what() << '\n'; | ||
} | ||
return this->attached_object_ids.size(); | ||
} | ||
|
||
void Block::attach_object_id(uint64_t o_id) { | ||
this->attached_object_ids.insert(o_id); | ||
} | ||
|
||
|
||
std::string Block::to_string() const { | ||
std::string out; | ||
out += "Block id: " + std::to_string(this->get_id()) | ||
+ ", home id: " + std::to_string(this->get_home_id()) | ||
+ ", size: " + std::to_string(this->get_size()) | ||
+ ", object ids: {"; | ||
for (const auto &elem : this->get_attached_object_ids()) { | ||
out += std::to_string(elem) + " "; | ||
} | ||
out += "}"; | ||
return out; | ||
} | ||
|
||
NB_MODULE(block, m) { | ||
nb::class_<Block>(m, "Block") | ||
.def(nb::init<uint64_t, uint64_t, double, std::unordered_set<uint64_t>>()) | ||
.def("get_id", &Block::get_id) | ||
.def("get_home_id", &Block::get_home_id) | ||
.def("get_size", &Block::get_size) | ||
.def("detach_object_id", &Block::detach_object_id) | ||
.def("attach_object_id", &Block::attach_object_id) | ||
.def("to_string", &Block::to_string); | ||
} | ||
|
||
}} /* end namesapce vt::tv */ |
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,62 @@ | ||
#if !defined INCLUDED_VT_TV_API_BLOCK_H | ||
#define INCLUDED_VT_TV_API_BLOCK_H | ||
|
||
#include <nanobind/nanobind.h> | ||
#include <nanobind/stl/string.h> | ||
#include <nanobind/stl/list.h> | ||
#include <nanobind/stl/map.h> | ||
#include <nanobind/stl/unordered_set.h> | ||
#include <nanobind/operators.h> | ||
|
||
#include <string> | ||
#include <iostream> | ||
#include <list> | ||
#include <map> | ||
#include <format> | ||
#include <unordered_set> | ||
|
||
namespace nb = nanobind; | ||
|
||
namespace vt { namespace tv { | ||
|
||
/** | ||
* A class representing a memory block with footprint and home. | ||
*/ | ||
struct Block | ||
{ | ||
private: | ||
uint64_t index; | ||
uint64_t home_id; | ||
double size = 0; | ||
std::unordered_set<uint64_t> attached_object_ids; | ||
public: | ||
uint64_t get_id() const { return this->index; }; | ||
uint64_t get_home_id() const { return this->home_id; }; | ||
double get_size() const { return this->size; }; | ||
std::unordered_set<uint64_t> get_attached_object_ids() const { return this->attached_object_ids; }; | ||
|
||
uint64_t detach_object_id(uint64_t); | ||
void attach_object_id(uint64_t); | ||
|
||
std::string to_string() const; | ||
|
||
friend std::ostream & operator << (std::ostream &out, const Block &b); | ||
|
||
Block(uint64_t, uint64_t, double, std::unordered_set<uint64_t>); | ||
~Block() = default; | ||
}; | ||
|
||
std::ostream & operator << (std::ostream &out, const Block &b) | ||
{ | ||
out << "Block id: " << b.get_id() << ", home id: " << b.get_home_id() | ||
<< ", size: " << b.get_size() << ", object ids: "; | ||
for (const auto &elem : b.get_attached_object_ids()) { | ||
out << elem << " "; | ||
} | ||
out << std::endl; | ||
return out; | ||
} | ||
|
||
}} /* end namesapce vt::tv */ | ||
|
||
#endif /*INCLUDED_VT_TV_API_BLOCK_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,14 @@ | ||
import my_ext | ||
import block | ||
|
||
circle1 = my_ext.Circle("Red") | ||
circle1.what_color() | ||
circle1.render() # exports test.png | ||
|
||
b = block.Block(2,3,5.4,set({1,2,3,4})) | ||
print(b.to_string()) | ||
print(b.attach_object_id(42)) | ||
# trying to attach an object id that is not an int actually throws a python TypeError | ||
print(b.to_string()) | ||
b.detach_object_id(42) | ||
print(b.to_string()) |
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,42 @@ | ||
#include "visualizer.h" | ||
|
||
Visualizer::Visualizer( | ||
std::list<std::string> qoi_request, | ||
bool continuous_object_qoi, | ||
std::list<Phase> phases, | ||
std::list<std::string> grid_size, | ||
double object_jitter, | ||
std::string output_dir, | ||
std::string output_file_stem, | ||
std::map<std::string, std::string> distributions, | ||
std::map<std::string, std::string> statistics, | ||
double resolution | ||
) | ||
: qoi_request(qoi_request) | ||
, continuous_object_qoi(continuous_object_qoi) | ||
, phases(phases) | ||
, grid_size(grid_size) | ||
, object_jitter(object_jitter) | ||
, output_dir(output_dir) | ||
, output_file_stem(output_file_stem) | ||
, distributions(distributions) | ||
, statistics(statistics) | ||
, resolution(resolution) | ||
{} | ||
|
||
|
||
NB_MODULE(visualizer, m) { | ||
nb::class_<Phase>(m, "phase") | ||
.def(nb::init<>()); | ||
nb::class_<Visualizer>(m, "Visualizer") | ||
.def(nb::init<std::list<std::string>, | ||
bool, | ||
std::list<Phase>, | ||
std::list<std::string>, | ||
double, | ||
std::string, | ||
std::string, | ||
std::map<std::string, std::string>, | ||
std::map<std::string, std::string>, | ||
double>()); | ||
} |
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,76 @@ | ||
#if !defined INCLUDED_VT_TV_VISUALIZER_H | ||
#define INCLUDED_VT_TV_VISUALIZER_H | ||
|
||
// #include <vtkActor.h> | ||
#include <vtkRenderWindow.h> | ||
#include <vtkRenderWindowInteractor.h> | ||
#include <vtkRenderer.h> | ||
#include <vtkNamedColors.h> | ||
#include <vtkNew.h> | ||
#include <vtkProperty.h> | ||
#include <vtkCamera.h> | ||
#include <vtkPolyData.h> | ||
#include <vtkPolyDataMapper.h> | ||
#include <vtkDoubleArray.h> | ||
#include <vtkPointData.h> | ||
#include <vtkGlyphSource2D.h> | ||
#include <vtkGlyph2D.h> | ||
#include <vtkTransform.h> | ||
#include <vtkTransformPolyDataFilter.h> | ||
#include <vtkColorTransferFunction.h> | ||
// #include <vtkScalarBarActor.h> | ||
#include <vtkTextProperty.h> | ||
#include <vtkArrayCalculator.h> | ||
#include <vtkThresholdPoints.h> | ||
#include <vtkWindowToImageFilter.h> | ||
#include <vtkPNGWriter.h> | ||
#include <vtkRegularPolygonSource.h> | ||
|
||
#include <Python.h> | ||
|
||
#include <nanobind/nanobind.h> | ||
#include <nanobind/stl/string.h> | ||
#include <nanobind/stl/list.h> | ||
#include <nanobind/stl/map.h> | ||
|
||
#include <string> | ||
#include <iostream> | ||
#include <list> | ||
#include <map> | ||
|
||
namespace nb = nanobind; | ||
|
||
struct Phase { | ||
uint64_t n_objects = 0; | ||
}; | ||
|
||
struct Visualizer { | ||
private: | ||
std::list<std::string> qoi_request; | ||
bool continuous_object_qoi; | ||
std::list<Phase> phases; | ||
std::list<std::string> grid_size; | ||
double object_jitter = 0; | ||
std::string output_dir = "."; | ||
std::string output_file_stem = "LBAF_out"; | ||
std::map<std::string, std::string> distributions; | ||
std::map<std::string, std::string> statistics; | ||
double resolution = 1; | ||
|
||
public: | ||
Visualizer( | ||
std::list<std::string>, | ||
bool, | ||
std::list<Phase>, | ||
std::list<std::string>, | ||
double, | ||
std::string, | ||
std::string, | ||
std::map<std::string, std::string>, | ||
std::map<std::string, std::string>, | ||
double | ||
); | ||
|
||
}; | ||
|
||
#endif /*INCLUDED_VT_TV_VISUALIZER_H*/ |