-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.lua
71 lines (60 loc) · 1.84 KB
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
require "torch"
require "cutorch"
require 'ztorch'
-- include('THZCi.lua')
-- local THZCudaTensor_polar = C['THZCudaTensor_polar']
local zcutorch = paths.require("libzcutorch")
local ffi = require 'ffi'
local argcheck = require 'argcheck'
torch.ZCudaStorage.__tostring__ = torch.ZFloatStorage.__tostring__
torch.ZCudaTensor.__tostring__ = torch.ZFloatTensor.__tostring__
include('Tensor.lua')
include('test.lua')
local unpack = unpack or table.unpack
function zcutorch.withDevice(newDeviceID, closure)
local curDeviceID = cutorch.getDevice()
zcutorch.setDevice(newDeviceID)
local vals = {pcall(closure)}
zcutorch.setDevice(curDeviceID)
if vals[1] then
return unpack(vals, 2)
end
error(unpack(vals, 2))
end
-- Creates a FloatTensor using the CudaHostAllocator.
-- Accepts either a LongStorage or a sequence of numbers.
function zcutorch.createZCudaHostTensor(...)
local size
if not ... then
size = torch.LongTensor{0}
elseif torch.isStorage(...) then
size = torch.LongTensor(...)
else
size = torch.LongTensor{...}
end
local storage = torch.ZFloatStorage(zcutorch.CudaHostAllocator, size:prod())
return torch.ZFloatTensor(storage, 1, size:storage())
end
zcutorch.setHeapTracking(true)
-- zcutorch.polar = argcheck{
-- nonamed=true,
-- {name="src1", type=ctypename},
-- {name="src2", type=ctypename},
-- call = function(src1, src2)
-- ret = torch.ZCudaTensor(src1:size())
-- THZCudaTensor_polar(cutorch._state,ret, src1, src2)
-- return ret
-- end
-- }
--
-- torch.polar = argcheck{
-- nonamed=true,
-- {name="src1", type=ctypename},
-- {name="src2", type=ctypename},
-- call = function(src1, src2)
-- ret = torch.ZCudaTensor(src1:size())
-- THZCudaTensor_polar(cutorch._state,ret, src1, src2)
-- return ret
-- end
-- }
return zcutorch