Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/basis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
template<typename P>
std::array<fk::matrix<P>, 6> generate_multi_wavelets(int const degree)
{
tools::expect(degree > 0);
expect(degree > 0);

// These are the function outputs
// g0,g1,h0, and h1 are two-scale coefficients
Expand Down Expand Up @@ -359,8 +359,8 @@ std::array<fk::matrix<P>, 6> generate_multi_wavelets(int const degree)
template<typename R>
fk::matrix<R> operator_two_scale(int const degree, int const num_levels)
{
tools::expect(degree > 0);
tools::expect(num_levels > 1);
expect(degree > 0);
expect(num_levels > 1);

int const max_level = fm::two_raised_to(num_levels);

Expand Down Expand Up @@ -502,7 +502,7 @@ wavelet_transform<P, resrc>::wavelet_transform(options const &program_opts,
<< '\n';

// copy to device if necessary
tools::expect(block_builder.size() == dense_blocks_.size());
expect(block_builder.size() == dense_blocks_.size());
for (auto i = 0; i < static_cast<int>(block_builder.size()); ++i)
{
if constexpr (resrc == resource::host)
Expand All @@ -527,8 +527,8 @@ fk::vector<P, mem_type::owner, resrc> wavelet_transform<P, resrc>::apply(
basis::side const transform_side,
basis::transpose const transform_trans) const
{
tools::expect(level >= 0);
tools::expect(level <= max_level);
expect(level >= 0);
expect(level <= max_level);

auto const ncols =
transform_side == basis::side::right ? coefficients.size() : 1;
Expand All @@ -546,22 +546,22 @@ fk::matrix<P, mem_type::owner, resrc> wavelet_transform<P, resrc>::apply(
basis::side const transform_side,
basis::transpose const transform_trans) const
{
tools::expect(level >= 0);
expect(level >= 0);
if (level == 0)
{
return fk::matrix<P, mem_type::owner, resrc>(coefficients);
}

tools::expect(level <= max_level);
expect(level <= max_level);

auto const op_size = fm::two_raised_to(level) * degree;
if (transform_side == basis::side::right)
{
tools::expect(coefficients.ncols() == op_size);
expect(coefficients.ncols() == op_size);
}
else
{
tools::expect(coefficients.nrows() == op_size);
expect(coefficients.nrows() == op_size);
}

int const rows_y =
Expand Down
98 changes: 49 additions & 49 deletions src/batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ batch<P, resrc>::batch(int const num_entries, int const nrows, int const ncols,
: num_entries_(num_entries), nrows_(nrows), ncols_(ncols), stride_(stride),
do_trans_(do_trans), batch_{new P *[num_entries]()}
{
tools::expect(num_entries > 0);
tools::expect(nrows > 0);
tools::expect(ncols > 0);
tools::expect(stride > 0);
expect(num_entries > 0);
expect(nrows > 0);
expect(ncols > 0);
expect(stride > 0);
}

template<typename P, resource resrc>
Expand All @@ -40,11 +40,11 @@ batch<P, resrc> &batch<P, resrc>::operator=(batch<P, resrc> const &other)
{
return *this;
}
tools::expect(num_entries() == other.num_entries());
tools::expect(nrows() == other.nrows());
tools::expect(ncols() == other.ncols());
tools::expect(get_stride() == other.get_stride());
tools::expect(get_trans() == other.get_trans());
expect(num_entries() == other.num_entries());
expect(nrows() == other.nrows());
expect(ncols() == other.ncols());
expect(get_stride() == other.get_stride());
expect(get_trans() == other.get_trans());
std::memcpy(batch_, other.batch_, other.num_entries() * sizeof(P *));
return *this;
}
Expand All @@ -66,12 +66,12 @@ batch<P, resrc> &batch<P, resrc>::operator=(batch<P, resrc> &&other)
return *this;
}

tools::expect(num_entries() == other.num_entries());
tools::expect(nrows() == other.nrows());
tools::expect(ncols() == other.ncols());
tools::expect(get_stride() == other.get_stride());
expect(num_entries() == other.num_entries());
expect(nrows() == other.nrows());
expect(ncols() == other.ncols());
expect(get_stride() == other.get_stride());

tools::expect(get_trans() == other.get_trans());
expect(get_trans() == other.get_trans());
batch_ = other.batch_;
other.batch_ = nullptr;
return *this;
Expand Down Expand Up @@ -121,8 +121,8 @@ bool batch<P, resrc>::operator==(batch<P, resrc> const &other) const
template<typename P, resource resrc>
P *batch<P, resrc>::operator()(int const position) const
{
tools::expect(position >= 0);
tools::expect(position < num_entries());
expect(position >= 0);
expect(position < num_entries());
return batch_[position];
}

Expand All @@ -136,29 +136,29 @@ void batch<P, resrc>::assign_entry(fk::matrix<P, mem, resrc> const &a,
{
// make sure this matrix is the
// same dimensions as others in batch
tools::expect(a.nrows() == nrows());
tools::expect(a.ncols() == ncols());
expect(a.nrows() == nrows());
expect(a.ncols() == ncols());

// if this is a batch of vectors,
// we won't check the single column
// matrix view a's stride
if (get_stride() != 1)
{
tools::expect(a.stride() == get_stride());
expect(a.stride() == get_stride());
}

// ensure position is valid
tools::expect(position >= 0);
tools::expect(position < num_entries());
expect(position >= 0);
expect(position < num_entries());

batch_[position] = a.data();
}

template<typename P, resource resrc>
void batch<P, resrc>::assign_raw(P *const a, int const position)
{
tools::expect(position >= 0);
tools::expect(position < num_entries());
expect(position >= 0);
expect(position < num_entries());
batch_[position] = a;
}

Expand Down Expand Up @@ -220,14 +220,14 @@ void batched_gemm(batch<P, resrc> const &a, batch<P, resrc> const &b,
batch<P, resrc> const &c, P const alpha, P const beta)
{
// check cardinality of sets
tools::expect(a.num_entries() == b.num_entries());
tools::expect(b.num_entries() == c.num_entries());
expect(a.num_entries() == b.num_entries());
expect(b.num_entries() == c.num_entries());

// not allowed by blas interface
// can be removed if we decide
// we need to consider the transpose
// of C later
tools::expect(!c.get_trans());
expect(!c.get_trans());

// check dimensions for gemm
//
Expand All @@ -239,9 +239,9 @@ void batched_gemm(batch<P, resrc> const &a, batch<P, resrc> const &b,
int const rows_b = b.get_trans() ? b.ncols() : b.nrows();
int const cols_b = b.get_trans() ? b.nrows() : b.ncols();

tools::expect(cols_a == rows_b);
tools::expect(c.nrows() == rows_a);
tools::expect(c.ncols() == cols_b);
expect(cols_a == rows_b);
expect(c.nrows() == rows_a);
expect(c.ncols() == cols_b);

// setup blas args
int m = rows_a;
Expand Down Expand Up @@ -271,21 +271,21 @@ void batched_gemv(batch<P, resrc> const &a, batch<P, resrc> const &b,
batch<P, resrc> const &c, P const alpha, P const beta)
{
// check cardinality of sets
tools::expect(a.num_entries() == b.num_entries());
tools::expect(b.num_entries() == c.num_entries());
expect(a.num_entries() == b.num_entries());
expect(b.num_entries() == c.num_entries());
int const num_entries = a.num_entries();

// our gemv will be set up for a column vector,
// so b cannot be transposed.
//
// we can remove either or both of these if
// we want to support more flexible operations
tools::expect(!b.get_trans() && !c.get_trans());
expect(!b.get_trans() && !c.get_trans());

// check dimensions for gemv
tools::expect((a.get_trans() ? a.nrows() : a.ncols()) == b.nrows());
tools::expect(b.ncols() == 1);
tools::expect(c.ncols() == 1);
expect((a.get_trans() ? a.nrows() : a.ncols()) == b.nrows());
expect(b.ncols() == 1);
expect(c.ncols() == 1);

// setup blas args
int m = a.nrows();
Expand Down Expand Up @@ -341,15 +341,15 @@ batch_chain<P, resrc, method>::batch_chain(
fk::vector<P, mem_type::view, resrc> &final_output)
{
/* validation */
tools::expect(matrices.size() > 0);
tools::expect(workspace.size() == 2);
expect(matrices.size() > 0);
expect(workspace.size() == 2);

/* ensure "x" is correct size - should be the product of all the matrices
respective number of columns */
tools::expect(x.size() == std::accumulate(matrices.begin(), matrices.end(), 1,
[](int const i, auto const &m) {
return i * m.ncols();
}));
expect(x.size() == std::accumulate(matrices.begin(), matrices.end(), 1,
[](int const i, auto const &m) {
return i * m.ncols();
}));

/* these are used to index "workspace" - the input/output role alternates
between workspace[ 0 ] and workspace[ 1 ] in this algorithm */
Expand All @@ -358,8 +358,8 @@ batch_chain<P, resrc, method>::batch_chain(

/* ensure the workspaces are big enough for the problem */
int const workspace_len = calculate_workspace_length(matrices, x.size());
tools::expect(workspace[0].size() >= workspace_len);
tools::expect(workspace[1].size() >= workspace_len);
expect(workspace[0].size() >= workspace_len);
expect(workspace[1].size() >= workspace_len);

/*
The algorithm iterates over each matrix in "matrix" in reverse order,
Expand Down Expand Up @@ -488,8 +488,8 @@ batch_chain<P, resrc, method>::batch_chain(
template<typename P, resource resrc, chain_method method>
void batch_chain<P, resrc, method>::execute() const
{
tools::expect(left_.size() == right_.size());
tools::expect(right_.size() == product_.size());
expect(left_.size() == right_.size());
expect(right_.size() == product_.size());

for (int i = 0; i < static_cast<int>(left_.size()); ++i)
{
Expand Down Expand Up @@ -535,13 +535,13 @@ void build_system_matrix(PDE<P> const &pde, elements::table const &elem_table,
int const elem_size = static_cast<int>(std::pow(degree, pde.num_dims));
int const A_size = elem_size * elem_table.size();

tools::expect(A.ncols() == A_size && A.nrows() == A_size);
expect(A.ncols() == A_size && A.nrows() == A_size);

using key_type = std::pair<int, int>;
using val_type = fk::matrix<P, mem_type::owner, resource::host>;
std::map<key_type, val_type> coef_cache;

tools::expect(A.ncols() == A_size && A.nrows() == A_size);
expect(A.ncols() == A_size && A.nrows() == A_size);

// copy coefficients to host for subsequent use
for (int k = 0; k < pde.num_terms; ++k)
Expand All @@ -561,7 +561,7 @@ void build_system_matrix(PDE<P> const &pde, elements::table const &elem_table,
// calculate from the level/cell indices for each
// dimension
fk::vector<int> const coords = elem_table.get_coords(i);
tools::expect(coords.size() == pde.num_dims * 2);
expect(coords.size() == pde.num_dims * 2);
fk::vector<int> const elem_indices = linearize(coords);

int const global_row = i * elem_size;
Expand All @@ -578,7 +578,7 @@ void build_system_matrix(PDE<P> const &pde, elements::table const &elem_table,
{
// get linearized indices for this connected element
fk::vector<int> const coords_nD = elem_table.get_coords(j);
tools::expect(coords_nD.size() == pde.num_dims * 2);
expect(coords_nD.size() == pde.num_dims * 2);
fk::vector<int> const connected_indices = linearize(coords_nD);

// calculate the col portion of the
Expand Down
2 changes: 1 addition & 1 deletion src/batch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ inline int calculate_workspace_length(
for (iter = matrices.rbegin(); iter != matrices.rend(); ++iter)
{
c_prod *= iter->ncols();
tools::expect(c_prod > 0);
expect(c_prod > 0);
r_prod *= iter->nrows();
int const size = x_size / c_prod * r_prod;
greatest = std::max(greatest, size);
Expand Down
18 changes: 9 additions & 9 deletions src/batch_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,18 +546,18 @@ void test_batched_gemm(int const m, int const n, int const k, int const lda,
bool const trans_a = false, bool const trans_b = false,
P const alpha = 1.0, P const beta = 0.0)
{
tools::expect(m > 0);
tools::expect(n > 0);
tools::expect(k > 0);
expect(m > 0);
expect(n > 0);
expect(k > 0);

int const rows_a = trans_a ? k : m;
int const cols_a = trans_a ? m : k;
tools::expect(lda >= rows_a);
tools::expect(ldc >= m);
expect(lda >= rows_a);
expect(ldc >= m);

int const rows_b = trans_b ? n : k;
int const cols_b = trans_b ? k : n;
tools::expect(ldb >= rows_b);
expect(ldb >= rows_b);

std::vector<std::vector<fk::matrix<P, mem_type::owner, resrc>>> const
matrices = [=]() {
Expand Down Expand Up @@ -760,9 +760,9 @@ void test_batched_gemv(int const m, int const n, int const lda,
int const num_batch = 3, bool const trans_a = false,
P const alpha = 1.0, P const beta = 0.0)
{
tools::expect(m > 0);
tools::expect(n > 0);
tools::expect(lda >= m);
expect(m > 0);
expect(n > 0);
expect(lda >= m);

int const rows_a = trans_a ? n : m;
int const cols_a = trans_a ? m : n;
Expand Down
Loading