Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Artifacts.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
[[torch]]
git-tree-sha1 = "21fba0f64d7e6dce93146b84ba73226f4f0f0983"
os = "macos"
arch = "x86_64"
git-tree-sha1 = "21fba0f64d7e6dce93146b84ba73226f4f0f0983"
os = "macos"

[[torch.download]]
sha256 = "21fba0f64d7e6dce93146b84ba73226f4f0f0983"
sha256 = "84e9112b442ee1e3dc9e078d9066a855a2344ec566616cffbff1662e08cd8bf7"
url = "https://download.pytorch.org/libtorch/cpu/libtorch-macos-1.4.0.zip"

[[torch]]
arch = "x86_64"
git-tree-sha1 = "42bc9814d06d949098f5ab218be61adaa3e29c06"
os = "linux"

[[torch.download]]
sha256 = "42bc9814d06d949098f5ab218be61adaa3e29c06"
sha256 = "f214bfde532877aa5d4e0803e51a28fa8edd97b6a44b6615f75a70352b6b542e"
url = "https://download.pytorch.org/libtorch/cu101/libtorch-cxx11-abi-shared-with-deps-1.4.0.zip"


17 changes: 17 additions & 0 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ git-tree-sha1 = "5b08ed6036d9d3f0ee6369410b830f8873d4024c"
uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
version = "0.5.8"

[[CEnum]]
git-tree-sha1 = "62847acab40e6855a9b5905ccb99c2b5cf6b3ebb"
uuid = "fa961155-64e5-5f13-b03f-caf6b980ea82"
version = "0.2.0"

[[CUDAapi]]
deps = ["Libdl", "Logging"]
git-tree-sha1 = "d7ceadd8f821177d05b897c0517e94633db535fe"
uuid = "3895d2a7-ec45-59b8-82bb-cfc6a382f9b3"
version = "3.1.0"

[[CUDAdrv]]
deps = ["CEnum", "CUDAapi", "Printf"]
git-tree-sha1 = "01e90fa34e25776bc7c8661183d4519149ebfe59"
uuid = "c5f51814-7f29-56b8-a69c-e4d8f6be1fde"
version = "6.0.0"

[[Codecs]]
deps = ["Test"]
git-tree-sha1 = "70885e5e038cba1c4c17a84ad6c40756e10a4fb5"
Expand Down
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ authors = ["dhairyagandhi96 "]
version = "0.1.0"

[deps]
CUDAdrv = "c5f51814-7f29-56b8-a69c-e4d8f6be1fde"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
NNlib = "872c559c-99b0-510c-b3b7-b6c96a88d5cd"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,10 @@ tip = tensor(ip, dev = 0) # 0 => GPU:0 in Torch
tresnet(tip);
```

## Making a CuArray
```julia
CuArray{Float32,4}(tip.ptr, size(tip), false)::CuArray
```

## Acknowledgements
Takes a lot of inspiration from existing such projects - ocaml-torch for generating the wrappers.
1 change: 1 addition & 0 deletions src/Torch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export Tensor, tensor, Scalar

using YAML
using Clang
using CUDAdrv
using ZygoteRules
using ZygoteRules: @adjoint
using NNlib
Expand Down
8 changes: 5 additions & 3 deletions src/tensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ async_free!(x) = let x = x, ptr = x.ptr, oid = objectid(x)
end

mutable struct Tensor{T, N} <: AbstractArray{T,N}
ptr::Ptr
ptr::Union{Ptr,CuPtr}
device::Int

function Tensor{T,N}(ptr::Ptr, dev::Int) where {T,N}
obj = new(ptr, dev)
function Tensor{T,N}(ptr::Union{Ptr,CuPtr}, dev::Int) where {T,N}
cuptr = convert(CuPtr{Cvoid}, Base.bitcast(UInt, ptr))
cuptr = convert(CuPtr{T}, cuptr)
obj = new(cuptr, dev)
finalizer(async_free!, obj)
# TURN_ON_LOGGING == true && (logdict[ptr] = (size(obj), stacktrace()))
obj
Expand Down
1,900 changes: 950 additions & 950 deletions src/wrap/libdoeye_caml_generated.jl

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/wrap/libtorch_common.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Automatically generated using Clang.jl


const tensor = Ptr{Cvoid}
const tensor = CuPtr{Cvoid}
const optimizer = Ptr{Cvoid}
const scalar = Ptr{Cvoid}
const module_t = Ptr{Cvoid}
Expand Down