-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Opt] Enforce the UT Coverity and add benchmark for transpose
#2421
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright (c) 2024, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <common/benchmark.hpp> | ||
|
||
#include <raft/core/resource/cuda_stream.hpp> | ||
#include <raft/linalg/matrix_vector_op.cuh> | ||
#include <raft/linalg/transpose.cuh> | ||
#include <raft/random/rng.cuh> | ||
#include <raft/util/cuda_utils.cuh> | ||
#include <raft/util/itertools.hpp> | ||
|
||
#include <rmm/device_uvector.hpp> | ||
|
||
namespace raft::bench::linalg { | ||
|
||
template <typename IdxT> | ||
struct transpose_input { | ||
IdxT rows, cols; | ||
}; | ||
|
||
template <typename IdxT> | ||
inline auto operator<<(std::ostream& os, const transpose_input<IdxT>& p) -> std::ostream& | ||
{ | ||
os << p.rows << "#" << p.cols; | ||
return os; | ||
} | ||
|
||
template <typename T, typename IdxT, typename Layout> | ||
struct TransposeBench : public fixture { | ||
TransposeBench(const transpose_input<IdxT>& p) | ||
: params(p), in(p.rows * p.cols, stream), out(p.rows * p.cols, stream) | ||
{ | ||
raft::random::RngState rng{1234}; | ||
raft::random::uniform(handle, rng, in.data(), p.rows * p.cols, (T)-10.0, (T)10.0); | ||
} | ||
|
||
void run_benchmark(::benchmark::State& state) override | ||
{ | ||
std::ostringstream label_stream; | ||
label_stream << params; | ||
state.SetLabel(label_stream.str()); | ||
|
||
loop_on_state(state, [this]() { | ||
auto input_view = | ||
raft::make_device_matrix_view<T, IdxT, Layout>(in.data(), params.rows, params.cols); | ||
auto output_view = raft::make_device_vector_view<T, IdxT, Layout>(out.data(), params.rows); | ||
raft::linalg::transpose(handle, | ||
input_view.data_handle(), | ||
output_view.data_handle(), | ||
params.rows, | ||
params.cols, | ||
handle.get_stream()); | ||
}); | ||
} | ||
|
||
private: | ||
transpose_input<IdxT> params; | ||
rmm::device_uvector<T> in, out; | ||
}; // struct TransposeBench | ||
|
||
const std::vector<transpose_input<int>> transpose_inputs_i32 = | ||
raft::util::itertools::product<transpose_input<int>>({10, 128, 256, 512, 1024}, | ||
{10000, 100000, 1000000}); | ||
|
||
RAFT_BENCH_REGISTER((TransposeBench<float, int, raft::row_major>), "", transpose_inputs_i32); | ||
RAFT_BENCH_REGISTER((TransposeBench<half, int, raft::row_major>), "", transpose_inputs_i32); | ||
|
||
RAFT_BENCH_REGISTER((TransposeBench<float, int, raft::col_major>), "", transpose_inputs_i32); | ||
RAFT_BENCH_REGISTER((TransposeBench<half, int, raft::col_major>), "", transpose_inputs_i32); | ||
|
||
} // namespace raft::bench::linalg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's not the part of the change, but it's advisable to use raft's helpers instread of
__xxx
functions unless you need a specific cache behavior (for which, maybe, we should add more helpers?..)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @achirkin , thank you for your suggestion! Yeah, you're right! Because
cublas<t>geam()
does not support the half. About thecublasLtMatrixTransform
. Let me see how many I can change. (would you like to suggest changing this PR or the next separate one to change all oftranspose
? )There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @achirkin, I just tested the
cublasLtMatrixTransform
benchmark and found that performance would be lower than the current implementation by around 10~20%. So, could I keep the current implementation temporarily:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rhdong lets create an issue for Artem’s suggested change and reference it in a todo comment in the corresponding kernel in the code. I think we should investigate this for sure so that we are utilizing math libs where at all possible (and not having to maintain both math libs and our own custom impls) but I do not think the further investigation should hold up this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, here it is: #2436