Skip to content

Commit

Permalink
Review and doc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
pratikvn committed Jul 26, 2023
1 parent a306100 commit 57539bc
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 95 deletions.
3 changes: 2 additions & 1 deletion core/base/batch_multi_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ void BatchMultiVector<ValueType>::move_to(
template <typename MatrixType, typename MatrixData>
void read_impl(MatrixType* mtx, const std::vector<MatrixData>& data)
{
GKO_ASSERT(data.size() > 0);
GKO_THROW_IF_INVALID(data.size() > 0, "Input data is empty");

auto common_size = data[0].size;
auto batch_size = batch_dim<2>(data.size(), common_size);
for (const auto& b : data) {
Expand Down
23 changes: 2 additions & 21 deletions cuda/base/batch_struct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace cuda {


/**
* Generates an immutable uniform batch struct from a batch of dense matrices.
* Generates an immutable uniform batch struct from a batch of multi-vectors.
*/
template <typename ValueType>
inline gko::batch_multi_vector::uniform_batch<const cuda_type<ValueType>>
Expand All @@ -72,7 +72,7 @@ get_batch_struct(const BatchMultiVector<ValueType>* const op)
}

/**
* Generates a uniform batch struct from a batch of dense matrices.
* Generates a uniform batch struct from a batch of multi-vectors.
*/
template <typename ValueType>
inline gko::batch_multi_vector::uniform_batch<cuda_type<ValueType>>
Expand All @@ -85,25 +85,6 @@ get_batch_struct(BatchMultiVector<ValueType>* const op)
}


/**
* Generates an immutable uniform batch struct from a batch of dense matrices
* that may be null.
*/
template <typename ValueType>
inline gko::batch_multi_vector::uniform_batch<const cuda_type<ValueType>>
maybe_null_batch_struct(const BatchMultiVector<ValueType>* const op)
{
if (op) {
return {as_cuda_type(op->get_const_values()),
op->get_num_batch_entries(), op->get_common_size()[1],
static_cast<int>(op->get_common_size()[0]),
static_cast<int>(op->get_common_size()[1])};
} else {
return {nullptr, 0, 0, 0, 0};
}
}


} // namespace cuda
} // namespace kernels
} // namespace gko
Expand Down
23 changes: 2 additions & 21 deletions dpcpp/base/batch_struct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace dpcpp {


/**
* Generates an immutable uniform batch struct from a batch of dense matrices.
* Generates an immutable uniform batch struct from a batch of multi-vectors.
*/
template <typename ValueType>
inline gko::batch_multi_vector::uniform_batch<const ValueType> get_batch_struct(
Expand All @@ -72,7 +72,7 @@ inline gko::batch_multi_vector::uniform_batch<const ValueType> get_batch_struct(


/**
* Generates a uniform batch struct from a batch of dense matrices.
* Generates a uniform batch struct from a batch of multi-vectors.
*/
template <typename ValueType>
inline gko::batch_multi_vector::uniform_batch<ValueType> get_batch_struct(
Expand All @@ -85,25 +85,6 @@ inline gko::batch_multi_vector::uniform_batch<ValueType> get_batch_struct(
}


/**
* Generates an immutable uniform batch struct from a batch of dense matrices
* that may be null.
*/
template <typename ValueType>
inline gko::batch_multi_vector::uniform_batch<const ValueType>
maybe_null_batch_struct(const BatchMultiVector<ValueType>* const op)
{
if (op) {
return {op->get_const_values(), op->get_num_batch_entries(),
op->get_common_size()[1],
static_cast<int>(op->get_common_size()[0]),
static_cast<int>(op->get_common_size()[1])};
} else {
return {nullptr, 0, 0, 0, 0};
}
}


} // namespace dpcpp
} // namespace kernels
} // namespace gko
Expand Down
23 changes: 2 additions & 21 deletions hip/base/batch_struct.hip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace hip {


/**
* Generates an immutable uniform batch struct from a batch of dense matrices.
* Generates an immutable uniform batch struct from a batch of multi-vectors.
*/
template <typename ValueType>
inline gko::batch_multi_vector::uniform_batch<const hip_type<ValueType>>
Expand All @@ -72,7 +72,7 @@ get_batch_struct(const BatchMultiVector<ValueType>* const op)
}

/**
* Generates a uniform batch struct from a batch of dense matrices.
* Generates a uniform batch struct from a batch of multi-vectors.
*/
template <typename ValueType>
inline gko::batch_multi_vector::uniform_batch<hip_type<ValueType>>
Expand All @@ -85,25 +85,6 @@ get_batch_struct(BatchMultiVector<ValueType>* const op)
}


