-
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
Implement maybe-owning multi-dimensional container (mdbuffer) #1999
Merged
Merged
Changes from 168 commits
Commits
Show all changes
176 commits
Select commit
Hold shift + click to select a range
e24fd2e
Initial commit
tarang-jain b8cda77
Merge branch 'branch-23.04' of https://github.com/rapidsai/raft into …
tarang-jain 07dabfe
New commit
tarang-jain 64eb461
Merge branch 'branch-23.06' of https://github.com/rapidsai/raft into …
tarang-jain 21c2641
Update
tarang-jain c84daa6
Merge
tarang-jain 4ad421b
Merge
tarang-jain ea11b07
Merge
tarang-jain ab19410
build
tarang-jain 9870e9d
Test start
tarang-jain 51a2581
Test start
tarang-jain 552b21e
Merge branch 'branch-23.06' of https://github.com/rapidsai/raft into …
tarang-jain d0e7b2c
style changes
tarang-jain f72f7f8
merge
tarang-jain 05f9daa
merge dependencies.yaml
tarang-jain 0250931
Updates
tarang-jain 057743d
Merge branch 'branch-23.06' of https://github.com/rapidsai/raft into …
tarang-jain 20042b0
Debugging
tarang-jain 2d189c3
Update gtest
tarang-jain 53c4557
Merge branch 'branch-23.06' of https://github.com/rapidsai/raft into …
tarang-jain de753ae
Merge branch 'branch-23.06' of https://github.com/rapidsai/raft into …
tarang-jain 2f8b294
Some updates after reviews
tarang-jain 6539ef4
Use raft::resources
tarang-jain 1709521
Merge branch 'branch-23.06' of https://github.com/rapidsai/raft into …
tarang-jain 008bb5b
move exception
tarang-jain 5b97273
Updates after PR Reviews
tarang-jain 5be6ec2
Merge branch 'branch-23.06' of https://github.com/rapidsai/raft into …
tarang-jain 838bfef
Add container policy
tarang-jain e035e2e
further changes with container policy
tarang-jain cd91a88
Merge branch 'branch-23.06' of https://github.com/rapidsai/raft into …
tarang-jain 338c1a6
Some updates
tarang-jain 6468c24
update container_policy
tarang-jain 1bd5455
Merge branch 'branch-23.08' of https://github.com/rapidsai/raft into …
tarang-jain 81c6a81
Working build
tarang-jain 77ae593
Merge branch 'branch-23.08' of https://github.com/rapidsai/raft into …
tarang-jain 451815e
Update buffer accessor policy
tarang-jain b553369
Merge branch 'branch-23.08' of https://github.com/rapidsai/raft into …
tarang-jain b410f36
Style changes
tarang-jain 4731620
minor changes
tarang-jain 238d010
combine owning buffer cpu/gpu
tarang-jain 75cfcf1
update tests
tarang-jain 7b1909f
Updates
tarang-jain 5c041c4
Merge branch 'branch-23.08' of https://github.com/rapidsai/raft into …
tarang-jain 0bf6f87
Merge branch 'branch-23.08' into tarbuf
wphicks 1a1143f
Temporarily remove new files to bring back necessary ones
wphicks acceb61
Begin refactoring buffer container policies
wphicks fdefc34
Add placeholder resource for stream view in CUDA-free builds
wphicks 24223ed
Add infrastructure for CUDA-free build
wphicks c6f6354
Merge branch 'branch-23.08' into fea-mdbuffer
wphicks 4689052
Add initial set of CUDA-free tests
wphicks 1b7e1e5
Add variant types to mdbuffer
wphicks 5416ceb
Provide all mdarray/mdspan to mdbuffer conversions
wphicks 355b3d4
Begin creating buffer copy utilities
wphicks 601f65d
Merge branch 'branch-23.10' into fea-mdbuffer
wphicks 4770a83
Correct computation of dest indices
wphicks 28e8627
Merge branch 'branch-23.10' into fea-mdbuffer
wphicks 8237a74
Temporarily remove simd-accelerated copy
wphicks 022cf6e
Add initial mdspan copy utility implementation
wphicks a1776f4
Refactor copy properties detection
wphicks a970dad
Correct detection of mdspan copy paths
wphicks 9a2fa9e
Correct build errors
wphicks eac9de6
Provide passing 3D host transpose tests
wphicks 39cf094
Add working tests for cuBlas based transpose
wphicks 760b656
Add incomplete kernel tests
wphicks f8d435f
Remove old mdspan copy header
wphicks 4c4fbaf
Revert "Remove old mdspan copy header"
wphicks ad5c786
Remove correct mdspan copy header
wphicks 2e433ba
Correct std::apply workaround in CUDA
wphicks d669e42
Provide fully working copy kernel
wphicks ed663c8
Begin adding SIMD support
wphicks ab809e8
Revert "Begin adding SIMD support"
wphicks 49d871a
Disable initial SIMD implementation
wphicks cb24abc
Rename mdspan copy headers
wphicks 2a83c1b
Remove mdbuffer work and document mdspan copy
wphicks 4193b74
Merge branch 'branch-23.10' into fea-mdspan_copy
wphicks 624e4f3
Remove un-needed changes left over from mdbuffer
wphicks e9ef750
Add testing for CUDA-disabled builds
wphicks 06fe54d
Merge branch 'branch-23.10' into fea-mdspan_copy
wphicks 92046e0
Fix style and revert some unnecessary changes
wphicks a0a5b69
Remove changes related to mdbuffer
wphicks 58389ec
Remove change related to mdbuffer
wphicks 0a19ae5
Correctly handle proxy references in mdspan copy kernel
wphicks 0675207
Check for unique destination layout in any parallel copy
wphicks 8ad9434
Use perfect forwarding for copy wrappers
wphicks fdbc9ee
Correct comment for dimension iteration order
wphicks 21618ea
Add warning about copying to non-unique layouts
wphicks c31a898
Update mdbuffer constructors for greater versatility
wphicks 18d462e
Add benchmarks for mdspan copy
wphicks 4700199
Merge branch 'branch-23.10' into fea-mdspan_copy
wphicks 2cad1ed
Merge branch 'branch-23.10' into fea-mdspan_copy
wphicks 6e91a1c
Correct check for assignability in mdspan copy
wphicks 55e06fe
Add comment explaining intermediate storage
wphicks faa402a
Correct dtype compatibility test
wphicks 2eba34d
Provide cleaner compile error for using copy with unsupported types
wphicks ca77cf0
Merge branch 'branch-23.10' into fea-mdspan_copy
wphicks 4389b64
Update stream_view docs
wphicks 7416b73
Merge branch 'branch-23.10' into fea-mdspan_copy
wphicks 7f407ed
Merge branch 'branch-23.10' into fea-mdspan_copy
wphicks 62ac60a
Update stream view docs
wphicks 5bddcc8
Merge remote-tracking branch 'origin/fea-mdspan_copy' into fea-mdspan…
wphicks 9c858fc
Merge branch 'fea-mdspan_copy' into fea-mdbuffer
wphicks 8d2b25b
Restore changes removed in mdspan copy PR
wphicks 21b1970
Restore fail_container_policy
wphicks bd5a8f8
Merge branch 'branch-23.12' into fea-mdspan_copy
wphicks c926653
Restore variant utils header
wphicks a8b17a8
Add static asserts for mdspan_copyable
wphicks 722425c
Correct iteration in host-to-host copies
wphicks a539de3
Merge branch 'fea-mdspan_copy' into fea-mdbuffer
wphicks 8835834
Correct double definition from branch merge
wphicks 7d68a7b
Merge branch 'branch-23.12' into fea-mdbuffer
wphicks 9a8b52e
Add remaining constructor logic
wphicks 502dddd
Add additional mdbuffer constructors
wphicks f289b6e
Simplify mdbuffer implementation
wphicks e96d257
Create cuh/hpp split for mdbuffer
wphicks c344033
Fix compilation issues
wphicks 7939c69
Add deduction guides for mdbuffer constructors
wphicks 5ec364f
Fix pinned container policy implementation
wphicks 03ad7f9
Rework constructors to correctly handle all cases
wphicks 20073e1
Correct enable_ifs for construction from mdarray
wphicks e012d07
Correct pinned memory handling
wphicks 84cf006
Split off managed and pinned container policies
wphicks 7d1c93b
FIXME: Add debugging lines for managed destructor segfault
wphicks 4acd66e
Begin fixing incorrect separation of device and managed
wphicks 5bf79e5
Merge branch 'branch-23.12' into fea-mdbuffer
wphicks da0a09f
Ensure managed memory resource remains in scope
wphicks 98c6a3f
Revert "FIXME: Add debugging lines for managed destructor segfault"
wphicks 934aa94
Add missing includes for managed and pinned
wphicks fb26fd7
Fully separate managed and pinned headers
wphicks a0830e1
REVERT ME: Temporary workaround for serialization size issue
wphicks fd852bc
Update managed and pinned header splits
wphicks 4d7602b
Add mdbuffer docs
wphicks a9f24da
Update docs for managed and pinned memory
wphicks dc390fe
Add mdspan implicit conversion test
wphicks c5d4f0f
Merge branch 'branch-23.12' into fea-mdbuffer
wphicks eb4fddf
Merge branch 'branch-24.02' into fea-mdbuffer
wphicks 29bd6b4
Tweak mdbuffer example code
wphicks b84c290
Merge branch 'branch-24.02' into fea-mdbuffer
wphicks 1f0ad4f
Merge branch 'branch-24.02' into fea-mdbuffer
wphicks eb49608
Correct accessibility of pinned memory type
wphicks 8e9ade2
Merge branch 'branch-24.02' into fea-mdbuffer
wphicks 909b786
Add memory type dispatching
wphicks 51ab695
Correct handling of pinned memory in dispatcher
wphicks 36bbffe
Begin writing mdspan_dispatched_functor
wphicks 5458e5b
Remove mdspan_dispatched_functor
wphicks 5733005
Add docs for memory_type_dispatcher
wphicks e6ce9c3
Respond to review
wphicks 40d75cc
Merge remote-tracking branch 'origin/fea-mdbuffer' into fea-mdbuffer
wphicks 3da9348
Merge branch 'branch-24.02' into fea-mdbuffer
wphicks 3b1f245
Merge branch 'branch-24.02' into fea-mdbuffer
wphicks 50032c5
Merge branch 'branch-24.02' into fea-mdbuffer
wphicks f270e74
Merge branch 'branch-24.02' into fea-mdbuffer
wphicks 6bd6abd
Merge branch 'branch-24.02' into fea-mdbuffer
wphicks afb692c
Update docs to provide clearer layout-transposition example
wphicks eee7238
Update for increased implementation clarity based on review
wphicks 864477e
Update cpp/include/raft/util/memory_type_dispatcher.cuh
wphicks edbad93
Use implicit void pointer cast
wphicks 01b45e4
Add memory_type_dispatcher example to mdbuffer
wphicks 93ca677
Merge branch 'branch-24.02' into fea-mdbuffer
wphicks 272af80
Fix style
wphicks fbdafd0
Merge branch 'branch-24.02' into fea-mdbuffer
wphicks b0c87a5
Merge branch 'branch-24.02' into fea-mdbuffer
wphicks 9c48d98
Merge branch 'branch-24.02' into fea-mdbuffer
wphicks f4e2e60
Merge branch 'branch-24.02' into fea-mdbuffer
wphicks ccb56ab
Merge branch 'branch-24.02' into fea-mdbuffer
wphicks c1db8a5
Allow implicit conversion to const mdbuffer from non-const mdspan
wphicks 253ac7a
Safeguard default_container_policy against enum changes
wphicks bfdb234
Correctly mark make_*_view functions as constexpr
wphicks fca74aa
Remove commented-out deduction guide
wphicks f7d470e
Merge branch 'branch-24.02' into fea-mdbuffer
wphicks 6c74dd0
Change spelling of policy selector
wphicks 50373d2
Update usage of memory_type_to_default_policy_t
wphicks 8d87cbd
Add clarifying information on const-ness
wphicks db06e7b
Merge branch 'branch-24.02' into fea-mdbuffer
wphicks 0177cd4
Make enum values consistent with cudaMemoryType
wphicks e671bd6
Merge branch 'branch-24.02' into fea-mdbuffer
wphicks a993fb0
Merge branch 'branch-24.02' into fea-mdbuffer
wphicks 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/* | ||
* Copyright (c) 2023, 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. | ||
*/ | ||
|
||
#pragma once | ||
#include <raft/core/error.hpp> | ||
#include <raft/core/logger-macros.hpp> | ||
#include <raft/core/resources.hpp> | ||
#include <raft/thirdparty/mdspan/include/experimental/mdspan> | ||
#include <stddef.h> | ||
|
||
namespace raft { | ||
namespace detail { | ||
|
||
template <typename T> | ||
struct fail_reference { | ||
using value_type = typename std::remove_cv_t<T>; | ||
using pointer = T*; | ||
using const_pointer = T const*; | ||
|
||
fail_reference() = default; | ||
template <typename StreamViewType> | ||
fail_reference(T* ptr, StreamViewType stream) | ||
{ | ||
throw non_cuda_build_error{"Attempted to construct reference to device data in non-CUDA build"}; | ||
} | ||
|
||
operator value_type() const // NOLINT | ||
{ | ||
throw non_cuda_build_error{"Attempted to dereference device data in non-CUDA build"}; | ||
return value_type{}; | ||
} | ||
auto operator=(T const& other) -> fail_reference& | ||
{ | ||
throw non_cuda_build_error{"Attempted to assign to device data in non-CUDA build"}; | ||
return *this; | ||
} | ||
}; | ||
|
||
/** A placeholder container which throws an exception on use | ||
* | ||
* This placeholder is used in non-CUDA builds for container types that would | ||
* otherwise be provided with CUDA code. Attempting to construct a non-empty | ||
* container of this type throws an exception indicating that there was an | ||
* attempt to use the device from a non-CUDA build. An example of when this | ||
* might happen is if a downstream application attempts to allocate a device | ||
* mdarray using a library built with non-CUDA RAFT. | ||
*/ | ||
template <typename T> | ||
struct fail_container { | ||
using value_type = T; | ||
using size_type = std::size_t; | ||
|
||
using reference = fail_reference<T>; | ||
using const_reference = fail_reference<T const>; | ||
|
||
using pointer = value_type*; | ||
using const_pointer = value_type const*; | ||
|
||
using iterator = pointer; | ||
using const_iterator = const_pointer; | ||
|
||
explicit fail_container(size_t n = size_t{}) | ||
{ | ||
if (n != size_t{}) { | ||
throw non_cuda_build_error{"Attempted to allocate device container in non-CUDA build"}; | ||
} | ||
} | ||
|
||
template <typename Index> | ||
auto operator[](Index i) noexcept -> reference | ||
{ | ||
RAFT_LOG_ERROR("Attempted to access device data in non-CUDA build"); | ||
return reference{}; | ||
} | ||
|
||
template <typename Index> | ||
auto operator[](Index i) const noexcept -> const_reference | ||
{ | ||
RAFT_LOG_ERROR("Attempted to access device data in non-CUDA build"); | ||
return const_reference{}; | ||
} | ||
void resize(size_t n) | ||
{ | ||
if (n != size_t{}) { | ||
throw non_cuda_build_error{"Attempted to allocate device container in non-CUDA build"}; | ||
} | ||
} | ||
|
||
[[nodiscard]] auto data() noexcept -> pointer { return nullptr; } | ||
[[nodiscard]] auto data() const noexcept -> const_pointer { return nullptr; } | ||
}; | ||
|
||
/** A placeholder container policy which throws an exception on use | ||
* | ||
* This placeholder is used in non-CUDA builds for container types that would | ||
* otherwise be provided with CUDA code. Attempting to construct a non-empty | ||
* container of this type throws an exception indicating that there was an | ||
* attempt to use the device from a non-CUDA build. An example of when this | ||
* might happen is if a downstream application attempts to allocate a device | ||
* mdarray using a library built with non-CUDA RAFT. | ||
*/ | ||
template <typename ElementType> | ||
struct fail_container_policy { | ||
using element_type = ElementType; | ||
using container_type = fail_container<element_type>; | ||
using pointer = typename container_type::pointer; | ||
using const_pointer = typename container_type::const_pointer; | ||
using reference = typename container_type::reference; | ||
using const_reference = typename container_type::const_reference; | ||
|
||
using accessor_policy = std::experimental::default_accessor<element_type>; | ||
using const_accessor_policy = std::experimental::default_accessor<element_type const>; | ||
|
||
auto create(raft::resources const& res, size_t n) -> container_type { return container_type(n); } | ||
|
||
fail_container_policy() = default; | ||
|
||
[[nodiscard]] constexpr auto access(container_type& c, size_t n) const noexcept -> reference | ||
{ | ||
return c[n]; | ||
} | ||
[[nodiscard]] constexpr auto access(container_type const& c, size_t n) const noexcept | ||
-> const_reference | ||
{ | ||
return c[n]; | ||
} | ||
|
||
[[nodiscard]] auto make_accessor_policy() noexcept { return accessor_policy{}; } | ||
[[nodiscard]] auto make_accessor_policy() const noexcept { return const_accessor_policy{}; } | ||
}; | ||
|
||
} // namespace detail | ||
} // namespace raft |
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
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.
Can we add this and other such declarations to
detail/fail_container_policy.hpp
? Easier to find them all in one location, and just include the header hereThere 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 just realized one disadvantage to that. It may be useful in certain contexts to use
fail_*
on their own without having CUDA compilation disabled. If we put the declarations infail_container_policy.hpp
there is no way to do that.