Closed lebedov closed 8 years ago
Ok. Nice work figuring out your way through the spaghetti :-)
Note that I dont think you want to add 1
to clGlobalSTate.state? But even if you fix that, the code still wont work. I reckon it's somethign to do with the commetns in the following lines :-) :
https://github.com/hughperkins/pycltorch/blob/master/PyClTorch.pyx#L70
self.native = THClTensor_newv2(clGlobalState.state, 0) # FIXME get device from state
Since you've done the hard bit, I think we can modify the code as follows:
device = THClState_getDevice(clGlobalState.state)
print('device', device)
if len(args) == 0:
self.native = THClTensor_newv2(clGlobalState.state, device)
elif len(args) == 1:
self.native = THClTensor_newWithSize1d(clGlobalState.state, device, args[0])
elif len(args) == 2:
self.native = THClTensor_newWithSize2d(clGlobalState.state, device, args[0], args[1])
elif len(args) == 3:
self.native = THClTensor_newWithSize3d(clGlobalState.state, device, args[0], args[1], args[2])
elif len(args) == 4:
self.native = THClTensor_newWithSize4d(clGlobalState.state, device, args[0], args[1], args[2], args[3])
else:
raise Exception('Not implemented, len(args)=' + str(len(args)))
Closing - thanks!
I tried to add support for setting the device used by PyClTorch. Setting the GPU via the
setDevice
function defined in the below modification doesn't seem to work, however; any subsequent allocations of ClTensors, for instance, use whatever GPU was selected at initialization, andgetDevice
returns the same device number even after invokingsetDevice
. What am I missing?