Skip to content

Commit a8187b8

Browse files
committed
Fix the polymorphic adaptor to actually use its template parameter.
Github NVIDIA#968
1 parent a6d41f6 commit a8187b8

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ thrust/system/cuda/detail/.gitignore
33
run
44
build
55
doc/html
6+
discrete_voronoi.pgm

examples/mr_basic.cu

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <thrust/mr/new.h>
33
#include <thrust/mr/pool.h>
44
#include <thrust/mr/disjoint_pool.h>
5+
#include <thrust/device_vector.h>
6+
#include <thrust/device_ptr.h>
57

68
#include <cassert>
79

@@ -43,6 +45,18 @@ int main()
4345
do_stuff_with_vector<thrust::host_vector<int, Alloc> >(alloc);
4446
}
4547

48+
{
49+
// use the global device_ptr-flavored device memory resource
50+
typedef thrust::device_ptr_memory_resource<thrust::device_memory_resource> Resource;
51+
thrust::mr::polymorphic_adaptor_resource<thrust::device_ptr<void> > adaptor(
52+
thrust::mr::get_global_resource<Resource>()
53+
);
54+
typedef thrust::mr::polymorphic_allocator<int, thrust::device_ptr<void> > Alloc;
55+
Alloc alloc(&adaptor);
56+
57+
do_stuff_with_vector<thrust::device_vector<int, Alloc> >(alloc);
58+
}
59+
4660
typedef thrust::mr::unsynchronized_pool_resource<
4761
thrust::mr::new_delete_resource
4862
> Pool;

thrust/mr/polymorphic_adaptor.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 NVIDIA Corporation
2+
* Copyright 2018-2019 NVIDIA Corporation
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,12 +31,12 @@ class polymorphic_adaptor_resource THRUST_FINAL : public memory_resource<Pointer
3131
{
3232
}
3333

34-
virtual void * do_allocate(std::size_t bytes, std::size_t alignment = THRUST_MR_DEFAULT_ALIGNMENT) THRUST_OVERRIDE
34+
virtual Pointer do_allocate(std::size_t bytes, std::size_t alignment = THRUST_MR_DEFAULT_ALIGNMENT) THRUST_OVERRIDE
3535
{
3636
return upstream_resource->allocate(bytes, alignment);
3737
}
3838

39-
virtual void do_deallocate(void * p, std::size_t bytes, std::size_t alignment) THRUST_OVERRIDE
39+
virtual void do_deallocate(Pointer p, std::size_t bytes, std::size_t alignment) THRUST_OVERRIDE
4040
{
4141
return upstream_resource->deallocate(p, bytes, alignment);
4242
}

0 commit comments

Comments
 (0)