-
Notifications
You must be signed in to change notification settings - Fork 59
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
Part 1 of the big GPU merge #45
Changes from 28 commits
b38f78b
7e54957
b7bd5dd
3edad46
1388d20
8e6d97f
4ee9930
4c0864b
d1a5b6e
36ebcc7
851f38c
4a1777f
2c6f5a3
c742fd5
039d5a9
121dade
b6aec69
44c8ac0
78f60f5
5c09594
3830c9a
2db99a2
65ed2fe
7f1216d
de992ad
b5bae5b
06ef117
18a9226
05e4770
b9b1e57
dbca304
ff14704
9e0b874
f1eac25
5174b69
a39c9a3
63c507b
830428a
cee495c
c97135d
5ade8d0
1b929ff
f189d73
550da10
a03af27
e7a8fb6
5aeea90
e8d3285
b39a93e
0ded25a
cd4d9ae
e74720b
b11990f
bb14d18
1584bf3
46427e6
7751058
2b2b310
5825543
faf1a41
6cf11d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,28 @@ | ||
set(HEADERS | ||
) | ||
set(MINIAPP_SOURCES | ||
io.cpp | ||
miniapp.cpp | ||
io.cpp | ||
miniapp_recipes.cpp | ||
) | ||
set(MINIAPP_SOURCES_CUDA | ||
miniapp.cu | ||
io.cpp | ||
miniapp_recipes.cpp | ||
) | ||
|
||
add_executable(miniapp.exe ${MINIAPP_SOURCES} ${HEADERS}) | ||
if(WITH_CUDA) | ||
cuda_add_executable(miniapp.exe ${MINIAPP_SOURCES_CUDA} ${HEADERS}) | ||
target_link_libraries(miniapp.exe gpu) | ||
else() | ||
add_executable(miniapp.exe ${MINIAPP_SOURCES} ${HEADERS}) | ||
endif() | ||
|
||
target_link_libraries(miniapp.exe nestmc) | ||
|
||
target_link_libraries(miniapp.exe LINK_PUBLIC cellalgo) | ||
target_link_libraries(miniapp.exe LINK_PUBLIC ${TBB_LIBRARIES}) | ||
if(WITH_TBB) | ||
target_link_libraries(miniapp.exe ${TBB_LIBRARIES}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need a |
||
endif() | ||
|
||
if(WITH_MPI) | ||
target_link_libraries(miniapp.exe LINK_PUBLIC ${MPI_C_LIBRARIES}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "miniapp.cpp" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,6 @@ CPrinter::CPrinter(Module &m, bool o) | |
text_.add_line("#include <limits>"); | ||
text_.add_line(); | ||
text_.add_line("#include <mechanism.hpp>"); | ||
text_.add_line("#include <mechanism_interface.hpp>"); | ||
text_.add_line("#include <algorithms.hpp>"); | ||
text_.add_line(); | ||
|
||
|
@@ -44,18 +43,19 @@ CPrinter::CPrinter(Module &m, bool o) | |
|
||
text_.add_line("namespace nest{ namespace mc{ namespace mechanisms{ namespace " + m.name() + "{"); | ||
text_.add_line(); | ||
text_.add_line("template<typename T, typename I>"); | ||
text_.add_line("class " + class_name + " : public mechanism<T, I> {"); | ||
text_.add_line("template<class MemoryPolicy>"); | ||
text_.add_line("class " + class_name + " : public mechanism<MemoryPolicy> {"); | ||
text_.add_line("public:"); | ||
text_.increase_indentation(); | ||
text_.add_line("using base = mechanism<T, I>;"); | ||
text_.add_line("using base = mechanism<MemoryPolicy>;"); | ||
text_.add_line("using value_type = typename base::value_type;"); | ||
text_.add_line("using size_type = typename base::size_type;"); | ||
text_.add_line("using vector_type = typename base::vector_type;"); | ||
text_.add_line("using view_type = typename base::view_type;"); | ||
text_.add_line("using index_type = typename base::index_type;"); | ||
text_.add_line("using index_view = typename base::index_view;"); | ||
text_.add_line("using const_index_view = typename base::const_index_view;"); | ||
text_.add_line(); | ||
text_.add_line("using array = typename base::array;"); | ||
text_.add_line("using iarray = typename base::iarray;"); | ||
text_.add_line("using view = typename base::view;"); | ||
text_.add_line("using iview = typename base::iview;"); | ||
text_.add_line("using const_iview = typename base::const_iview;"); | ||
text_.add_line("using indexed_view_type= typename base::indexed_view_type;"); | ||
text_.add_line("using ion_type = typename base::ion_type;"); | ||
text_.add_line(); | ||
|
@@ -67,12 +67,12 @@ CPrinter::CPrinter(Module &m, bool o) | |
text_.add_line("struct " + tname + " {"); | ||
text_.increase_indentation(); | ||
for(auto& field : ion.read) { | ||
text_.add_line("view_type " + field.spelling + ";"); | ||
text_.add_line("view " + field.spelling + ";"); | ||
} | ||
for(auto& field : ion.write) { | ||
text_.add_line("view_type " + field.spelling + ";"); | ||
text_.add_line("view " + field.spelling + ";"); | ||
} | ||
text_.add_line("index_type index;"); | ||
text_.add_line("iarray index;"); | ||
text_.add_line("std::size_t memory() const { return sizeof(size_type)*index.size(); }"); | ||
text_.add_line("std::size_t size() const { return index.size(); }"); | ||
text_.decrease_indentation(); | ||
|
@@ -85,7 +85,7 @@ CPrinter::CPrinter(Module &m, bool o) | |
// constructor | ||
////////////////////////////////////////////// | ||
int num_vars = array_variables.size(); | ||
text_.add_line(class_name + "(view_type vec_v, view_type vec_i, const_index_view node_index)"); | ||
text_.add_line(class_name + "(view vec_v, view vec_i, const_iview node_index)"); | ||
text_.add_line(": base(vec_v, vec_i, node_index)"); | ||
text_.add_line("{"); | ||
text_.increase_indentation(); | ||
|
@@ -102,8 +102,8 @@ CPrinter::CPrinter(Module &m, bool o) | |
|
||
text_.add_line(); | ||
text_.add_line("// allocate memory"); | ||
text_.add_line("data_ = vector_type(field_size * num_fields);"); | ||
text_.add_line("data_(memory::all) = std::numeric_limits<value_type>::quiet_NaN();"); | ||
text_.add_line("data_ = array(field_size * num_fields);"); | ||
text_.add_line("memory::fill(data_, std::numeric_limits<value_type>::quiet_NaN());"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it worth considering an STL-like constructor for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The library already has this functionality. I don't know why I have done things this way, probably just sloppiness. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, it was sloppiness. I have fixed it by using just one line:
|
||
|
||
// assign the sub-arrays | ||
// replace this : data_(1*n, 2*n); | ||
|
@@ -261,7 +261,11 @@ CPrinter::CPrinter(Module &m, bool o) | |
auto ion = find_ion(ionKind::Na); | ||
text_.add_line("if(k==ionKind::na) {"); | ||
text_.increase_indentation(); | ||
text_.add_line("ion_na.index = index_into(i.node_index(), node_index_);"); | ||
text_.add_line("// TODO a more elegant way of initializing host storage from ranges"); | ||
text_.add_line("auto index = index_into(i.node_index(), node_index_);"); | ||
text_.add_line("ion_na.index = iarray(size());"); | ||
text_.add_line("auto last = std::copy(index.begin(), index.end(), ion_na.index.begin());"); | ||
text_.add_line("EXPECTS((unsigned)std::distance(ion_na.index.begin(), last) == size());"); | ||
if(has_variable(*ion, "ina")) text_.add_line("ion_na.ina = i.current();"); | ||
if(has_variable(*ion, "ena")) text_.add_line("ion_na.ena = i.reversal_potential();"); | ||
if(has_variable(*ion, "nai")) text_.add_line("ion_na.nai = i.internal_concentration();"); | ||
|
@@ -274,7 +278,11 @@ CPrinter::CPrinter(Module &m, bool o) | |
auto ion = find_ion(ionKind::Ca); | ||
text_.add_line("if(k==ionKind::ca) {"); | ||
text_.increase_indentation(); | ||
text_.add_line("ion_ca.index = index_into(i.node_index(), node_index_);"); | ||
text_.add_line("// TODO a more elegant way of initializing host storage from ranges"); | ||
text_.add_line("auto index = index_into(i.node_index(), node_index_);"); | ||
text_.add_line("ion_ca.index = iarray(size());"); | ||
text_.add_line("auto last = std::copy(index.begin(), index.end(), ion_ca.index.begin());"); | ||
text_.add_line("EXPECTS((unsigned)std::distance(ion_ca.index.begin(), last) == size());"); | ||
if(has_variable(*ion, "ica")) text_.add_line("ion_ca.ica = i.current();"); | ||
if(has_variable(*ion, "eca")) text_.add_line("ion_ca.eca = i.reversal_potential();"); | ||
if(has_variable(*ion, "cai")) text_.add_line("ion_ca.cai = i.internal_concentration();"); | ||
|
@@ -287,7 +295,11 @@ CPrinter::CPrinter(Module &m, bool o) | |
auto ion = find_ion(ionKind::K); | ||
text_.add_line("if(k==ionKind::k) {"); | ||
text_.increase_indentation(); | ||
text_.add_line("ion_k.index = index_into(i.node_index(), node_index_);"); | ||
text_.add_line("// TODO a more elegant way of initializing host storage from ranges"); | ||
text_.add_line("auto index = index_into(i.node_index(), node_index_);"); | ||
text_.add_line("ion_k.index = iarray(size());"); | ||
text_.add_line("auto last = std::copy(index.begin(), index.end(), ion_k.index.begin());"); | ||
text_.add_line("EXPECTS((unsigned)std::distance(ion_k.index.begin(), last) == size());"); | ||
if(has_variable(*ion, "ik")) text_.add_line("ion_k.ik = i.current();"); | ||
if(has_variable(*ion, "ek")) text_.add_line("ion_k.ek = i.reversal_potential();"); | ||
if(has_variable(*ion, "ki")) text_.add_line("ion_k.ki = i.internal_concentration();"); | ||
|
@@ -324,15 +336,15 @@ CPrinter::CPrinter(Module &m, bool o) | |
////////////////////////////////////////////// | ||
////////////////////////////////////////////// | ||
|
||
text_.add_line("vector_type data_;"); | ||
text_.add_line("array data_;"); | ||
for(auto var: array_variables) { | ||
if(optimize_) { | ||
text_.add_line( | ||
"__declspec(align(vector_type::alignment())) value_type *" | ||
"__declspec(align(array::alignment())) value_type *" | ||
+ var->name() + ";"); | ||
} | ||
else { | ||
text_.add_line("view_type " + var->name() + ";"); | ||
text_.add_line("view " + var->name() + ";"); | ||
} | ||
} | ||
|
||
|
@@ -356,52 +368,6 @@ CPrinter::CPrinter(Module &m, bool o) | |
text_.add_line("using base::node_index_;"); | ||
|
||
text_.add_line(); | ||
//text_.add_line("DATA_PROFILE"); | ||
text_.decrease_indentation(); | ||
text_.add_line("};"); | ||
text_.add_line(); | ||
|
||
// print the helper type that provides the bridge from the mechanism to | ||
// the calling code | ||
text_.add_line("template<typename T, typename I>"); | ||
text_.add_line("struct helper : public mechanism_helper<T, I> {"); | ||
text_.increase_indentation(); | ||
text_.add_line("using base = mechanism_helper<T, I>;"); | ||
text_.add_line("using index_view = typename base::index_view;"); | ||
text_.add_line("using view_type = typename base::view_type;"); | ||
text_.add_line("using mechanism_ptr_type = typename base::mechanism_ptr_type;"); | ||
text_.add_gutter() << "using mechanism_type = " << class_name << "<T, I>;"; | ||
text_.add_line(); | ||
text_.add_line(); | ||
|
||
text_.add_line("std::string"); | ||
text_.add_line("name() const override"); | ||
text_.add_line("{"); | ||
text_.increase_indentation(); | ||
text_.add_gutter() << "return \"" << m.name() << "\";"; | ||
text_.add_line(); | ||
text_.decrease_indentation(); | ||
text_.add_line("}"); | ||
text_.add_line(); | ||
|
||
text_.add_line("mechanism_ptr<T,I>"); | ||
text_.add_line("new_mechanism(view_type vec_v, view_type vec_i, index_view node_index) const override"); | ||
text_.add_line("{"); | ||
text_.increase_indentation(); | ||
text_.add_line("return nest::mc::mechanisms::make_mechanism<mechanism_type>(vec_v, vec_i, node_index);"); | ||
text_.decrease_indentation(); | ||
text_.add_line("}"); | ||
text_.add_line(); | ||
|
||
text_.add_line("void"); | ||
text_.add_line("set_parameters(mechanism_ptr_type&, parameter_list const&) const override"); | ||
text_.add_line("{"); | ||
text_.increase_indentation(); | ||
// TODO : interface that writes parameter_list paramaters into the mechanism's storage | ||
text_.decrease_indentation(); | ||
text_.add_line("}"); | ||
text_.add_line(); | ||
|
||
text_.decrease_indentation(); | ||
text_.add_line("};"); | ||
text_.add_line(); | ||
|
@@ -713,7 +679,7 @@ void CPrinter::print_APIMethod_optimized(APIMethod* e) { | |
text_.add_line("int NB = n_/BSIZE;"); | ||
for(auto out: aliased_variables) { | ||
text_.add_line( | ||
"__declspec(align(vector_type::alignment())) value_type " | ||
"__declspec(align(array::alignment())) value_type " | ||
+ out->name() + "[BSIZE];"); | ||
} | ||
//text_.add_line("START_PROFILE"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer need
ExternalProject
here I think.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed