Why can't self defined layers run on GPUs

Mudou: <p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/2/9/291afe1d9bea7473a91e220edd457588a2b1432a.png" data-download-href="https://discuss.pytorch.org/uploads/default/291afe1d9bea7473a91e220edd457588a2b1432a" title="20200919_084028"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/2/9/291afe1d9bea7473a91e220edd457588a2b1432a_2_640x500.png" alt="20200919_084028" data-base62-sha1="5RDphozze4tmc8N5Jxg7HbRFL2a" width="640" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/2/9/291afe1d9bea7473a91e220edd457588a2b1432a_2_640x500.png, https://discuss.pytorch.org/uploads/default/optimized/3X/2/9/291afe1d9bea7473a91e220edd457588a2b1432a_2_960x750.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/2/9/291afe1d9bea7473a91e220edd457588a2b1432a.png 2x" data-dominant-color="F2F2F2"><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">20200919_084028</span><span class="informations">1148×896 77.9 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><br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/5/6/567194e62c59706fae2359e7188f75c309feabb7.png" data-download-href="https://discuss.pytorch.org/uploads/default/567194e62c59706fae2359e7188f75c309feabb7" title="20200919_084106"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/5/6/567194e62c59706fae2359e7188f75c309feabb7_2_348x500.png" alt="20200919_084106" data-base62-sha1="ckIpq12b8KlG5yg9MAftueNcsGH" width="348" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/5/6/567194e62c59706fae2359e7188f75c309feabb7_2_348x500.png, https://discuss.pytorch.org/uploads/default/optimized/3X/5/6/567194e62c59706fae2359e7188f75c309feabb7_2_522x750.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/5/6/567194e62c59706fae2359e7188f75c309feabb7.png 2x" data-dominant-color="F4F2F2"><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">20200919_084106</span><span class="informations">593×852 64.4 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><br>
def forward( self, x ):<br>
start = time.time()<br>
out = self.Rconv2d( x )<br>
cost = time.time()-start<br>
out = self.maxpool1( out )<br>
out = self.block1( out )<br>
out = self.block2( out )<br>
out = self.block3( out )<br>
out = F.avg_pool2d( out, 7 )<br>
out = out.view( out.size(0), -1 )<br>
out = self.out_layer( out )<br>
total_cost = time.time()-start</p>
<p>print(cost/total_cost)<br>
return out</p>
<p>最后使用time模块查看该层执行效率，发现这个变换层模块占了模型99.9%的时间</p>

ptrblck: <p>From Google translate:</p>
<blockquote>
<p>Finally, use the time module to check the execution efficiency of this layer and find that this transformation layer module accounts for 99.9% of the model’s time</p>
</blockquote>
<p>Could you please use an online translate service, so that we could support you? <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=12" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<p>Custom layers can run on the GPU. However, since CUDA operations are asynchronous, you would have to synchronize the code via <code>torch.cuda.synchronize()</code> before starting and stopping the timer.</p>
<p>Also, please post code snippets by wrapping them into three backticks ```, which makes debugging easier.</p>

Mudou: <p>thanks for your reply. l will check my code</p>