Provide GPU implementations for resize image methods
As far as I can tell, these operations are only provided on CPU so far. It would be very convenient to also have GPU implementations. I'll have a go at it if there's nobody else working on it.
Edit: I mean methods such as resize_nearest_neighbor, not the reshape operator.
Tensors on the GPU still store their shapes on the CPU, and reshape already works in that case. The shape will never be stored on the GPU, so I think this should be closed. Presumably you're seeing an error caused by forcing the shape argument onto the GPU; if so there should possibly be a different bug about placer functionality.
Wouldn't tf.shape return a tensor that could be shipped onto the GPU? In that case, all information could be on the GPU, and the actual resizing code should be able to run on the GPU.
On Fri, Dec 18, 2015 at 4:41 PM Geoffrey Irving [email protected] wrote:
Tensors on the GPU still store their shapes on the CPU, and reshape already works in that case. The shape will never be stored on the GPU, so I think this should be closed. Presumably you're seeing an error caused by forcing the shape argument onto the GPU; if so there should possibly be a different bug about placer functionality.
— Reply to this email directly or view it on GitHub https://github.com/tensorflow/tensorflow/issues/533#issuecomment-165927888 .
The Tensor C++ class unconditionally stores the shape on the CPU regardless of where the data is, and essentially everything assumes this (for error detection, branching, etc.). I think there's very little chance this situation will change.
Note that as long as all the shape data is on the CPU, a reshape does O(0) GPU work even if the data is on the GPU.
I think I'm implicitly assuming we're talking about the resize_image ops. Sorry, that may be misinterpreting panmari's original request.
On Fri, Dec 18, 2015 at 4:54 PM Geoffrey Irving [email protected] wrote:
Note that as long as all the shape data is on the CPU, a reshape does O(0) GPU work even if the data is on the GPU.
— Reply to this email directly or view it on GitHub https://github.com/tensorflow/tensorflow/issues/533#issuecomment-165929024 .
Ah, all my comments are wrong if this is about image resizing.
@panmari -- which ops are you thinking about?
On Fri, Dec 18, 2015 at 5:06 PM Geoffrey Irving [email protected] wrote:
Ah, all my comments are wrong if this is about image resizing.
— Reply to this email directly or view it on GitHub https://github.com/tensorflow/tensorflow/issues/533#issuecomment-165929904 .
Given @panmari's recent pull request to extend the types supported by resize_image ops, I think it's those.
Yes, as the @vrv and @martinwicke assumed, I meant the resize_image ops. I'll change the title to reflect that more clearly.
Sorry to be the necromancer, but any plans on this?
@TimZaman I think it's still contributions welcome. :)
@girving I will send you a wheel of cheese from the Netherlands if you get someone to implement this. All bribes aside, this PR matched with this issue: https://github.com/tensorflow/tensorflow/pull/588 but sadly it's the lowest quality algo.
@TimZaman It'd be better to send the wheel of cheese to whoever implements the feature. Not sure where best to advertise that, though.
So what's this then https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/kernels/resize_bilinear_op_gpu.cu.cc
Looks like someone did it, at least for bilinear. @panmari Should this be closed, or are there missing ones?
PS resize bilinear and resize bicubic GPU implementations are slow (about 2 seconds for resizing 375 x 667 to 1280 x 1280, same as on CPU), when we switched to nearest neighbor, it made our CNN run 10x faster, see discussion in https://github.com/tensorflow/tensorflow/commit/c02edfa8c97c2cb0133534badc23dda0521e54ff#commitcomment-20615000
I did the implementation for nearest neighbor in #588 (funny enough, blame doesn't show me anymore). That algorithm is good enough for my purposes and I've been using it since. So from my side, we can close this bug @girving. But there might be others that want fast implementations for other algorithms such as @TimZaman. Maybe I'll come around and do some benchmarking of the current implementation of bilinear and see what can be done. Who's the author of it?
Cc @gpapan.
I did the gpu implementation for bilinear interpolation. The Cuda kernel can get faster (e.g., have each thread compute multiple channels reusing the indexing arithmetic). However, I find the quoted "(about 2 seconds for resizing 375 x 667 to 1280 x 1280, same as on CPU)" too large. What is the benchmark used? Are we certain that the gpu path is activated? Which gpu? What is the depth of the tensors? Does this cover forward only or both forward and backward? In any case, I think writing a benchmark suite is the first step that we should accomplish.
cc @strin who gave me these numbers