Skip to content

Commit

Permalink
Visitors now takes C++ references of ast nodes in parameter, not poin…
Browse files Browse the repository at this point in the history
…ters (#297)

* Visitors now takes C++ references of ast nodes in parameter, not pointers
* Add instructions to run Python tests
  • Loading branch information
Tristan Carel authored Apr 23, 2020
1 parent 25e654c commit b8ba4a0
Show file tree
Hide file tree
Showing 101 changed files with 1,425 additions and 1,400 deletions.
17 changes: 14 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,21 @@ do not comply with coding conventions of this project. These 2 CMake variables r
* [pre-commit](https://pre-commit.com/)
clang-format can be installed on Linux thanks
to [LLVM apt page](http://apt.llvm.org/). On MacOS, there is a
[brew recipe](https://gist.github.com/ffeu/0460bb1349fa7e4ab4c459a6192cbb25)
to install clang-format 7. _cmake-format_ and _pre-commit_ utilities can be installed with *pip*.
to [LLVM apt page](http://apt.llvm.org/). On MacOS, you can simply install llvm with brew:
`brew install llvm`.
_cmake-format_ and _pre-commit_ utilities can be installed with *pip*.
### Validate the Python package
You may run the Python test-suites if your contribution has an impact
on the Python API:
1. setup a sandbox environment with either _virtualenv_,
_pyenv_, or _pipenv_. For instance with _virtualenv_:
`python -m venv .venv && source .venv/bin/activate`
1. build the Python package with the command: `python setup.py build`
1. install _pytest_ Python package: `pip install pytest`
1. execute the unit-tests: `pytest`
### Memory Leaks and clang-tidy
Expand Down
7 changes: 4 additions & 3 deletions src/codegen/codegen_acc_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ void CodegenAccVisitor::print_backend_includes() {
}


std::string CodegenAccVisitor::backend_name() {
std::string CodegenAccVisitor::backend_name() const {
return "C-OpenAcc (api-compatibility)";
}


void CodegenAccVisitor::print_memory_allocation_routine() {
void CodegenAccVisitor::print_memory_allocation_routine() const {
printer->add_newline(2);
auto args = "size_t num, size_t size, size_t alignment = 16";
printer->add_line("static inline void* mem_alloc({}) {}"_format(args, "{"));
Expand Down Expand Up @@ -174,7 +174,8 @@ void CodegenAccVisitor::print_global_variable_device_update_annotation() {
}
}

std::string CodegenAccVisitor::get_variable_device_pointer(std::string variable, std::string type) {
std::string CodegenAccVisitor::get_variable_device_pointer(const std::string& variable,
const std::string& type) const {
if (info.artificial_cell) {
return variable;
}
Expand Down
19 changes: 10 additions & 9 deletions src/codegen/codegen_acc_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace codegen {
class CodegenAccVisitor: public CodegenCVisitor {
protected:
/// name of the code generation backend
std::string backend_name() override;
std::string backend_name() const override;


/// common includes : standard c/c++, coreneuron and backend specific
Expand All @@ -46,7 +46,7 @@ class CodegenAccVisitor: public CodegenCVisitor {


/// memory allocation routine
void print_memory_allocation_routine() override;
void print_memory_allocation_routine() const override;


/// annotations like "acc enter data present(...)" for main kernel
Expand Down Expand Up @@ -81,20 +81,21 @@ class CodegenAccVisitor: public CodegenCVisitor {
/// update global variable from host to the device
void print_global_variable_device_update_annotation() override;

std::string get_variable_device_pointer(std::string variable, std::string type) override;
std::string get_variable_device_pointer(const std::string& variable,
const std::string& type) const override;


public:
CodegenAccVisitor(std::string mod_file,
std::string output_dir,
CodegenAccVisitor(const std::string& mod_file,
const std::string& output_dir,
LayoutType layout,
std::string float_type)
const std::string& float_type)
: CodegenCVisitor(mod_file, output_dir, layout, float_type) {}

CodegenAccVisitor(std::string mod_file,
std::stringstream& stream,
CodegenAccVisitor(const std::string& mod_file,
std::ostream& stream,
LayoutType layout,
std::string float_type)
const std::string& float_type)
: CodegenCVisitor(mod_file, stream, layout, float_type) {}
};

Expand Down
Loading

0 comments on commit b8ba4a0

Please sign in to comment.