Skip to content
Open
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
10 changes: 10 additions & 0 deletions benchmark/blas/blas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ std::map<std::string, std::function<std::unique_ptr<BenchmarkOperation>(
exec, Generator{}, dims.n, dims.k, dims.m, dims.stride_A,
dims.stride_B, dims.stride_C);
}},
{"add_diag",
[](std::shared_ptr<const gko::Executor> exec, dimensions dims) {
return std::make_unique<AddDiagOperation<Generator>>(
exec, Generator{}, dims.n, dims.stride_A);
}},
{"sub_diag",
[](std::shared_ptr<const gko::Executor> exec, dimensions dims) {
return std::make_unique<SubDiagOperation<Generator>>(
exec, Generator{}, dims.n, dims.stride_A);
}},
{"prefix_sum32",
[](std::shared_ptr<const gko::Executor> exec, dimensions dims) {
return std::make_unique<PrefixSumOperation<gko::int32>>(exec,
Expand Down
74 changes: 74 additions & 0 deletions benchmark/blas/blas_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ DEFINE_string(
" norm (a = sqrt(x' * x)),\n"
" mm (C = A * B),\n"
" gemm (C = a * A * B + b * C)\n"
" add_diag (A = A + a * D)\n"
" sub_diag (A = A - a * D)\n"
"Non-numerical algorithms:\n"
" prefix_sum32 (x_i <- sum_{j=0}^{i-1} x_i, 32 bit indices)\n"
" prefix_sum64 ( 64 bit indices)\n"
Expand Down Expand Up @@ -373,6 +375,78 @@ class AdvancedApplyOperation : public BenchmarkOperation {
};


template <typename Generator>
class AddDiagOperation : public BenchmarkOperation {
public:
AddDiagOperation(std::shared_ptr<const gko::Executor> exec,
const Generator& generator, gko::size_type n,
gko::size_type stride)
{
// Since dense distributed matrices are not supported we can use
// local_size == global_size
A_ = generator.create_multi_vector_strided(exec, gko::dim<2>{n, n},
gko::dim<2>{n, n}, stride);
D_ = gko::matrix::Diagonal<etype>::create(exec, n);
alpha_ = gko::matrix::Dense<etype>::create(exec, gko::dim<2>{1, 1});

as_vector<Generator>(A_)->fill(1);
D_->read(gko::matrix_data<etype, itype>::diag(gko::dim<2>{n, n},
etype{2.2}));
alpha_->fill(1);
}

gko::size_type get_flops() const override { return A_->get_size()[0] * 2; }

gko::size_type get_memory() const override
{
return A_->get_size()[0] * 3 * sizeof(etype);
}

void run() override { as_vector<Generator>(A_)->add_scaled(alpha_, D_); }

private:
std::unique_ptr<gko::matrix::Dense<etype>> alpha_;
std::unique_ptr<gko::LinOp> A_;
std::unique_ptr<gko::matrix::Diagonal<etype>> D_;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the naming scheme here should match the operation description in the CLI flag. I adjusted it accordingly.

};


template <typename Generator>
class SubDiagOperation : public BenchmarkOperation {
public:
SubDiagOperation(std::shared_ptr<const gko::Executor> exec,
const Generator& generator, gko::size_type n,
gko::size_type stride)
{
// Since dense distributed matrices are not supported we can use
// local_size == global_size
A_ = generator.create_multi_vector_strided(exec, gko::dim<2>{n, n},
gko::dim<2>{n, n}, stride);
D_ = gko::matrix::Diagonal<etype>::create(exec, n);
alpha_ = gko::matrix::Dense<etype>::create(exec, gko::dim<2>{1, 1});

as_vector<Generator>(A_)->fill(1);
D_->read(gko::matrix_data<etype, itype>::diag(gko::dim<2>{n, n},
etype{2.2}));
alpha_->fill(1);
}

gko::size_type get_flops() const override { return A_->get_size()[0] * 2; }

gko::size_type get_memory() const override
{
return A_->get_size()[0] * 3 * sizeof(etype);
}

void run() override { as_vector<Generator>(A_)->sub_scaled(alpha_, D_); }

private:
std::unique_ptr<gko::matrix::Dense<etype>> alpha_;
std::unique_ptr<gko::LinOp> A_;
std::unique_ptr<gko::matrix::Diagonal<etype>> D_;
};


GKO_REGISTER_OPERATION(prefix_sum_nonnegative,
components::prefix_sum_nonnegative);

Expand Down
Loading