Skip to content

Commit 306738b

Browse files
committed
decode exit status
1 parent b93f180 commit 306738b

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
0.1.7 decode downloader exit code. iterative merge tensors.
12
0.1.6 algo arg for compression, respect LOAD_UNCOMPRESSED, fix vmsplice
23
0.1.5 pass envvars to downloader + remotefile works with regional cache
34
0.1.4 increase merge_tensors maxsize and make compression block size configurable

remotefile/main.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ func (b *DownloadBuffer) IsDone() bool {
9393
return b.done && len(b.data) == 0
9494
}
9595

96-
func downloadToBuffer(buf *DownloadBuffer) {
96+
func downloadToBuffer(buf *DownloadBuffer) int64 {
9797
startTime := time.Now()
9898
resp, err := client.Get(buf.url)
9999
if err != nil {
100100
fmt.Fprintf(os.Stderr, "Error fetching %s: %v\n", buf.url, err)
101-
return
101+
return 0
102102
}
103103
defer resp.Body.Close()
104104

@@ -118,11 +118,11 @@ func downloadToBuffer(buf *DownloadBuffer) {
118118
throughput := float64(resp.ContentLength) / elapsed.Seconds() / 1024 / 1024
119119
fmt.Fprintf(os.Stderr, "Downloaded %s in %s (%.2f MB/s)\n", resp.Request.URL, elapsed, throughput)
120120
buf.chunkPool.Put(chunk)
121-
return
121+
return resp.ContentLength
122122
}
123123
if err != nil {
124124
fmt.Fprintf(os.Stderr, "Error reading from %s: %v\n", resp.Request.URL, err)
125-
return
125+
return 0
126126
}
127127
}
128128
}
@@ -177,15 +177,20 @@ func main() {
177177
}
178178
bufChan := make(chan *DownloadBuffer)
179179
go func(bufChan chan *DownloadBuffer) {
180+
total_size := int64(0)
181+
start := time.Now()
180182
for _, url := range os.Args[1:] {
181183
// ignore curl args
182184
if url == "-s" || url == "-v" {
183185
continue
184186
}
185187
buf := NewBuffer(url)
186188
bufChan <- buf
187-
downloadToBuffer(buf)
189+
total_size += downloadToBuffer(buf)
188190
}
191+
elapsed := time.Since(start)
192+
throughput := float64(total_size) / elapsed.Seconds() / 1024 / 1024
193+
fmt.Fprintf(os.Stderr, "Overall downloaded %d MB in %s (%.2f MB/s)\n", total_size/1024/1024, elapsed, throughput)
189194
close(bufChan)
190195
}(bufChan)
191196
for buf := range bufChan {

src/main.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,15 @@ class DownloadProc {
242242
throw std::runtime_error("Failed to spawn curl subprocess. Error code: " + std::to_string(retcode));
243243
int status;
244244
waitpid(pid, &status, 0);
245-
throw std::runtime_error("Failed to spawn curl subprocess. Error code: " + std::to_string(retcode) + ", exit code: " + std::to_string(status));
245+
// decode status
246+
if (WIFEXITED(status))
247+
throw std::runtime_error("Failed to spawn curl subprocess. Error code: " + std::to_string(retcode) + ", exit code: " + std::to_string(WEXITSTATUS(status)));
248+
else if (WIFSIGNALED(status))
249+
throw std::runtime_error("Failed to spawn curl subprocess. Error code: " + std::to_string(retcode) + ", exit signal: " + std::to_string(WTERMSIG(status)));
250+
else if (WIFSTOPPED(status))
251+
throw std::runtime_error("Failed to spawn curl subprocess. Error code: " + std::to_string(retcode) + ", stop signal: " + std::to_string(WSTOPSIG(status)));
252+
else
253+
throw std::runtime_error("Failed to spawn curl subprocess. Error code: " + std::to_string(retcode) + ", unknown status: " + std::to_string(status));
246254
}
247255
// close write end of the pipe
248256
close(pipefd[1]);
@@ -256,7 +264,7 @@ class DownloadProc {
256264
kill(pid, SIGTERM);
257265
int status;
258266
waitpid(pid, &status, 0);
259-
int code = ((WIFEXITED(status) ? WEXITSTATUS(status) : (WIFSIGNALED(status) ? -WTERMSIG(status) : 0)))
267+
int code = ((WIFEXITED(status) ? WEXITSTATUS(status) : (WIFSIGNALED(status) ? -WTERMSIG(status) : 0)));
260268
log("killed downloader process. exit code: " + std::to_string(code));
261269
}
262270

tools/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
set -o xtrace
22
set -o pipefail
33
set -o errexit
4-
export VERSION="0.1.6"
4+
export VERSION="0.1.7"
55
# worked with auditwheel for manywheel torch, but not freshly compiled recent-glibc torch
66
# nyacomp-$VERSION-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
77
WHEEL="nyacomp-$VERSION-cp311-cp311-linux_x86_64.whl"

0 commit comments

Comments
 (0)