Skip to content

Instantly share code, notes, and snippets.

View lw's full-sized avatar

Luca Wehrstedt lw

View GitHub Profile
@lw
lw / async.py
Created June 27, 2021 20:16
Asyncio using generators
"""Demo asynchronous server using only generators.
Test with:
$ netcat -N 127.0.0.1 1234
"""
import enum
import select
import socket
#0 0x00007fffe310eb30 in clock_gettime ()
#1 0x00007f610869f936 in __GI___clock_gettime (clock_id=4, tp=0x7fffe30224d0) at ../sysdeps/unix/clock_gettime.c:115
#2 0x00007f609491081e in ?? () from /usr/lib/x86_64-linux-gnu/libcuda.so.1
#3 0x00007f60949f4d14 in ?? () from /usr/lib/x86_64-linux-gnu/libcuda.so.1
#4 0x00007f60948adef9 in ?? () from /usr/lib/x86_64-linux-gnu/libcuda.so.1
#5 0x00007f60948ae0b0 in ?? () from /usr/lib/x86_64-linux-gnu/libcuda.so.1
#6 0x00007f60948dd623 in ?? () from /usr/lib/x86_64-linux-gnu/libcuda.so.1
#7 0x00007f6094a76790 in ?? () from /usr/lib/x86_64-linux-gnu/libcuda.so.1
#8 0x00007f60947e03e7 in ?? () from /usr/lib/x86_64-linux-gnu/libcuda.so.1
#9 0x00007f60947e0850 in ?? () from /usr/lib/x86_64-linux-gnu/libcuda.so.1
@lw
lw / example.cpp
Last active September 22, 2020 20:37
Smart switch over TBuffer w/ C++-14 "auto" lambdas
#include <iostream>
struct CpuBuffer {};
struct CudaBuffer {};
template<typename TBuffer>
int getValue();
int cpuValue = 1;
@lw
lw / example.cpp
Last active September 22, 2020 20:36
Smart switch over TBuffer w/ C++-20 templated lambdas
#include <iostream>
struct CpuBuffer {};
struct CudaBuffer {};
template<typename TBuffer>
int getValue();
int cpuValue = 1;
@lw
lw / gist:233695418823ab5fa8ae768128cabaa3
Last active June 14, 2023 05:04
RAII file descriptor wrapper using unique_ptr
#include <iostream>
#include <array>
#include <memory>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
struct FdHandle {
WARNING: ThreadSanitizer: data race (pid=4955)
Write of size 8 at 0x7b0400001280 by thread T8:
#0 open64 <null> (libtsan.so.0+0x2e2b1)
#1 uv__open_cloexec <null> (tensorpipe_test+0x2b865c)
#2 uv__stream_init <null> (tensorpipe_test+0x2c5ac8)
#3 uv_tcp_init_ex <null> (tensorpipe_test+0x2cb455)
#4 uv_tcp_init <null> (tensorpipe_test+0x2cb540)
#5 tensorpipe::transport::uv::TCPHandle::initFromLoop() <null> (tensorpipe_test+0x2020f8)
#6 tensorpipe::transport::uv::Listener::Impl::initFromLoop() <null> (tensorpipe_test+0x1eafd0)
#7 tensorpipe::transport::uv::Listener::Impl::init()::{lambda()#1}::operator()() const <null> (tensorpipe_test+0x1ed709)
$ nm build/lib/libtorch_global_deps.so
0000000000202028 B __bss_start
0000000000202028 b completed.7697
w __cxa_finalize@@GLIBC_2.2.5
0000000000001220 t deregister_tm_clones
00000000000012b0 t __do_global_dtors_aux
0000000000201c48 t __do_global_dtors_aux_fini_array_entry
0000000000202020 d __dso_handle
0000000000201c50 d _DYNAMIC
0000000000202028 D _edata
$ nm venv/lib/python3.7/site-packages/torch/lib/libtorch_global_deps.so
0000000000201018 B __bss_start
0000000000201018 b completed.6945
w __cxa_finalize@@GLIBC_2.2.5
0000000000000520 t deregister_tm_clones
00000000000005b0 t __do_global_dtors_aux
0000000000200dc0 t __do_global_dtors_aux_fini_array_entry
0000000000200dc8 d __dso_handle
0000000000200dd0 d _DYNAMIC
0000000000201018 D _edata
$ nm build/lib/libtorch_global_deps.so
0000000000201020 B __bss_start
0000000000201020 b completed.7697
w __cxa_finalize@@GLIBC_2.2.5
0000000000000580 t deregister_tm_clones
0000000000000610 t __do_global_dtors_aux
0000000000200d98 t __do_global_dtors_aux_fini_array_entry
0000000000201018 d __dso_handle
0000000000200da0 d _DYNAMIC
0000000000201020 D _edata
Test executor: ['/opt/conda/bin/python']
Running distributed/rpc/tensorpipe/test_dist_autograd_spawn ... [2020-06-17 10:01:31.480372]
Running tests...
----------------------------------------------------------------------
V0617 10:01:33.548001 11988 /var/lib/jenkins/workspace/third_party/tensorpipe/tensorpipe/core/context.cc:118] Context 11988:c0 created
V0617 10:01:33.548062 11988 /var/lib/jenkins/workspace/third_party/tensorpipe/tensorpipe/core/context.cc:120] Context 11988:c0 aliased as worker0
V0617 10:01:33.558348 11990 /var/lib/jenkins/workspace/third_party/tensorpipe/tensorpipe/core/context.cc:118] Context 11990:c0 created
V0617 10:01:33.558446 11991 /var/lib/jenkins/workspace/third_party/tensorpipe/tensorpipe/core/context.cc:118] Context 11991:c0 created
V0617 10:01:33.558470 11991 /var/lib/jenkins/workspace/third_party/tensorpipe/tensorpipe/core/context.cc:120] Context 11991:c0 aliased as worker3