Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
madsbk committed Apr 24, 2019
1 parent 51ec5f2 commit 16e3371
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 91 deletions.
47 changes: 8 additions & 39 deletions bridge/pgas4py/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from setuptools.command.build_ext import build_ext as setup_build_ext
import numbers
import os
import glob


def script_path(*paths):
Expand All @@ -35,29 +34,6 @@ def script_path(*paths):
return os.path.join(prefix, *paths)


def get_pyx_extensions():
"""Find and compiles all cython extensions"""
include_dirs = []
if 'USE_CYTHON' in os.environ:
import numpy
import bohrium_api
include_dirs.extend([numpy.get_include(), bohrium_api.get_include()])
pyx_list = glob.glob(script_path("bohrium", "*.pyx"))
ret = []
for pyx in pyx_list:
ret.append(Extension(name="bohrium.%s" % os.path.splitext(os.path.basename(pyx))[0],
sources=[pyx],
include_dirs=include_dirs))
ret.append(Extension(name="bohrium.nobh.bincount_cython",
sources=[script_path("bohrium", "nobh", "bincount_cython.pyx")],
include_dirs=include_dirs))
if 'USE_CYTHON' in os.environ:
import Cython.Build
return Cython.Build.cythonize(ret, nthreads=2)
else:
return ret


class BuildExt(setup_build_ext):
"""We delay the numpy and bohrium dependency to the build command.
Hopefully, PIP has installed them at this point."""
Expand Down Expand Up @@ -131,19 +107,12 @@ def __str__(self):
# simple. Or you can use find_packages().
packages=find_packages(exclude=['tests']),

ext_modules=[
Extension(
name='_bh_api',
sources=[script_path('src', '_bh_api.c')],
depends=[script_path('src', '_bh_api.h')],
include_dirs=[
"/home/madsbk/repos/bohrium/b/bridge/c/out/",
],
libraries=['bhc'],
library_dirs=[
"/home/madsbk/repos/bohrium/b/bridge/c/",
],
extra_compile_args=["-std=c99"],
),
]
# ext_modules=[
# Extension(
# name='_bh_api',
# sources=[script_path('src', '_bh_api.c')],
# depends=[script_path('src', '_bh_api.h')],
# extra_compile_args=["-std=c99"],
# ),
# ]
)
12 changes: 6 additions & 6 deletions bridge/pgas4py/src/_bh_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ GNU Lesser General Public License along with Bohrium.
If not, see <http://www.gnu.org/licenses/>.
*/

#include "_bh_api.h"
#include <bhc.h>
#include <Python.h>
#include <bohrium_api.h>

#if PY_MAJOR_VERSION >= 3
#define NPY_PY3K
#endif

PyObject* PyFlush(PyObject *self, PyObject *args) {
bhc_flush();
Py_RETURN_NONE;
}

