はい、簡単で簡単です。
例:
In [24]: import os
# select `GPU 0` for the whole session
In [25]: os.environ['CUDA_VISIBLE_DEVICES'] = '0'
# required `data type` (for GPU)
In [26]: dtype = torch.cuda.FloatTensor
# define `x` & `y` directly on GPU
In [27]: x = torch.randn(100, 100).type(dtype)
In [28]: y = torch.randn(100, 100).type(dtype)
# stay on GPU with desired `dtype`
In [31]: x.gt(y).type(dtype)
Out[31]:
0 1 1 ... 0 0 0
1 0 0 ... 1 0 1
1 1 1 ... 0 0 0
... ⋱ ...
1 1 1 ... 0 0 0
0 1 1 ... 1 1 1
1 0 1 ... 1 0 1
[torch.cuda.FloatTensor of size 100x100 (GPU 0)]
# sanity check :)
In [33]: x.gt(y).type(dtype).is_cuda
Out[33]: True
'(t1> t2).float()' – blckbird
は(t1> t2).float()[0]を使うとうまく動作します。ありがとうございます – Maximilian
私はそれを受け入れるでしょう回答を投稿する場合 – Maximilian