Skip to content

Commit

Permalink
Fix and polish Raw Mechanism Support in ModCC and arbor-build-catalog…
Browse files Browse the repository at this point in the history
…ue (#2292)

- Add `--raw` to `modcc`'s catalogue processing.
- Check `gpu == none` in `arbor-build-catalogue`
- Fix some cheap signed/unsigned warnings
  • Loading branch information
thorstenhater authored Jul 30, 2024
1 parent 927200d commit ddb7e70
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 15 deletions.
4 changes: 4 additions & 0 deletions mechanisms/BuildModules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ function("make_catalogue_standalone")
endif()
endforeach()

foreach(mech ${MK_CAT_CXX})
set(mk_cat_modcc_flags -r ${mech} ${mk_cat_modcc_flags})
endforeach()

add_custom_command(OUTPUT ${catalogue_${MK_CAT_NAME}_source}
DEPENDS ${catalogue_${MK_CAT_NAME}_mods}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
Expand Down
20 changes: 14 additions & 6 deletions modcc/modcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ auto key_by_value(const Map& map, const V& v) -> decltype(map.begin()->first) {
struct Options {
std::string outprefix;
std::vector<std::string> modfiles;
std::vector<std::string> rawfiles;
std::string modulename;
std::string catalogue;
bool verbose = false;
Expand Down Expand Up @@ -140,6 +141,7 @@ const char* usage_str =
"-S|--simd-abi [Override SIMD ABI in generated code. Use /n suffix to force SIMD width to be size n. Examples: 'avx2', 'native/4', ...]\n"
"-V|--verbose [Toggle verbose mode]\n"
"-A|--analyse [Toggle analysis mode]\n"
"-r|--raw [Add raw (CXX) mechanisms]\n"
"-T|--trace-codegen [Leave trace marks in generated source]\n"
"<filenames> [Files to be compiled]\n";

Expand Down Expand Up @@ -172,6 +174,7 @@ int main(int argc, char **argv) {
{ popt.simd, "-S", "--simd-abi" },
{ to::set(popt.trace_codegen), to::flag, "-T", "--trace-codegen"},
{ to::action(add_target, to::keywords(targetKindMap)), "-t", "--target" },
{ to::push_back(opt.rawfiles), "-r", "--raw"},
{ to::action(help), to::flag, to::exit, "-h", "--help" }
};

Expand Down Expand Up @@ -290,24 +293,29 @@ int main(int argc, char **argv) {
}

if (!opt.catalogue.empty()) {
std::vector<std::string> names = {};
for (const auto& [mod, prefix]: modules) names.push_back(mod);
for (const auto& mod: opt.rawfiles) names.push_back(mod);

const auto ns = std::regex_replace(popt.cpp_namespace, std::regex{"::"}, "_");
{
std::ofstream out(outdir / (opt.catalogue + "_catalogue.cpp"));
out << "// Automatically generated by modcc\n"
auto fn = outdir / (opt.catalogue + "_catalogue.cpp");
std::ofstream out(fn);
out << "// Automatically generated by modcc\n"
"\n"
"#include <arbor/mechanism_abi.h>\n"
"\n";

for (const auto& [mod, prefix]: modules) out << fmt::format("#include \"{}.hpp\"\n", mod);
for (const auto& mod: names) out << fmt::format("#include \"{}.hpp\"\n", mod);

out << "\n"
"#ifdef STANDALONE\n"
"extern \"C\" {\n"
" [[gnu::visibility(\"default\")]] const void* get_catalogue(int* n) {\n"
<< fmt::format(" *n = {0};\n"
" static arb_mechanism cat[{0}] = {{\n",
opt.modfiles.size());
for (const auto& [mod, prefix]: modules) {
names.size());
for (const auto& mod: names) {
out << fmt::format(" make_{}_{}(),\n", ns, mod);
}
out << " };\n"
Expand All @@ -326,7 +334,7 @@ int main(int argc, char **argv) {
"mechanism_catalogue build_{0}_catalogue() {{\n"
" mechanism_catalogue cat;\n",
opt.catalogue);
for (const auto& [mod, prefix]: modules) {
for (const auto& mod: names) {
out << fmt::format(" {{\n"
" auto mech = make_{}_{}();\n"
" auto ty = mech.type();\n"
Expand Down
4 changes: 2 additions & 2 deletions python/test/unit/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def num_cells(self):
def cell_kind(self, _):
return A.cell_kind.cable

def cell_description(self, gid):
def cell_description(self, _):
tree = A.segment_tree()
s = tree.append(A.mnpos, A.mpoint(-3, 0, 0, 3), A.mpoint(3, 0, 0, 3), tag=1)
_ = tree.append(s, A.mpoint(3, 0, 0, 1), A.mpoint(33, 0, 0, 1), tag=3)
Expand All @@ -235,7 +235,7 @@ def cell_description(self, gid):

return A.cable_cell(tree, dec)

def global_properties(self, kind):
def global_properties(self, _):
return self.the_props


Expand Down
2 changes: 1 addition & 1 deletion scripts/arbor-build-catalogue
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ with TemporaryDirectory() as tmp:
sfx = [".hpp"]
if cpu:
sfx += ["_cpu.cpp"]
if gpu:
if gpu and gpu != 'none':
sfx += ["_gpu.cpp", "_gpu.cu"]
for e in raw:
for s in sfx:
Expand Down
2 changes: 1 addition & 1 deletion test/unit-distributed/test_distributed_for_each.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ TEST(distributed_for_each, all_zero) {
int call_count = 0;

auto sample = [&](const util::range<int*>& range) {
EXPECT_EQ(0, range.size());
EXPECT_EQ(0ul, range.size());
++call_count;
};

Expand Down
8 changes: 4 additions & 4 deletions test/unit/test_asc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ TEST(asc, spine) {
EXPECT_EQ(m.branch_segments(6)[0].prox, (arb::mpoint{ 0, 5, 0, 1}));
// Now check metadata
auto d = std::get<arborio::asc_metadata>(result.metadata);
EXPECT_EQ(d.spines.size(), 2);
EXPECT_EQ(d.spines.size(), 2ul);
EXPECT_EQ(d.spines[0].location.x, 11);
EXPECT_EQ(d.spines[0].location.y, 12);
EXPECT_EQ(d.spines[0].location.z, 13);
Expand All @@ -355,12 +355,12 @@ TEST(asc, spine) {
EXPECT_EQ(d.spines[1].location.radius, 2);
EXPECT_EQ(d.spines[1].name, "S2");

EXPECT_EQ(d.markers.size(), 2);
EXPECT_EQ(d.markers[0].locations.size(), 2);
EXPECT_EQ(d.markers.size(), 2ul);
EXPECT_EQ(d.markers[0].locations.size(), 2ul);
EXPECT_EQ(d.markers[0].name, "M1");
EXPECT_EQ(d.markers[0].marker, arborio::asc_marker::cross);

EXPECT_EQ(d.markers[1].locations.size(), 1);
EXPECT_EQ(d.markers[1].locations.size(), 1ul);
EXPECT_EQ(d.markers[1].name, "M2");
EXPECT_EQ(d.markers[1].marker, arborio::asc_marker::dot);
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ TEST(hash, doesnt_compile) {

// check that we do not fall into the trap of the STL...
TEST(hash, integral_is_not_identity) {
ASSERT_NE(arb::hash_value(42), 42);
ASSERT_NE(arb::hash_value(42), 42ul);
}

0 comments on commit ddb7e70

Please sign in to comment.