Nn.functional.interpolate is really slow

username: m732367606
cooked: <p>It seems nn.functional.interpolate is working on CPU instead of GPU.<br>
The CPU occupancy is 100%, however the GPU occupancy  is merely 11%.<br>
Here are the parts my model forward codes, I wrote the nn.functional.interpolate into it.<br>
Can the nn.functional.interpolate function be ran by cuda?</p>
<pre><code class="lang-auto">    def forward(self, x):
        x = nn.functional.interpolate(x, scale_factor=self.scale, mode='bicubic',align_corners=True)
        return x
</code></pre>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/c/cd7338cd258c43710f3c500c96dae90695c64dbb.png" data-download-href="https://discuss.pytorch.org/uploads/default/cd7338cd258c43710f3c500c96dae90695c64dbb" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/2X/c/cd7338cd258c43710f3c500c96dae90695c64dbb.png" alt="image" data-base62-sha1="tjuK4N5RGhRX2LtsjcMSHyO67xN" width="533" height="500" data-dominant-color="AEACA7"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">823×772 13.7 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

username: m732367606
cooked: <p><img src="https://discuss.pytorch.org/images/emoji/apple/face_with_head_bandage.png?v=9" title=":face_with_head_bandage:" class="emoji" alt=":face_with_head_bandage:"><img src="https://discuss.pytorch.org/images/emoji/apple/face_with_head_bandage.png?v=9" title=":face_with_head_bandage:" class="emoji" alt=":face_with_head_bandage:"><img src="https://discuss.pytorch.org/images/emoji/apple/face_with_head_bandage.png?v=9" title=":face_with_head_bandage:" class="emoji" alt=":face_with_head_bandage:"></p>

username: m732367606
cooked: <p><img src="https://discuss.pytorch.org/images/emoji/apple/face_with_raised_eyebrow.png?v=9" title=":face_with_raised_eyebrow:" class="emoji" alt=":face_with_raised_eyebrow:"><img src="https://discuss.pytorch.org/images/emoji/apple/face_with_raised_eyebrow.png?v=9" title=":face_with_raised_eyebrow:" class="emoji" alt=":face_with_raised_eyebrow:">Did somebody also encounter this problem?</p>

username: ptrblck
cooked: <p>I cannot reproduce this issue.<br>
Are you sure <code>F.interpolate</code> is using the CPUs?<br>
This code snippet utilizes the GPU 100% and a single CPU code, which seems to be fine:</p>
<pre><code class="lang-python">import torch
import torch.nn as nn
import torch.nn.functional as F

import time


class MyModel(nn.Module):
    def __init__(self, scale_factor=2):
        super(MyModel, self).__init__()
        self.scale_factor = scale_factor
        
    def forward(self, x):
        x = F.interpolate(x, scale_factor=self.scale_factor, mode='bicubic',align_corners=True)
        return x


model = MyModel()

b, c, h, w = 64, 3, 128, 128
x = torch.randn(b, c, h, w, device='cuda')

nb_iters = 100000

torch.cuda.synchronize()
t0 = time.perf_counter()

for _ in range(nb_iters):
    output = model(x)
    
torch.cuda.synchronize()
t1 = time.perf_counter()

print('Took {}s, {}s per iter'.format((t1 - t0), (t1 - t0)/nb_iters))
</code></pre>
<p>Could you try this code?</p>

username: m732367606
cooked: <p><img src="https://discuss.pytorch.org/images/emoji/apple/face_with_head_bandage.png?v=9" title=":face_with_head_bandage:" class="emoji" alt=":face_with_head_bandage:">Dear ptrblck. It was found that high CPU occupancy was caused by slow dataloader during training data preparing process instead of nn.functional.interpolate.<br>
<img src="https://discuss.pytorch.org/images/emoji/apple/sob.png?v=9" title=":sob:" class="emoji" alt=":sob:">It was all my fault.<br>
Thank you for your help sincerely!<img src="https://discuss.pytorch.org/images/emoji/apple/smile_cat.png?v=9" title=":smile_cat:" class="emoji" alt=":smile_cat:"><img src="https://discuss.pytorch.org/images/emoji/apple/zipper_mouth_face.png?v=9" title=":zipper_mouth_face:" class="emoji" alt=":zipper_mouth_face:"><img src="https://discuss.pytorch.org/images/emoji/apple/zipper_mouth_face.png?v=9" title=":zipper_mouth_face:" class="emoji" alt=":zipper_mouth_face:"></p>