This repository has been archived by the owner on Mar 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move properties out of namespace mr and add
forward_property
helper
- Loading branch information
Showing
15 changed files
with
195 additions
and
96 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
.upstream-tests/test/cuda/memory_resource/get_property/forward_property.pass.cpp
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,75 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++03, c++11 | ||
|
||
// cuda::forward_property | ||
#include <cuda/std/cassert> | ||
#include <cuda/memory_resource> | ||
|
||
struct prop_with_value { | ||
using value_type = int; | ||
}; | ||
struct prop {}; | ||
|
||
template<class Upstream> | ||
struct derived_plain : public cuda::forward_property<derived_plain<Upstream>, Upstream> | ||
{ | ||
__host__ __device__ constexpr Upstream upstream_resource() const noexcept { return Upstream{}; } | ||
}; | ||
|
||
struct upstream_with_valueless_property { | ||
__host__ __device__ friend constexpr void get_property(const upstream_with_valueless_property&, prop) {} | ||
}; | ||
static_assert( cuda::has_property<derived_plain<upstream_with_valueless_property>, prop>, ""); | ||
static_assert(!cuda::has_property<derived_plain<upstream_with_valueless_property>, prop_with_value>, ""); | ||
|
||
struct upstream_with_stateful_property { | ||
__host__ __device__ friend constexpr int get_property(const upstream_with_stateful_property&, prop_with_value) { | ||
return 42; | ||
} | ||
}; | ||
static_assert(!cuda::has_property<derived_plain<upstream_with_stateful_property>, prop>, ""); | ||
static_assert( cuda::has_property<derived_plain<upstream_with_stateful_property>, prop_with_value>, ""); | ||
|
||
struct upstream_with_both_properties { | ||
__host__ __device__ friend constexpr void get_property(const upstream_with_both_properties&, prop) {} | ||
__host__ __device__ friend constexpr int get_property(const upstream_with_both_properties&, prop_with_value) { | ||
return 42; | ||
} | ||
}; | ||
static_assert( cuda::has_property<derived_plain<upstream_with_both_properties>, prop>, ""); | ||
static_assert( cuda::has_property<derived_plain<upstream_with_both_properties>, prop_with_value>, ""); | ||
|
||
struct derived_override : public cuda::forward_property<derived_override, upstream_with_both_properties> | ||
{ | ||
__host__ __device__ constexpr upstream_with_both_properties upstream_resource() const noexcept { | ||
return upstream_with_both_properties{}; | ||
} | ||
__host__ __device__ friend constexpr int get_property(const derived_override&, prop_with_value) { | ||
return 1337; | ||
} | ||
}; | ||
|
||
__host__ __device__ constexpr bool test_stateful() { | ||
using derived_no_override = derived_plain<upstream_with_stateful_property>; | ||
const derived_no_override without_override{}; | ||
assert(get_property(without_override, prop_with_value{}) == 42); | ||
|
||
const derived_override with_override{}; | ||
assert(get_property(with_override, prop_with_value{}) == 1337); | ||
|
||
return true; | ||
} | ||
|
||
int main(int, char**) { | ||
test_stateful(); | ||
static_assert(test_stateful(), ""); | ||
return 0; | ||
} |
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
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
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.