-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,11 @@ | |
import | ||
std/[asyncdispatch, httpclient, | ||
strformat, strutils, os], | ||
#zippy/ziparchives, | ||
zip/zipfiles | ||
|
||
{.passl: "-lz".} | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
HugoGranstrom
Author
Member
|
||
|
||
type | ||
Acceleration* = enum | ||
Cpu = "cpu" | ||
|
@@ -26,17 +29,17 @@ type | |
proc getProjectDir(): string {.compileTime.} = | ||
currentSourcePath.rsplit(DirSep, 1)[0] | ||
|
||
proc onProgressChanged(total, progress, speed: BiggestInt) {.async.} = | ||
proc onProgressChanged(total, progress, speed: BiggestInt) = | ||
echo &"Downloaded {progress} of {total}" | ||
echo &"Current rate: {speed.float64 / (1000*1000):4.3f} MiBi/s" # TODO the unit is neither MB or Mb or MiBi ??? | ||
|
||
proc downloadTo(url, targetDir, filename: string) {.async.} = | ||
var client = newAsyncHttpClient() | ||
proc downloadTo(url, targetDir, filename: string) = | ||
var client = newHttpClient() | ||
defer: client.close() | ||
client.onProgressChanged = onProgressChanged | ||
echo "Starting download of \"", url, '\"' | ||
echo "Storing temporary into: \"", targetDir, '\"' | ||
await client.downloadFile(url, targetDir / filename) | ||
client.downloadFile(url, targetDir / filename) | ||
|
||
proc getUrlAndFilename(version = "1.8.1", accel = Cuda111, abi = Cpp11): tuple[url, filename: string] = | ||
result.filename = "libtorch-" | ||
|
@@ -47,16 +50,50 @@ proc getUrlAndFilename(version = "1.8.1", accel = Cuda111, abi = Cpp11): tuple[u | |
result.filename &= &"%2B{accel}" | ||
result.filename &= ".zip" | ||
elif defined(windows): | ||
let abi = Cpp | ||
doAssert abi == Cpp, "LibTorch for Windows does not support the C++11 ABI" | ||
result.filename &= &"-win-{abi}-{version}.zip" | ||
result.filename &= &"win-{abi}-{version}" | ||
result.filename &= &"%2B{accel}" | ||
result.filename &= ".zip" | ||
elif defined(osx): | ||
doAssert accel == Cpu, "LibTorch for MacOS does not support GPU acceleration" | ||
result.filename &= &"macos-{version}.zip" | ||
|
||
result.url = &"https://download.pytorch.org/libtorch/{accel}/{result.filename}" | ||
|
||
proc downloadLibTorch(url, targetDir, filename: string) = | ||
waitFor url.downloadTo(targetDir, filename) | ||
if not fileExists(targetDir / "libtorch.zip"): | ||
This comment has been minimized.
Sorry, something went wrong.
Clonkk
Member
|
||
url.downloadTo(targetDir, "libtorch.zip") | ||
else: | ||
echo "File is already downloaded" | ||
|
||
#[ proc uncompress(targetDir, filename: string, delete = false) = | ||
let tmpZip = targetDir / filename | ||
var tmpDir = getTempDir() / "libtorch_temp_download" | ||
var i = 0 | ||
while dirExists(tmpDir & $i): | ||
inc(i) | ||
tmpDir = tmpDir & $i | ||
echo "Tempdir: ", tmpDir | ||
let folderName = filename[0 ..< ^4] # remove .zip | ||
let targetDir = targetDir# / "test" | ||
#removeDir(tmpDir) | ||
#createDir(tmpDir) | ||
echo "Decompressing \"", tmpZip, "\" and storing into \"", targetDir, "\"" | ||
extractAll(tmpZip, tmpDir) | ||
echo "Extraction done! Now copying from temp" | ||
removeDir(targetDir / "libtorch") # remove old install | ||
echo "Removed old folder" | ||
copyDir(tmpDir, targetDir) | ||
echo "Copy done!" | ||
removeDir(tmpDir) | ||
echo "Done." | ||
if delete: | ||
echo "Deleting \"", tmpZip, "\"" | ||
removeFile(tmpZip) | ||
else: | ||
echo "Not deleting \"", tmpZip, "\"" ]# | ||
|
||
proc uncompress(targetDir, filename: string, delete = false) = | ||
var z: ZipArchive | ||
|
Why not use Zippy ?
Unzip to a
tmp
folder andmoveDir
the un-zipped content back tovendor
as a workaround of guzba/zippy#8It should work on Windows.