Skip to content

Instantly share code, notes, and snippets.

View podgorskiy's full-sized avatar
🏠
Working from home

Stanislav Pidhorskyi podgorskiy

🏠
Working from home
View GitHub Profile
@JSandusky
JSandusky / imgui_bitfield.cpp
Created March 26, 2018 05:56
ImGui Bitfield Checkbox Matrix
bool BitField(const char* label, unsigned* bits, unsigned* hoverIndex)
{
unsigned val = *bits;
ImGuiWindow* window = GetCurrentWindow();
if (window->SkipItems)
return false;
unsigned oldFlags = window->Flags;
ImGuiContext* g = ImGui::GetCurrentContext();

Cuda and current compilers

NVidia is archaic as f..., so they don't officially support any current compiler.

but I found a bunch of ugly hacks to make it work with:

  • gcc 7.3.0
  • cuda 9.1.85_387.26
    • install from the .run file with argument --override so it asks you if you're ok with having an unsupported system instead of failing because you're not using ages old ubuntu :P
    • install the CUDA toolkit, but not the (often older than OS provided) GPU driver and not the examples.
    • also install to /opt/cuda-9.1 because your're not your package manager and it doesn't belong into /usr/!
  • then comment out line 121 of /opt/cuda-9.1/include/crt/host_config.h (the one #erroring about unsupported gcc version)
@hyqneuron
hyqneuron / pytorch_visualize.py
Created June 7, 2017 07:06
PyTorch graph visualization
import torch
import torch.nn as nn
from torch.nn import Parameter
from torch.autograd import Variable, Function
from collections import defaultdict
import graphviz
"""
This is a rather distorted implementation of graph visualization in PyTorch.
@victor-shepardson
victor-shepardson / pytorch-glumpy.py
Last active March 25, 2024 19:47
using pycuda and glumpy to draw pytorch GPU tensors to the screen without copying to host memory
from contextlib import contextmanager
import numpy as np
import torch
from torch import Tensor, ByteTensor
import torch.nn.functional as F
from torch.autograd import Variable
import pycuda.driver
from pycuda.gl import graphics_map_flags
from glumpy import app, gloo, gl
@guschmue
guschmue / tf_user_ops.cmake
Last active September 13, 2019 16:11
example how to build a user_op for windows
# example how to build a user_op for windows
#
# 1. save this file as tensorflow/contrib/cmake/tf_user_ops.cmake
# 2. append "include(tf_user_ops.cmake)" to CMakeLists.txt
# 3. call cmake (see tensorflow/contrib/cmake/README.md), ie:
# cmake %cmake_dir% -A x64 -DCMAKE_BUILD_TYPE=RelWithDebInfo -DPYTHON_EXECUTABLE=%PY%\python.exe
# -DPYTHON_LIBRARIES=%PY%\libs\python35.lib -DSWIG_EXECUTABLE=c:\local\swigwin-3.0.10\swig.exe
# -Dtensorflow_BUILD_PYTHON_TESTS=ON
# 4. you need to build the source tree once to generate all header files needed, ie:
# MSBuild /p:Configuration=RelWithDebInfo tf_python_build_pip_package.vcxproj
@simonw
simonw / recover_source_code.md
Last active June 21, 2024 00:11
How to recover lost Python source code if it's still resident in-memory

How to recover lost Python source code if it's still resident in-memory

I screwed up using git ("git checkout --" on the wrong file) and managed to delete the code I had just written... but it was still running in a process in a docker container. Here's how I got it back, using https://pypi.python.org/pypi/pyrasite/ and https://pypi.python.org/pypi/uncompyle6

Attach a shell to the docker container

Install GDB (needed by pyrasite)

apt-get update && apt-get install gdb
cmake_minimum_required(VERSION 3.5)
project(user_ops C CXX)
set(CMAKE_CXX_STANDARD 14)
set (tensorflow_SOURCE_DIR "c:/src/tensorflow.guschmue")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_definitions(/I${tensorflow_SOURCE_DIR} /I${tensorflow_SOURCE_DIR}/cmake_build)
add_definitions(-DEIGEN_AVOID_STL_ARRAY)
@javidcf
javidcf / pseudoinverse.cpp
Last active July 27, 2022 21:21
Compute the pseudoinverse of a dense matrix with Eigen (C++11)
#include <Eigen/Dense>
template <class MatT>
Eigen::Matrix<typename MatT::Scalar, MatT::ColsAtCompileTime, MatT::RowsAtCompileTime>
pseudoinverse(const MatT &mat, typename MatT::Scalar tolerance = typename MatT::Scalar{1e-4}) // choose appropriately
{
typedef typename MatT::Scalar Scalar;
auto svd = mat.jacobiSvd(Eigen::ComputeFullU | Eigen::ComputeFullV);
const auto &singularValues = svd.singularValues();
Eigen::Matrix<Scalar, MatT::ColsAtCompileTime, MatT::RowsAtCompileTime> singularValuesInv(mat.cols(), mat.rows());
@domnikl
domnikl / LICENSE
Last active July 11, 2024 08:28
C function to dump memory
Copyright 2018 Dominik Liebler
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR O
@galek
galek / pbr.glsl
Created November 4, 2015 11:10
PBR GLSL SHADER
in vec2 v_texcoord; // texture coords
in vec3 v_normal; // normal
in vec3 v_binormal; // binormal (for TBN basis calc)
in vec3 v_pos; // pixel view space position
out vec4 color;
layout(std140) uniform Transforms
{
mat4x4 world_matrix; // object's world position