3

Just a couple facts for setup:

  • Thrust doesn't operate in-place for all of it's operations.
  • You can supply custom allocators to thrust::device_vectors.

I've looked in thrust::system and thrust::system::cuda and haven't found anything that looks like a static system allocator. By that I mean, I can't see a way of replacing the allocator that thrust uses internally to allocate extra memory for the out-of-place algorithms.

I also find it hard to believe that the functions that are not in-place use the allocators for the given thrust::device_vectors to allocator working memory.

Question: Does thrust have a way of replacing the internal allocator with a user defined one?

Related questions:

implies that thrust operates out-of-place

example of custom thrust allocator

Community
  • 1
  • 1
maxywb
  • 2,275
  • 1
  • 19
  • 25

1 Answers1

3

Thrust's custom_temporary_allocation example demonstrates how to build your own custom allocator for the temporary storage used internally by Thrust algorithms. The example uses a caching scheme to perform allocation but in principle you could use any strategy you like.

Basically, the idea is to build a custom backend derived from the CUDA backend specifically for the purpose of customizing allocation. Then, when you'd like to use an algorithm with your custom allocator, you point Thrust at your custom backend when you call the algorithm.

Note that this feature requires Thrust 1.6 or better.

Jared Hoberock
  • 11,118
  • 3
  • 40
  • 76
  • Thank you. That example does make sense, but I have thrust 1.4 so it doesn't work for me. Is there a way to ensure that the thrust internals are using the proper allocator in older versions of thrust? – maxywb Aug 23 '12 at 18:27
  • I'm not sure what you mean by "proper allocator". Thrust versions older than 1.6 can't customize temporary allocation. – Jared Hoberock Aug 23 '12 at 18:58
  • Yeah I don't either. I didn't have a full understanding how thrust allocates when you pass a device_vector with a custom allocator to a thrust function. Playing around the with allocator example above answered it for me. Thanks again. – maxywb Aug 23 '12 at 19:37