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

Add brain graph generator. #50

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
23 changes: 22 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ option(KAGEN_USE_SPARSEHASH "Build with Google Sparsehash. If turned off, fall b
option(KAGEN_USE_FAST_MATH "Use -ffast-math." OFF)
option(KAGEN_USE_MKL "Build with Intel MKL random generator." OFF)
option(KAGEN_USE_XXHASH "Build with xxHash. If turned off, path permutation will not be available." ON)
option(KAGEN_ENABLE_BRAIN_GRAPH "Enable support for the RELeARN brain graph generator. Requires an additional dependency." OFF)


option(KAGEN_WARNINGS_ARE_ERRORS "Make compiler warnings compiler errors." OFF)

Expand Down Expand Up @@ -193,7 +195,26 @@ if (KAGEN_USE_MKL)
else ()
message(STATUS "MKL requested but not found, building without MKL")
endif ()
endif ()
endif ()

###############################################################################
# RELeARN brain graph generator
###############################################################################

if (KAGEN_ENABLE_BRAIN_GRAPH)
set(CMAKE_CXX_STANDARD 20)
FetchContent_Declare(
relearn
GIT_REPOSITORY https://github.com/KarlsruheGraphGeneration/RELeARN.git
GIT_TAG 9a448d3
SOURCE_SUBDIR relearn
SYSTEM
)
FetchContent_MakeAvailable(relearn)
list(APPEND KAGEN_LINK_LIBRARIES relearn_lib)
add_definitions(-DKAGEN_ENABLE_BRAIN_GRAPH)

endif()

################################################################################

Expand Down
13 changes: 13 additions & 0 deletions app/KaGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*
* All rights reserved. Published under the BSD-2 license in the LICENSE file.
******************************************************************************/
#include "kagen.h"
#include "kagen/context.h"
#include "kagen/definitions.h"
#include "kagen/external_memory_facade.h"
Expand Down Expand Up @@ -428,6 +429,18 @@ This is mostly useful for experimental graph generators or when using KaGen to l
cmd->add_option("--cols-per-pe", config.image_mesh.cols_per_pe, "Number of columns assigned to the same PE");
cmd->add_option("--rows-per-pe", config.image_mesh.rows_per_pe, "Number of rows assigned to the same PE");
}
{ // BRAIN
auto* cmd = app.add_subcommand("brain", "R-MAT Graph");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

R-MAT?

cmd->callback([&] { config.generator = GeneratorType::BRAIN; });
add_option_n(cmd);
cmd->add_option("--synapse-creation-model", config.brain.algorithm)
->transform(CLI::CheckedTransformer(GetBrainSynapseCreationModelMap()));
cmd->add_option("--gaussian-mu", config.brain.gaussian_mu);
cmd->add_option("--gaussian-sigma", config.brain.gaussian_sigma);
cmd->add_option("--simulation-steps", config.brain.simulation_steps);
cmd->add_option("--synapses-ub", config.brain.synapses_ub);
cmd->add_option("--synapses-lb", config.brain.synapses_lb);
}