// The methods (functions) of this module
static PyMethodDef _bh_apiMethods[] = {
Expand Down
27 changes: 0 additions & 27 deletions bridge/pgas4py/src/_bh_api.h

This file was deleted.

53 changes: 34 additions & 19 deletions ve/pgas/engine_pgas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace bohrium {

EnginePGAS::EnginePGAS(component::ComponentVE &comp, jitk::Statistics &stat) :
EngineCPU(comp, stat),
compiler(comp.config.get<string>("compiler_cmd"), verbose, comp.config.file_dir.string()) {
compiler(comp.config.get<string>("compiler_cmd"), comp.config.file_dir.string(), verbose) {

compilation_hash = util::hash(compiler.cmd_template);

Expand Down Expand Up @@ -163,9 +163,9 @@ KernelFunction EnginePGAS::getFunction(const string &source, const std::string &


void EnginePGAS::execute(const jitk::SymbolTable &symbols,
const std::string &source,
uint64_t codegen_hash,
const std::vector<const bh_instruction *> &constants) {
const std::string &source,
uint64_t codegen_hash,
const std::vector<const bh_instruction *> &constants) {
// Notice, we use a "pure" hash of `source` to make sure that the `source_filename` always
// corresponds to `source` even if `codegen_hash` is buggy.
uint64_t hash = util::hash(source);
Expand Down Expand Up @@ -226,10 +226,10 @@ void EnginePGAS::execute(const jitk::SymbolTable &symbols,

// Writes the OpenMP specific for-loop header
void EnginePGAS::loopHeadWriter(const jitk::SymbolTable &symbols,
jitk::Scope &scope,
const jitk::LoopB &block,
const vector<uint64_t> &thread_stack,
stringstream &out) {
jitk::Scope &scope,
const jitk::LoopB &block,
const vector<uint64_t> &thread_stack,
stringstream &out) {
int64_t local_size = block.size;
int64_t local_offset = 0;

Expand Down Expand Up @@ -307,14 +307,17 @@ void EnginePGAS::writeKernel(const LoopB &kernel,

for (bh_base *base: symbols.getParams()) {
ss << " MPI_Win win" << symbols.baseID(base) << ";\n";
ss << " MPI_Win_create(a" << symbols.baseID(base) << ", " << base->pgas.localSize() * bh_type_size(base->dtype())
<< ", " << bh_type_size(base->dtype()) << ", MPI_INFO_NULL, MPI_COMM_WORLD, &win" << symbols.baseID(base) << ");\n";
ss << " MPI_Win_create(a" << symbols.baseID(base) << ", "
<< base->pgas.localSize() * bh_type_size(base->dtype())
<< ", " << bh_type_size(base->dtype()) << ", MPI_INFO_NULL, MPI_COMM_WORLD, &win" << symbols.baseID(base)
<< ");\n";
}

// Write allocations of the kernel temporaries
for (const bh_base *b: kernel_temps) {
util::spaces(ss, 4);
ss << writeType(b->dtype()) << " * __restrict__ a" << symbols.baseID(b) << " = malloc(" << b->nbytes() << ");\n";
ss << writeType(b->dtype()) << " * __restrict__ a" << symbols.baseID(b) << " = malloc(" << b->nbytes()
<< ");\n";
}
ss << "\n";

Expand Down Expand Up @@ -404,7 +407,9 @@ void write_mpi_indexes(const Scope &scope, int rank, const bh_view &view, std::s
out << "}\n";
}

void write_mpi_get(const SymbolTable &symbols, const Scope &scope, int rank, const bh_view &view, std::stringstream &out, bool always_mpi = false) {
void
write_mpi_get(const SymbolTable &symbols, const Scope &scope, int rank, const bh_view &view, std::stringstream &out,
bool always_mpi = false) {
util::spaces(out, 8 + rank * 4);
out << "{ // PGAS Get \n";
write_mpi_indexes(scope, rank, view, out);
Expand All @@ -423,7 +428,9 @@ void write_mpi_get(const SymbolTable &symbols, const Scope &scope, int rank, con
util::spaces(out, 16 + rank * 4);
out << "MPI_Win_unlock (owner_rank, win" << symbols.baseID(view.base) << ");\n";
util::spaces(out, 16 + rank * 4);
out << "printf(\"%d: MPI_Get(%ld) - owner_rank: %d, owner_offset: %ld, local_size: %ld, value: %ld\\n\", world_rank, global_idx, owner_rank, owner_offset, local_size, " << scope.getName(view) << ");\n";
out
<< "printf(\"%d: MPI_Get(%ld) - owner_rank: %d, owner_offset: %ld, local_size: %ld, value: %ld\\n\", world_rank, global_idx, owner_rank, owner_offset, local_size, "
<< scope.getName(view) << ");\n";
util::spaces(out, 12 + rank * 4);
out << "}";
if (always_mpi) {
Expand All @@ -433,15 +440,19 @@ void write_mpi_get(const SymbolTable &symbols, const Scope &scope, int rank, con
util::spaces(out, 16 + rank * 4);
out << scope.getName(view) << " = a" << symbols.baseID(view.base) << "[owner_offset];\n";
util::spaces(out, 16 + rank * 4);
out << "printf(\"%d: Local_Get(%ld) - owner_rank: %d, owner_offset: %ld, local_size: %ld, value: %d\\n\", world_rank, global_idx, owner_rank, owner_offset, local_size, (int)" << scope.getName(view) << ");\n";
out
<< "printf(\"%d: Local_Get(%ld) - owner_rank: %d, owner_offset: %ld, local_size: %ld, value: %d\\n\", world_rank, global_idx, owner_rank, owner_offset, local_size, (int)"
<< scope.getName(view) << ");\n";
util::spaces(out, 12 + rank * 4);
out << "}\n";
}
util::spaces(out, 8 + rank * 4);
out << "}\n";
}

void write_mpi_put(const SymbolTable &symbols, const Scope &scope, int rank, const bh_view &view, std::stringstream &out, bool always_mpi = false) {
void
write_mpi_put(const SymbolTable &symbols, const Scope &scope, int rank, const bh_view &view, std::stringstream &out,
bool always_mpi = false) {
util::spaces(out, 8 + rank * 4);
out << "{ // PGAS Put \n";
write_mpi_indexes(scope, rank, view, out);
Expand All @@ -452,7 +463,9 @@ void write_mpi_put(const SymbolTable &symbols, const Scope &scope, int rank, con
out << "if (owner_rank != world_rank) {\n";
}
util::spaces(out, 16 + rank * 4);
out << "printf(\"%d: MPI_Put(%ld) - owner_rank: %d, owner_offset: %ld, local_size: %ld, value: %d\\n\", world_rank, global_idx, owner_rank, owner_offset, local_size, (int)" << scope.getName(view) << ");\n";
out
<< "printf(\"%d: MPI_Put(%ld) - owner_rank: %d, owner_offset: %ld, local_size: %ld, value: %d\\n\", world_rank, global_idx, owner_rank, owner_offset, local_size, (int)"
<< scope.getName(view) << ");\n";
util::spaces(out, 16 + rank * 4);
out << "MPI_Win_lock(MPI_LOCK_SHARED, owner_rank, 0, win" << symbols.baseID(view.base) << ");\n";
util::spaces(out, 16 + rank * 4);
Expand All @@ -468,7 +481,9 @@ void write_mpi_put(const SymbolTable &symbols, const Scope &scope, int rank, con
} else {
out << "else {\n";
util::spaces(out, 16 + rank * 4);
out << "printf(\"%d: Local_Put(%ld) - owner_rank: %d, owner_offset: %ld, local_size: %ld, value: %d\\n\", world_rank, global_idx, owner_rank, owner_offset, local_size, (int)" << scope.getName(view) << ");\n";
out
<< "printf(\"%d: Local_Put(%ld) - owner_rank: %d, owner_offset: %ld, local_size: %ld, value: %d\\n\", world_rank, global_idx, owner_rank, owner_offset, local_size, (int)"
<< scope.getName(view) << ");\n";
util::spaces(out, 16 + rank * 4);
out << "a" << symbols.baseID(view.base) << "[owner_offset] = ";
scope.getName(view, out);
Expand Down Expand Up @@ -500,7 +515,7 @@ void EnginePGAS::writeBlock(const SymbolTable &symbols,
for (const jitk::InstrPtr &instr: jitk::iterator::allInstr(kernel)) {
for (const auto &view: instr->getViews()) {
if (util::exist(local_tmps, view.base)) {
if (not (scope.isDeclared(view) or symbols.isAlwaysArray(view.base))) {
if (not(scope.isDeclared(view) or symbols.isAlwaysArray(view.base))) {
scope.insertTmp(view.base);
util::spaces(out, 8 + kernel.rank * 4);
scope.writeDeclaration(view, writeType(view.base->dtype()), out);
Expand Down Expand Up @@ -585,7 +600,7 @@ void EnginePGAS::writeBlock(const SymbolTable &symbols,
}
}
util::spaces(out, 4 + b.rank() * 4);
writeInstr(scope, *instr, 4 + b.rank() * 4, opencl, out);
writeInstr(scope, *instr, 4 + b.rank() * 4, opencl, out);
}
} else {
util::spaces(out, 4 + b.rank() * 4);
Expand Down

0 comments on commit 16e3371

Please sign in to comment.