Skip to content

Instantly share code, notes, and snippets.

@juniorprincewang
juniorprincewang / nvidia.sh
Created May 22, 2019 11:53
setup nvidia char device
#!/bin/bash
/sbin/modprobe nvidia
if [ "$?" -eq 0 ]; then
# Count the number of NVIDIA controllers found.
NVDEVS=`lspci | grep -i NVIDIA`
N3D=`echo "$NVDEVS" | grep "3D controller" | wc -l`
NVGA=`echo "$NVDEVS" | grep "VGA compatible controller" | wc -l`
@juniorprincewang
juniorprincewang / demo.tex
Created August 19, 2019 07:09 — forked from Liam0205/demo.tex
demo of moderncv
%!TEX program = xelatex
% Font Size:
% 10pt, 11pt, 12pt
% Paper Size:
% a4paper, letterpaper, a5paper, leagalpaper, executivepaper, landscape
% Font Family:
% roman, sans
\documentclass[12pt, a4paper, roman]{moderncv}
% Style:
@juniorprincewang
juniorprincewang / get.c
Last active March 21, 2022 23:30 — forked from garcia556/get.c
POSIX shared memory IPC example (shm_open, mmap), working on Linux
#include <stdio.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#define STORAGE_ID "/SHM_TEST"
#define STORAGE_SIZE 32
int main(int argc, char *argv[])
@juniorprincewang
juniorprincewang / start_mps_as_root.sh
Last active September 27, 2019 03:10
CUDA MPS start and stop script
#!/bin/bash
# the following must be performed with root privilege
helpFuction()
{
echo ""
echo "Usage: $0 device_id"
echo -e "\t device_id is the id of nvidia device from what nvidia-smi displays"
exit 1
}
@juniorprincewang
juniorprincewang / Makefile
Last active September 2, 2019 09:26
CUDA contexts created by threads are supported by mps. \n first `make threadMigration_kernel64.ptx` then `make`
NVCC=/usr/local/cuda/bin/nvcc
LIBS=-lcuda
INCLUDE=~/NVIDIA_CUDA-9.1_Samples/common/inc
all:main
threadMigration_kernel64.ptx:threadMigration_kernel.cu
$(NVCC) -ptx -o $@ $< $(LIBS) -arch=sm_35
main:threadMigration.cpp
$(NVCC) $(LIBS) -I $(INCLUDE) -o threadMigration threadMigration.cpp
@juniorprincewang
juniorprincewang / mps_run.sh
Created September 2, 2019 09:29
CUDA contexts created by process is supported by MPS
#!/bin/bash
./t1034 &
./t1034
@juniorprincewang
juniorprincewang / avg_time.sh
Created September 2, 2019 09:31
Benchmarking programs in Linux SHELL
#!/bin/bash
avg_time() {
# usage: avg_time n command ...
#
n=$1; shift
(($# > 0)) || return
for((i = 0; i < n; i++)); do
{ time -p "$@" &>/dev/null; } 2>&1
@juniorprincewang
juniorprincewang / mmap_shm.c
Created September 20, 2019 12:21
mmap memory fractions into unified memory address
/*
POSIX:
gcc -std=gnu99 -o mmap_shm mmap_shm.c -lrt
*/
#include <stdio.h>
#include <stdint.h>
#include <assert.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
@juniorprincewang
juniorprincewang / sgx_enable.c
Created September 27, 2019 02:33
enable SGX in Software Controlled BIOS option
/**
After setting BIOS with "software controlled" option, try to enable SGX in software opt-in way.
The source code comes from https://github.com/intel/linux-sgx/issues/238#issuecomment-377324381.
I just compile and execute it.
Note that: replace the path with your own, run it with root permission, then reboot the machine
gcc -o sgx_enable sgx_enable.c -I /home/max/data/gitroom/linux-sgx/common/inc/ -L /home/max/data/gitroom/linux-sgx/build/linux/ -lsgx_capable
sudo ./sgx_enable
sudo reboot
@juniorprincewang
juniorprincewang / benchmark.md
Last active April 30, 2020 02:20
Caffe installation steps in Ubuntu 16.04 or 18.04 with CUDA 9.1 & CUDA 10.0