Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Make the tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
miscco committed Feb 16, 2023
1 parent d0a55c5 commit 572f73d
Show file tree
Hide file tree
Showing 18 changed files with 98 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ namespace forward_property {
return convertible_to_upstream{};
}
};
static_assert(!cuda::has_property<derived_with_converstin_upstream_resource, prop_with_value>);
static_assert(!cuda::has_property<derived_with_converstin_upstream_resource, prop_with_value>, "");

__host__ __device__ constexpr bool test_stateful() {
using derived_no_override = derived_plain<upstream_with_stateful_property>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ struct prop_with_value {
};
struct prop {};

static_assert(cuda::property_with_value<prop_with_value>);
static_assert(!cuda::property_with_value<prop>);
static_assert(cuda::property_with_value<prop_with_value>, "");
static_assert(!cuda::property_with_value<prop>, "");

struct valid_property {
friend void get_property(const valid_property&, prop) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,12 @@ struct async_resource {
int _val = 0;

_LIBCUDACXX_TEMPLATE(class Property)
(requires !cuda::property_with_value<Property> &&
_CUDA_VSTD::_One_of<Property, Properties...>) //
friend void get_property(const async_resource&, Property) noexcept {}
(requires (!cuda::property_with_value<Property>) && _CUDA_VSTD::_One_of<Property, Properties...>) //
friend void get_property(const async_resource&, Property) noexcept {}

_LIBCUDACXX_TEMPLATE(class Property)
(requires cuda::property_with_value<Property>&&
_CUDA_VSTD::_One_of<Property, Properties...>) //
friend typename Property::value_type
get_property(const async_resource& res, Property) noexcept {
(requires cuda::property_with_value<Property> && _CUDA_VSTD::_One_of<Property, Properties...>) //
friend typename Property::value_type get_property(const async_resource& res, Property) noexcept {
return res._val;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,12 @@ struct resource {
int _val = 0;

_LIBCUDACXX_TEMPLATE(class Property)
(requires !cuda::property_with_value<Property> &&
_CUDA_VSTD::_One_of<Property, Properties...>) //
friend void get_property(const resource&, Property) noexcept {}
(requires (!cuda::property_with_value<Property>) && _CUDA_VSTD::_One_of<Property, Properties...>) //
friend void get_property(const resource&, Property) noexcept {}

_LIBCUDACXX_TEMPLATE(class Property)
(requires cuda::property_with_value<Property>&&
_CUDA_VSTD::_One_of<Property, Properties...>) //
friend typename Property::value_type
get_property(const resource& res, Property) noexcept {
(requires cuda::property_with_value<Property> && _CUDA_VSTD::_One_of<Property, Properties...>) //
friend typename Property::value_type get_property(const resource& res, Property) noexcept {
return res._val;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++03, c++11
// UNSUPPORTED: nvrtc

// cuda::mr::async_resource_ref equality

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,12 @@ struct async_resource {
int _val = 0;

_LIBCUDACXX_TEMPLATE(class Property)
(requires !cuda::property_with_value<Property> &&
_CUDA_VSTD::_One_of<Property, Properties...>) //
friend void get_property(const async_resource&, Property) noexcept {}
(requires (!cuda::property_with_value<Property>) && _CUDA_VSTD::_One_of<Property, Properties...>) //
friend void get_property(const async_resource&, Property) noexcept {}

_LIBCUDACXX_TEMPLATE(class Property)
(requires cuda::property_with_value<Property>&&
_CUDA_VSTD::_One_of<Property, Properties...>) //
friend typename Property::value_type
get_property(const async_resource& res, Property) noexcept {
(requires cuda::property_with_value<Property> && _CUDA_VSTD::_One_of<Property, Properties...>) //
friend typename Property::value_type get_property(const async_resource& res, Property) noexcept {
return res._val;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,12 @@ struct async_resource_base {
bool operator!=(const async_resource_base& other) const { return false; }

_LIBCUDACXX_TEMPLATE(class Property)
(requires !cuda::property_with_value<Property> &&
_CUDA_VSTD::_One_of<Property, Properties...>) //
friend void get_property(const async_resource_base&, Property) noexcept {}
(requires (!cuda::property_with_value<Property>) && _CUDA_VSTD::_One_of<Property, Properties...>) //
friend void get_property(const async_resource_base&, Property) noexcept {}

_LIBCUDACXX_TEMPLATE(class Property)
(requires cuda::property_with_value<Property>&&
_CUDA_VSTD::_One_of<Property, Properties...>) //
friend typename Property::value_type
get_property(const async_resource_base& res, Property) noexcept {
(requires cuda::property_with_value<Property> && _CUDA_VSTD::_One_of<Property, Properties...>) //
friend typename Property::value_type get_property(const async_resource_base& res, Property) noexcept {
return 42;
}
};
Expand All @@ -58,7 +55,6 @@ template <class... Properties>
struct async_resource_derived_first
: public async_resource_base<Properties...> {
using super_t = async_resource_base<Properties...>;
using super_t::operator==;

async_resource_derived_first(const int val) : _val(val) {}

Expand All @@ -73,9 +69,12 @@ struct async_resource_derived_first
void deallocate_async(void* ptr, std::size_t, std::size_t,
cuda::stream_ref) override {}

bool operator==(const async_resource_derived_first& other) const { return true; }
bool operator!=(const async_resource_derived_first& other) const { return false; }

int _val = 0;
};
static_assert(cuda::mr::async_resource<async_resource_derived_first<> >);
static_assert(cuda::mr::async_resource<async_resource_derived_first<> >, "");

struct some_data {
int _val;
Expand All @@ -85,7 +84,6 @@ template <class... Properties>
struct async_resource_derived_second
: public async_resource_base<Properties...> {
using super_t = async_resource_base<Properties...>;
using super_t::operator==;

async_resource_derived_second(some_data* val) : _val(val) {}

Expand All @@ -100,6 +98,9 @@ struct async_resource_derived_second
void deallocate_async(void* ptr, std::size_t, std::size_t,
cuda::stream_ref) override {}

bool operator==(const async_resource_derived_second& other) const { return true; }
bool operator!=(const async_resource_derived_second& other) const { return false; }

some_data* _val = 0;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,55 +59,52 @@ struct async_resource {
int _val = 0;

_LIBCUDACXX_TEMPLATE(class Property)
(requires !cuda::property_with_value<Property> &&
_CUDA_VSTD::_One_of<Property, Properties...>) //
friend void get_property(const async_resource&, Property) noexcept {}
(requires (!cuda::property_with_value<Property>) && _CUDA_VSTD::_One_of<Property, Properties...>) //
friend void get_property(const async_resource&, Property) noexcept {}

_LIBCUDACXX_TEMPLATE(class Property)
(requires cuda::property_with_value<Property>&&
_CUDA_VSTD::_One_of<Property, Properties...>) //
friend typename Property::value_type
get_property(const async_resource& res, Property) noexcept {
(requires cuda::property_with_value<Property> && _CUDA_VSTD::_One_of<Property, Properties...>) //
friend typename Property::value_type get_property(const async_resource& res, Property) noexcept {
return res._val;
}
};

// Ensure we have the right size
static_assert(sizeof(cuda::mr::async_resource_ref<property_with_value<short>,
property_with_value<int> >) ==
(4 * sizeof(void*)));
(4 * sizeof(void*)), "");
static_assert(
sizeof(cuda::mr::async_resource_ref<property_with_value<short>,
property_without_value<int> >) ==
(3 * sizeof(void*)));
(3 * sizeof(void*)), "");
static_assert(sizeof(cuda::mr::async_resource_ref<property_without_value<short>,
property_with_value<int> >) ==
(3 * sizeof(void*)));
(3 * sizeof(void*)), "");
static_assert(
sizeof(cuda::mr::async_resource_ref<property_without_value<short>,
property_without_value<int> >) ==
(2 * sizeof(void*)));
(2 * sizeof(void*)), "");

_LIBCUDACXX_TEMPLATE(class Property, class Ref)
(requires !cuda::property_with_value<Property>) //
(requires (!cuda::property_with_value<Property>)) //
int InvokeIfWithValue(const Ref& ref) {
return -1;
}

_LIBCUDACXX_TEMPLATE(class Property, class Ref)
(requires cuda::property_with_value<Property>) //
(requires cuda::property_with_value<Property>) //
typename Property::value_type InvokeIfWithValue(const Ref& ref) {
return get_property(ref, Property{});
}

_LIBCUDACXX_TEMPLATE(class Property, class Ref)
(requires cuda::property_with_value<Property>) //
(requires cuda::property_with_value<Property>) //
int InvokeIfWithoutValue(const Ref& ref) {
return -1;
}

_LIBCUDACXX_TEMPLATE(class Property, class Ref)
(requires !cuda::property_with_value<Property>) //
(requires (!cuda::property_with_value<Property>)) //
int InvokeIfWithoutValue(const Ref& ref) {
get_property(ref, Property{});
return 1;
Expand Down Expand Up @@ -155,12 +152,12 @@ void test_property_forwarding() {
using ref = cuda::mr::async_resource_ref<property_with_value<short> >;

static_assert(cuda::mr::async_resource_with<res, property_with_value<short>,
property_with_value<int> >);
property_with_value<int> >, "");
static_assert(!cuda::mr::async_resource_with<ref, property_with_value<short>,
property_with_value<int> >);
property_with_value<int> >, "");

static_assert(
cuda::mr::async_resource_with<res, property_with_value<short> >);
cuda::mr::async_resource_with<res, property_with_value<short> >, "");
}

void test_async_resource_ref() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,12 @@ struct resource {
int _val = 0;

_LIBCUDACXX_TEMPLATE(class Property)
(requires !cuda::property_with_value<Property> &&
_CUDA_VSTD::_One_of<Property, Properties...>) //
friend void get_property(const resource&, Property) noexcept {}
(requires (!cuda::property_with_value<Property>) && _CUDA_VSTD::_One_of<Property, Properties...>) //
friend void get_property(const resource&, Property) noexcept {}

_LIBCUDACXX_TEMPLATE(class Property)
(requires cuda::property_with_value<Property>&&
_CUDA_VSTD::_One_of<Property, Properties...>) //
friend typename Property::value_type
get_property(const resource& res, Property) noexcept {
(requires cuda::property_with_value<Property> && _CUDA_VSTD::_One_of<Property, Properties...>) //
friend typename Property::value_type get_property(const resource& res, Property) noexcept {
return res._val;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,12 @@ struct resource {
int _val = 0;

_LIBCUDACXX_TEMPLATE(class Property)
(requires !cuda::property_with_value<Property> &&
_CUDA_VSTD::_One_of<Property, Properties...>) //
friend void get_property(const resource&, Property) noexcept {}
(requires (!cuda::property_with_value<Property>) && _CUDA_VSTD::_One_of<Property, Properties...>) //
friend void get_property(const resource&, Property) noexcept {}

_LIBCUDACXX_TEMPLATE(class Property)
(requires cuda::property_with_value<Property>&&
_CUDA_VSTD::_One_of<Property, Properties...>) //
friend typename Property::value_type
get_property(const resource& res, Property) noexcept {
(requires cuda::property_with_value<Property> && _CUDA_VSTD::_One_of<Property, Properties...>) //
friend typename Property::value_type get_property(const resource& res, Property) noexcept {
return res._val;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++03, c++11
// UNSUPPORTED: nvrtc

// cuda::mr::resource_ref equality

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,12 @@ struct resource {
int _val = 0;

_LIBCUDACXX_TEMPLATE(class Property)
(requires !cuda::property_with_value<Property> &&
_CUDA_VSTD::_One_of<Property, Properties...>) //
friend void get_property(const resource&, Property) noexcept {}
(requires (!cuda::property_with_value<Property>) && _CUDA_VSTD::_One_of<Property, Properties...>) //
friend void get_property(const resource&, Property) noexcept {}

_LIBCUDACXX_TEMPLATE(class Property)
(requires cuda::property_with_value<Property>&&
_CUDA_VSTD::_One_of<Property, Properties...>) //
friend typename Property::value_type
get_property(const resource& res, Property) noexcept {
(requires cuda::property_with_value<Property> && _CUDA_VSTD::_One_of<Property, Properties...>) //
friend typename Property::value_type get_property(const resource& res, Property) noexcept {
return res._val;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,33 +36,32 @@ struct resource_base {
bool operator!=(const resource_base& other) const { return false; }

_LIBCUDACXX_TEMPLATE(class Property)
(requires !cuda::property_with_value<Property> &&
_CUDA_VSTD::_One_of<Property, Properties...>) //
friend void get_property(const resource_base&, Property) noexcept {}
(requires (!cuda::property_with_value<Property>) && _CUDA_VSTD::_One_of<Property, Properties...>) //
friend void get_property(const resource_base&, Property) noexcept {}

_LIBCUDACXX_TEMPLATE(class Property)
(requires cuda::property_with_value<Property>&&
_CUDA_VSTD::_One_of<Property, Properties...>) //
friend typename Property::value_type
get_property(const resource_base& res, Property) noexcept {
(requires cuda::property_with_value<Property> && _CUDA_VSTD::_One_of<Property, Properties...>) //
friend typename Property::value_type get_property(const resource_base& res, Property) noexcept {
return 42;
}
};

template <class... Properties>
struct resource_derived_first : public resource_base<Properties...> {
using super_t = resource_base<Properties...>;
using super_t::operator==;

resource_derived_first(const int val) : _val(val) {}

void* allocate(std::size_t, std::size_t) override { return &_val; }

void deallocate(void* ptr, std::size_t, std::size_t) override {}

bool operator==(const resource_derived_first& other) const { return true; }
bool operator!=(const resource_derived_first& other) const { return false; }

int _val = 0;
};
static_assert(cuda::mr::resource<resource_derived_first<> >);
static_assert(cuda::mr::resource<resource_derived_first<> >, "");

struct some_data {
int _val;
Expand All @@ -71,14 +70,16 @@ struct some_data {
template <class... Properties>
struct resource_derived_second : public resource_base<Properties...> {
using super_t = resource_base<Properties...>;
using super_t::operator==;

resource_derived_second(some_data* val) : _val(val) {}

void* allocate(std::size_t, std::size_t) override { return &_val->_val; }

void deallocate(void* ptr, std::size_t, std::size_t) override {}

bool operator==(const resource_derived_second& other) const { return true; }
bool operator!=(const resource_derived_second& other) const { return false; }

some_data* _val = 0;
};

Expand Down
Loading

0 comments on commit 572f73d

Please sign in to comment.