{ // Graph from file
auto* cmd =
Expand Down
4 changes: 4 additions & 0 deletions kagen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ if (NOT SAMPLING_HAVE_MKL)
list(FILTER KAGEN_SOURCE_FILES EXCLUDE REGEX "mkl.*")
endif ()

if (NOT KAGEN_ENABLE_BRAIN_GRAPH)
list(FILTER KAGEN_SOURCE_FILES EXCLUDE REGEX "brain.*")
endif ()

add_library(kagen OBJECT ${KAGEN_SOURCE_FILES})
target_compile_features(kagen PRIVATE cxx_std_17)
target_link_libraries(kagen PUBLIC ${KAGEN_LINK_LIBRARIES})
Expand Down
26 changes: 26 additions & 0 deletions kagen/context.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "kagen/context.h"

#include "kagen/definitions.h"
#include "kagen/kagen.h"

#include <mpi.h>

Expand Down Expand Up @@ -166,6 +167,16 @@ std::ostream& operator<<(std::ostream& out, const PGeneratorConfig& config) {
<< (config.image_mesh.rows_per_pe == 0 ? "auto" : std::to_string(config.image_mesh.rows_per_pe))
<< "\n";
break;
case kagen::GeneratorType::BRAIN:
out << " Number of vertices: " << config.n << "\n";
out << " Number of neurons per rank: " << config.brain.num_neurons_per_rank << "\n";
out << " Synapses lower bound: " << config.brain.synapses_lb << "\n";
out << " Synapses upper bound: " << config.brain.synapses_ub << "\n";
out << " Simulation steps: " << config.brain.simulation_steps << "\n";
out << " Algorithm: " << config.brain.algorithm << "\n";
out << " Gaussian sigma: " << config.brain.gaussian_sigma << "\n";
out << " Gaussian mu: " << config.brain.gaussian_mu << "\n";
break;

case GeneratorType::FILE:
out << " Input file: " << config.input_graph.filename << "\n";
Expand Down Expand Up @@ -375,6 +386,21 @@ PGeneratorConfig CreateConfigFromString(const std::string& options_str, PGenerat
throw std::runtime_error("invalid weight model name");
}
config.image_mesh.weight_model = weight_model_it->second;

} else if (config.generator == GeneratorType::BRAIN) {
const auto synapse_creation_models = GetBrainSynapseCreationModelMap();
const std::string synapse_creation_model_name =
get_string_or_default("synapse_creation_model", StringifyEnum(config.brain.algorithm));
const auto it = synapse_creation_models.find(synapse_creation_model_name);
if (it == synapse_creation_models.end()) {
throw std::runtime_error("invalid synapse creation model name");
}
config.brain.algorithm = it->second;
config.brain.gaussian_mu = get_hpfloat_or_default("gaussian_mu", config.brain.gaussian_mu);
config.brain.gaussian_sigma = get_hpfloat_or_default("gaussian_sigma", config.brain.gaussian_sigma);
config.brain.simulation_steps = get_sint_or_default("simulation_steps", config.brain.simulation_steps);
config.brain.synapses_lb = get_hpfloat_or_default("synapses_lb", config.brain.synapses_lb);
config.brain.synapses_ub = get_hpfloat_or_default("synapses_ub", config.brain.synapses_ub);
} else if (config.generator == GeneratorType::FILE) {
const std::string filename = get_string_or_default("filename");
if (filename.empty()) {
Expand Down
13 changes: 13 additions & 0 deletions kagen/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ struct ImageMeshConfig {
SInt rows_per_pe = 0;
};

struct BrainConfig {
std::uint64_t num_neurons_per_rank;
double synapses_ub = 5.0;
double synapses_lb = 5.0;
std::uint32_t simulation_steps = 1001;
BrainSynapseCreationModel algorithm = BrainSynapseCreationModel::BARNES_HUT;
double gaussian_sigma = 2.0;
double gaussian_mu = 0.0;
};

struct InputGraphConfig {
std::string filename = "";
FileFormat format = FileFormat::EXTENSION;
Expand Down Expand Up @@ -144,6 +154,9 @@ struct PGeneratorConfig {
// Image mesh generator settings
ImageMeshConfig image_mesh{};

// Brain generator settings
BrainConfig brain{};

// Settings for the static graph pseudo-generator
InputGraphConfig input_graph{};

Expand Down
14 changes: 14 additions & 0 deletions kagen/factories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@
#include "kagen/generators/path/path_directed.h"
#include "kagen/generators/rmat/rmat.h"

#include <memory>

#ifdef KAGEN_CGAL_FOUND
#include "kagen/generators/geometric/delaunay.h"
#endif // KAGEN_CGAL_FOUND

#ifdef KAGEN_ENABLE_BRAIN_GRAPH
#include "kagen/generators/brain/brain.h"
#endif

namespace kagen {
std::unique_ptr<GeneratorFactory> CreateGeneratorFactory(const GeneratorType type) {
switch (type) {
Expand Down Expand Up @@ -79,6 +85,14 @@ std::unique_ptr<GeneratorFactory> CreateGeneratorFactory(const GeneratorType typ

case GeneratorType::FILE:
return std::make_unique<FileGraphFactory>();

case GeneratorType::BRAIN:
#ifdef KAGEN_ENABLE_BRAIN_GRAPH
return std::make_unique<BrainFactory>();
#else
// throw exception after switch
break;
#endif
}

throw std::runtime_error("invalid graph generator type");
Expand Down
Loading