/**
* Generates an immutable uniform batch struct from a batch of dense matrices
* that may be null.
*/
template <typename ValueType>
inline gko::batch_multi_vector::uniform_batch<const hip_type<ValueType>>
maybe_null_batch_struct(const BatchMultiVector<ValueType>* const op)
{
if (op) {
return {as_hip_type(op->get_const_values()),
op->get_num_batch_entries(), op->get_common_size()[1],
static_cast<int>(op->get_common_size()[0]),
static_cast<int>(op->get_common_size()[1])};
} else {
return {nullptr, 0, 0, 0, 0};
}
}


} // namespace hip
} // namespace kernels
} // namespace gko
Expand Down
20 changes: 11 additions & 9 deletions include/ginkgo/core/base/batch_multi_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,9 @@ std::unique_ptr<Matrix> batch_initialize(
{
using batch_multi_vector = BatchMultiVector<typename Matrix::value_type>;
size_type num_batch_entries = vals.size();
GKO_ASSERT(num_batch_entries > 0);
GKO_THROW_IF_INVALID(num_batch_entries > 0, "Input data is empty");
auto vals_begin = begin(vals);
size_type common_num_rows = vals_begin->size();
size_type common_num_rows = vals_begin ? vals_begin->size() : 0;
auto common_size = dim<2>(common_num_rows, 1);
for (auto& val : vals) {
GKO_ASSERT_EQ(common_num_rows, val.size());
Expand Down Expand Up @@ -624,7 +624,7 @@ std::unique_ptr<Matrix> batch_initialize(
{
using batch_multi_vector = BatchMultiVector<typename Matrix::value_type>;
size_type num_batch_entries = vals.size();
GKO_ASSERT(num_batch_entries > 0);
GKO_THROW_IF_INVALID(num_batch_entries > 0, "Input data is empty");
auto vals_begin = begin(vals);
size_type common_num_rows = vals_begin ? vals_begin->size() : 0;
size_type common_num_cols =
Expand Down Expand Up @@ -689,9 +689,10 @@ std::unique_ptr<Matrix> batch_initialize(
{
using batch_multi_vector = BatchMultiVector<typename Matrix::value_type>;
size_type num_batch_entries = num_vectors;
GKO_ASSERT(num_batch_entries > 0);
auto b_size =
batch_dim<2>(num_batch_entries, dim<2>(vals ? vals.size() : 0, 1));
GKO_THROW_IF_INVALID(num_batch_entries > 0 && vals.size() > 0,
"Input data is empty");
auto b_size = batch_dim<2>(num_batch_entries,
dim<2>(begin(vals) ? vals.size() : 0, 1));
auto tmp = batch_multi_vector::create(exec->get_master(), b_size);
for (size_type batch = 0; batch < num_vectors; batch++) {
size_type idx = 0;
Expand Down Expand Up @@ -736,9 +737,10 @@ std::unique_ptr<Matrix> batch_initialize(
std::shared_ptr<const Executor> exec, TArgs&&... create_args)
{
using batch_multi_vector = BatchMultiVector<typename Matrix::value_type>;
GKO_ASSERT(num_batch_entries > 0);
auto common_size =
dim<2>(vals ? vals.size() : 0, vals ? begin(vals)->size() : 0);
GKO_THROW_IF_INVALID(num_batch_entries > 0 && vals.size() > 0,
"Input data is empty");
auto common_size = dim<2>(begin(vals) ? vals.size() : 0,
begin(vals) ? begin(vals)->size() : 0);
batch_dim<2> b_size(num_batch_entries, common_size);
auto tmp = batch_multi_vector::create(exec->get_master(), b_size);
for (size_type batch = 0; batch < num_batch_entries; batch++) {
Expand Down
27 changes: 27 additions & 0 deletions include/ginkgo/core/base/exception_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,13 @@ inline T ensure_allocated_impl(T ptr, const std::string& file, int line,
"semi-colon warnings")


/**
* Throws an InvalidStateError with a user-specified message
*
* @param _message message to be displayed.
*
* @throw InvalidStateError.
*/
#define GKO_INVALID_STATE(_message) \
{ \
throw ::gko::InvalidStateError(__FILE__, __LINE__, __func__, \
Expand All @@ -716,6 +723,26 @@ inline T ensure_allocated_impl(T ptr, const std::string& file, int line,
"semi-colon warnings")


/**
* Throws an InvalidStateError if condition is not satisfied
*
* @param _condition the condition to check.
* @param _message message to be displayed.
*
* @throw InvalidStateError.
*/
#define GKO_THROW_IF_INVALID(_condition, _message) \
{ \
if (!_condition) { \
throw ::gko::InvalidStateError(__FILE__, __LINE__, __func__, \
_message); \
} \
} \
static_assert(true, \
"This assert is used to counter the false positive extra " \
"semi-colon warnings")


} // namespace gko


Expand Down
2 changes: 1 addition & 1 deletion include/ginkgo/core/base/range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ GKO_BIND_UNARY_RANGE_OPERATION_TO_OPERATOR(transpose_operation, transpose);


#define GKO_DEPRECATED_SIMPLE_BINARY_OPERATION(_deprecated_name, _name) \
struct [[deprecated("Please use " #_name)]] _deprecated_name : _name{};
struct [[deprecated("Please use " #_name)]] _deprecated_name : _name {}

#define GKO_DEFINE_SIMPLE_BINARY_OPERATION(_name, ...) \
struct _name { \
Expand Down
23 changes: 2 additions & 21 deletions reference/base/batch_struct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace host {


/**
* Generates an immutable uniform batch struct from a batch of dense matrices.
* Generates an immutable uniform batch struct from a batch of multi-vectors.
*/
template <typename ValueType>
inline gko::batch_multi_vector::uniform_batch<const ValueType> get_batch_struct(
Expand All @@ -74,7 +74,7 @@ inline gko::batch_multi_vector::uniform_batch<const ValueType> get_batch_struct(


/**
* Generates a uniform batch struct from a batch of dense matrices.
* Generates a uniform batch struct from a batch of multi-vectors.
*/
template <typename ValueType>
inline gko::batch_multi_vector::uniform_batch<ValueType> get_batch_struct(
Expand All @@ -87,25 +87,6 @@ inline gko::batch_multi_vector::uniform_batch<ValueType> get_batch_struct(
}


/**
* Generates an immutable uniform batch struct from a batch of dense matrices
* that may be null.
*/
template <typename ValueType>
inline gko::batch_multi_vector::uniform_batch<const ValueType>
maybe_null_batch_struct(const BatchMultiVector<ValueType>* const op)
{
if (op) {
return {op->get_const_values(), op->get_num_batch_entries(),
op->get_common_size()[1],
static_cast<int>(op->get_common_size()[0]),
static_cast<int>(op->get_common_size()[1])};
} else {
return {nullptr, 0, 0, 0, 0};
}
}


} // namespace host
} // namespace kernels
} // namespace gko
Expand Down

0 comments on commit 57539bc

Please sign in to comment.