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.
Implement
cuda::get_property
niebloid
- Loading branch information
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
.upstream-tests/test/cuda/memory_resource/get_property/get_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,61 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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::get_property | ||
#include <cuda/std/cassert> | ||
#include <cuda/memory_resource> | ||
|
||
struct prop_with_value { | ||
using value_type = int; | ||
}; | ||
struct prop {}; | ||
|
||
struct upstream_with_valueless_property { | ||
friend constexpr void get_property(const upstream_with_valueless_property&, prop) {} | ||
}; | ||
static_assert( cuda::std::invocable<decltype(cuda::get_property), upstream_with_valueless_property, prop>, ""); | ||
static_assert(!cuda::std::invocable<decltype(cuda::get_property), upstream_with_valueless_property, prop_with_value>, ""); | ||
|
||
struct upstream_with_stateful_property { | ||
friend constexpr int get_property(const upstream_with_stateful_property&, prop_with_value) { | ||
return 42; | ||
} | ||
}; | ||
static_assert(!cuda::std::invocable<decltype(cuda::get_property), upstream_with_stateful_property, prop>, ""); | ||
static_assert( cuda::std::invocable<decltype(cuda::get_property), upstream_with_stateful_property, prop_with_value>, ""); | ||
|
||
struct upstream_with_both_properties { | ||
friend constexpr void get_property(const upstream_with_both_properties&, prop) {} | ||
friend constexpr int get_property(const upstream_with_both_properties&, prop_with_value) { | ||
return 42; | ||
} | ||
}; | ||
static_assert( cuda::std::invocable<decltype(cuda::get_property), upstream_with_both_properties, prop>, ""); | ||
static_assert( cuda::std::invocable<decltype(cuda::get_property), upstream_with_both_properties, prop_with_value>, ""); | ||
|
||
__host__ __device__ constexpr bool test() { | ||
upstream_with_valueless_property with_valueless{}; | ||
cuda::get_property(with_valueless, prop{}); | ||
|
||
upstream_with_stateful_property with_value{}; | ||
assert(cuda::get_property(with_value, prop_with_value{}) == 42); | ||
|
||
upstream_with_both_properties with_both{}; | ||
cuda::get_property(with_both, prop{}); | ||
assert(cuda::get_property(with_both, prop_with_value{}) == 42); | ||
return true; | ||
} | ||
|
||
int main(int, char**) { | ||
test(); | ||
static_assert(test(), ""); | ||
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