tensorflow icon indicating copy to clipboard operation
tensorflow copied to clipboard

Provide GPU implementations for resize image methods

Open panmari opened this issue 10 years ago • 32 comments

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.

panmari avatar Dec 17 '15 14:12 panmari

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.

girving avatar Dec 19 '15 00:12 girving

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 .

martinwicke avatar Dec 19 '15 00:12 martinwicke

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.

girving avatar Dec 19 '15 00:12 girving

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.

girving avatar Dec 19 '15 00:12 girving

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 .

martinwicke avatar Dec 19 '15 01:12 martinwicke

Ah, all my comments are wrong if this is about image resizing.

girving avatar Dec 19 '15 01:12 girving

@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 .

martinwicke avatar Dec 19 '15 01:12 martinwicke

Given @panmari's recent pull request to extend the types supported by resize_image ops, I think it's those.

vrv avatar Dec 19 '15 01:12 vrv

Yes, as the @vrv and @martinwicke assumed, I meant the resize_image ops. I'll change the title to reflect that more clearly.

panmari avatar Dec 19 '15 15:12 panmari

Sorry to be the necromancer, but any plans on this?

TimZaman avatar Nov 29 '16 18:11 TimZaman

@TimZaman I think it's still contributions welcome. :)

girving avatar Nov 29 '16 18:11 girving

@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 avatar Nov 29 '16 18:11 TimZaman

@TimZaman It'd be better to send the wheel of cheese to whoever implements the feature. Not sure where best to advertise that, though.

girving avatar Nov 29 '16 18:11 girving

So what's this then https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/kernels/resize_bilinear_op_gpu.cu.cc

TimZaman avatar Feb 13 '17 09:02 TimZaman

Looks like someone did it, at least for bilinear. @panmari Should this be closed, or are there missing ones?

girving avatar Feb 13 '17 15:02 girving

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

yaroslavvb avatar Feb 13 '17 17:02 yaroslavvb

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?

panmari avatar Feb 14 '17 09:02 panmari

Cc @gpapan.

girving avatar Feb 14 '17 15:02 girving

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.

gpapan avatar Feb 14 '17 17:02 gpapan

cc @strin who gave me these numbers

yaroslavvb avatar Feb 14 '17 18:02 yaroslavvb