-
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
Expose linalg::dot
in public API
#968
Merged
Merged
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
01dd067
Expose `linalg::dot` in public API
benfred e6a5bb1
formatting
benfred 400dfa9
Merge branch 'branch-22.12' into linalg_dot
benfred f376c51
Updates from code review
benfred 9c9efe8
Update axpy to take a device_vector_view
benfred 2bf4eae
Changes from codereview
benfred 2e1c0e6
remove dot w/ host pointer overload
benfred a668098
Added docs / created 'make_strided_layout' factory function
benfred 977949f
Add doxygen for make_strided_layout
benfred a125c4f
fix
benfred 6f8a76c
Test out host and device api's
benfred af52c0c
Merge remote-tracking branch 'origin/branch-22.12' into linalg_dot
benfred 25333ee
test out both device/host alpha scalar overloads with dot
benfred 98f7d85
Fix docstring
benfred 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
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,59 @@ | ||
/* | ||
* Copyright (c) 2022, 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. | ||
*/ | ||
#ifndef __DOT_H | ||
#define __DOT_H | ||
|
||
#pragma once | ||
|
||
#include <raft/linalg/detail/cublas_wrappers.hpp> | ||
|
||
#include <raft/core/device_mdspan.hpp> | ||
#include <raft/core/handle.hpp> | ||
#include <raft/core/host_mdspan.hpp> | ||
|
||
namespace raft::linalg { | ||
/** | ||
* @brief Computes the dot product of two vectors. | ||
* @param[in] handle raft::handle_t | ||
* @param[in] x First input vector | ||
* @param[in] y Second input vector | ||
* @param[out] out The output dot product between the x and y vectors. | ||
* @note The out parameter can be either a host_scalar_view or device_scalar_view | ||
*/ | ||
template <typename ElementType, | ||
typename IndexType = std::uint32_t, | ||
benfred marked this conversation as resolved.
Show resolved
Hide resolved
|
||
typename ScalarIndexType = std::uint32_t, | ||
typename LayoutPolicy1 = layout_c_contiguous, | ||
typename LayoutPolicy2 = layout_c_contiguous> | ||
void dot(const raft::handle_t& handle, | ||
raft::device_vector_view<const ElementType, IndexType, LayoutPolicy1> x, | ||
raft::device_vector_view<const ElementType, IndexType, LayoutPolicy2> y, | ||
raft::device_scalar_view<ElementType, ScalarIndexType> out) | ||
benfred marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
RAFT_EXPECTS(x.size() == y.size(), | ||
"Size mismatch between x and y input vectors in raft::linalg::dot"); | ||
|
||
RAFT_CUBLAS_TRY(detail::cublasdot(handle.get_cublas_handle(), | ||
x.size(), | ||
x.data_handle(), | ||
x.stride(0), | ||
y.data_handle(), | ||
y.stride(0), | ||
out.data_handle(), | ||
handle.get_stream())); | ||
} | ||
} // namespace raft::linalg | ||
#endif |
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
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.
This is a little awkward. We accept a layout policy as a template argument, but then we also accept a function argument for a stride which essentially overrides the layout from the template.
Would it be achieving this same goal if a user were to just set a strided layout on the template argument directly? Perhaps we could provide a factory function to make said strided layout and provide the user with something like a statically sized object (eg. std::array) to set the strides for each dimension?
An of course, this is one of those things (the new strided factory function) that I think should have a usage example in the doxygen and perhaps even a subsection section in the mdspan tutorial markdown of the docs.
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.
If I'm understanding you correctly - you're thinking we can just pass the layout mapping to the
make_device_vector_view
function directly , and add a new factory function for creating this layout mapping?I took a stab at that in the last commit - unfortunately, I couldn't get a single
make_device_vector_view
function to compile successfully with being passed both a IndexType with the number of elements and the Mapping with the strided layout (was getting compile errors in various other raft functions that I hadn't updated). However, I could get it to work with adding an overload - which is whats in the last commit. Do you have any suggestions on how to clean this up =) ?I'll add something to the tutorial / docs once we're happy with the API -