This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Some { | |
template <typename T> struct type { | |
static void id() {} | |
}; | |
template <typename T> static size_t type_id() { | |
return reinterpret_cast<size_t>(&type<T>::id); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import matplotlib as mpl | |
mpl.rcParams['figure.dpi'] = 300 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import tensorflow as tf | |
from tensorflow.contrib.tensorboard.plugins import projector | |
import numpy as np | |
import time | |
try: | |
import scipy.misc | |
except ImportError: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# mainly from: | |
# 1. https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#env-vars | |
# 2. https://github.com/NVIDIA/DeepLearningExamples/issues/57 | |
# 3. https://docs.nvidia.com/deeplearning/frameworks/tensorflow-user-guide/index.html#variablesaddtf | |
def is_using_hvd(): | |
env_vars = ["OMPI_COMM_WORLD_RANK", "OMPI_COMM_WORLD_SIZE"] | |
if all([var in os.environ for var in env_vars]): | |
return True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# Created by ay27 at 2018/4/8 | |
import os | |
def set_best_gpu(top_k=1): | |
best_gpu = _scan(top_k) | |
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" | |
os.environ["CUDA_VISIBLE_DEVICES"] = ','.join(map(str, best_gpu)) |