Skip to content

Commit

Permalink
Merge branch 'cpu'
Browse files Browse the repository at this point in the history
  • Loading branch information
safl committed May 12, 2015
2 parents b3137a7 + 9bedd17 commit e73c18c
Show file tree
Hide file tree
Showing 11 changed files with 320 additions and 257 deletions.
9 changes: 0 additions & 9 deletions bridge/c/codegen/templates/type_definitions.ctpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,12 @@ directiveStartToken = %

using namespace bxx;

// Common slice range
struct bh_slice_range {
slice_range me;
};


%for $ctype, $bh_atype, $bh_ctype, $bh_enum in $data

// $bh_enum

struct bh_multi_array_${bh_ctype} {
multi_array<${bh_atype}> me;
};
struct bh_slice_range_${bh_ctype} {
slice<${bh_atype}> me;
};

%end for
6 changes: 0 additions & 6 deletions bridge/c/codegen/templates/type_header.ctpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ DLLEXPORT void bh_runtime_flush(void);
// Shutdown Bohrium
DLLEXPORT void bh_runtime_shutdown(void);

// Common slice range
struct bh_slice_range;
typedef struct bh_slice_range* bh_slice_range_p;

// Common type forward definition
#ifndef __BH_ARRAY_H
struct bh_base;
Expand All @@ -47,11 +43,9 @@ typedef bh_view* bh_view_p;

// Forward definitions
struct bh_multi_array_${bh_ctype};
struct bh_slice_${bh_ctype};

// Shorthand pointer defs
typedef struct bh_multi_array_${bh_ctype}* bh_multi_array_${bh_ctype}_p;
typedef struct bh_slice_range_${bh_ctype}* bh_slice_range_${bh_ctype}_p;

// Marks the data as externally allocated
DLLEXPORT void bh_multi_array_${bh_ctype}_set_external(const bh_multi_array_${bh_ctype}_p self, bh_bool value);
Expand Down
71 changes: 44 additions & 27 deletions bridge/cpp/bxx/bohrium.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,35 +89,50 @@ enum scannable {
//
// Slicing
//
class slice_range {
class Slice {
public:
slice_range();
slice_range(int begin, int end, size_t stride);
Slice();
Slice(int begin, int end, size_t step);

int begin, end;
size_t stride;
bool inclusive_end;
int begin;
int end;
size_t step;
};

template <typename T>
class slice {
public:
slice(multi_array<T>& op);
inline Slice::Slice() : begin(0), end(-1), step(1) {}

slice& operator[](int rhs);
slice& operator[](slice_range& rhs);
multi_array<T>& operator=(T rhs);
inline Slice::Slice(int begin, int end, size_t step)
: begin(begin), end(end), step(step) {}

// Create a actual view of the slice
bxx::multi_array<T>& view();
inline Slice _(int begin, int end, size_t step)
{
return Slice(begin, end, step);
}

private:
multi_array<T>* op; // The op getting sliced
inline Slice _(int begin, int end)
{
return _(begin, end, 1);
}

int dims; // The amount of dims covered by the slice
slice_range ranges[BH_MAXDIM]; // The ranges...
inline Slice _SI(int begin, int end, size_t step)
{
return _(begin, end, step);
}

};
inline Slice _SI(int begin, int end)
{
return _(begin, end, 1);
}

inline Slice _SE(int begin, int end, size_t step)
{
return _(begin, end-1, step);
}

inline Slice _SE(int begin, int end)
{
return _(begin, end-1, 1);
}

//
// The Abstraction
Expand Down Expand Up @@ -161,12 +176,11 @@ class multi_array {
// Definitions are provided in:
//
// - multi_array.hpp for those implemented by hand ([], ++, --, ostream<< ).
// - slicing.hpp: Auxilary behavior of the [] operator.
// - operators.hpp: defined code-generator.
//
// Slicing / explicit view
slice<T>& operator[](int rhs); // Select a single element / dimension
slice<T>& operator[](slice_range& rhs); // Select a range (begin, end, stride)
multi_array<T>& operator[](int rhs); // Select a single element / dimension
multi_array<T>& operator[](Slice rhs); // Select a range (begin, end, step)

multi_array& operator()(const T& n); // Update
multi_array& operator()(multi_array<T>& rhs);
Expand All @@ -179,8 +193,6 @@ class multi_array {
template <typename In>
multi_array<T>& operator=(multi_array<In>& rhs);// Initialization / assignment.

multi_array& operator=(slice<T>& rhs ); // Initialization / assignment.

multi_array& operator+=(const T& rhs); // Compound assignment / increment
multi_array& operator+=(multi_array& rhs);

Expand Down Expand Up @@ -232,8 +244,12 @@ class multi_array {
bool allocated() const; // Determine if the array is intitialized and data for it is allocated
void sync();

int getSliceDim(void);
void setSliceDim(int dim);

protected:
bool temp_;
int slicing_dim_;

private:
void reset_meta(); // Helper, shared among constructors
Expand Down Expand Up @@ -347,17 +363,18 @@ class Runtime {

}

#include "multi_array.hpp" // Operand definition.
#include "slicing.hpp" // Operand slicing / explicit views / aliases
#include "multi_array.hpp" // Operand definition.

#include "runtime.hpp" // Communication with Bohrium runtime
#include "runtime.broadcast.hpp" // Operand broadcasting
#include "runtime.typechecker.hpp" // Array operations - typechecker
#include "runtime.operations.hpp" // Array operations
#include "runtime.extensions.hpp" // Extensions

#include "reduction.hpp" // DSEL Reduction
#include "scan.hpp" // DSEL Scan operation
#include "generator.hpp" // DSEL Generators
#include "visuals.hpp" // DSEL Visualization

#include "operators.hpp" // DSEL Operations via operator-overloads.
#include "sugar.hpp" // DSEL Additional sugar...
Expand Down
37 changes: 18 additions & 19 deletions bridge/cpp/bxx/generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,6 @@ multi_array<T>& randu(const Dimensions&... shape)
// End of random number generators.
//

/**
* Create a range of values defined as [0, nelem[
*/
template <typename T>
multi_array<T>& range(uint64_t nelem)
{
multi_array<T>* result = new multi_array<T>(nelem);
result->link();

bh_range(*result);

result->setTemp(true);
return *result;
}

/**
* Create a range of values defined as the [start, end[
* Each element in the range is seperated by 'skip'.
Expand All @@ -155,17 +140,31 @@ multi_array<T>& range(const int64_t start, const int64_t end, const int64_t skip
nelem = (start-adj_end+1)/abs(skip);
}

multi_array<uint32_t>* base_range = new multi_array<uint32_t>(nelem);
base_range->link();

multi_array<T>* result = new multi_array<T>(nelem);
result->link();

bh_range(*result);
bh_multiply(*result, *result, (T)skip);
bh_add(*result, *result, (T)start);

bh_range(*base_range);
bh_multiply(*base_range, *base_range, (uint32_t)skip);
bh_add(*base_range, *base_range, (uint32_t)start);
base_range->setTemp(true);
bh_identity(*result, *base_range);

result->setTemp(true);
return *result;
}

/**
* Create a range of values defined as [0, nelem[
*/
template <typename T>
multi_array<T>& range(uint64_t nelem)
{
return range<T>((int64_t)0, (int64_t)nelem, (int64_t)1);
}

}
#endif

0 comments on commit e73c18c

Please sign in to comment.