artyom-beilis / pytorch_dlprim

DLPrimitives/OpenCL out of tree backend for pytorch
http://blog.dlprimitives.org/
MIT License
227 stars 16 forks source link

tensor comparison work error under some testdata!!! #36

Open Xrigok opened 1 year ago

Xrigok commented 1 year ago

I meet a stranger problem:tensor comparison work error at some test data, other test data is correct, is strange problem this my code:

import torch import torch.nn as nn import torch.nn.functional as F import numpy as np

device="ocl:0" if device.find('ocl')==0: torch.ops.load_library("../libpt_ocl.so") device = device.replace('ocl','privateuseone')

y=[5.7657e-05, 11.25,2.2863e-05, 1.5291e-05, 9.2284e-06, 1.2024e-05, 1.1976e-05,1.4908e-05, 1.6296e-05, 1.3599e-05, 1.7960e-05]

im = torch.tensor(y, dtype=torch.float32) im=im.to(device) print(im>0.25)

z=[0.1] im2 = torch.tensor(z, dtype=torch.float32) print(im2) print(im2>0.25) im2=im2.to(device) print(im2) print(im2>0.25)

image

artyom-beilis commented 1 year ago

I don't understand your example. Can you elaborate?

Xrigok commented 1 year ago

z=[0.1] im2 = torch.tensor(z, dtype=torch.float32) print(im2) now,output im2=》0.1, and im2 device is cpu, print(im2>0.25)=》False(this output is correct)

Here,we put im2 to opencl device im2=im2.to(device) and, we print im2>0.25: print(im2>0.25) this output is True,and the output is uncorrrect. It should to output False I check the compare kernel and print scale in kernel, w(scale) is 0 of above example

artyom-beilis commented 1 year ago

Ok thanks got it!