Skip to content

Instantly share code, notes, and snippets.

@juniorprincewang
juniorprincewang / setting.sh
Created April 1, 2020 12:52
CUDA PATH and LD_LIBRARY_PATH setting
echo 'export PATH=$PATH:/usr/local/cuda/bin' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib:/usr/local/cuda/lib64' >> ~/.bashrc
source ~/.bashrc
sudo bash -c "echo /usr/local/cuda/lib64/ > /etc/ld.so.conf.d/cuda.conf"
sudo ldconfig
@juniorprincewang
juniorprincewang / Makefile
Last active March 28, 2020 07:31
Glib Hash Table
all:
gcc -I/usr/include/glib-2.0/ ghashtable.c -o main -lglib-2.0
clean:
rm -rf main
@juniorprincewang
juniorprincewang / Makefile
Created March 19, 2020 06:36
kernel module for `get_user_pages_remote()`
obj-m += sample.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
all:
$(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
$(MAKE) -C $(KDIR) M=$(PWD) clean
@juniorprincewang
juniorprincewang / pci-driver.c
Created March 10, 2020 08:41
an example of a simple pci driver for a VIRTUAL card
// http://www.zarb.org/~trem/kernel/pci/pci-driver.c
/***************************************************************************
* Copyright (C) 2005 by trem *
* [email protected] *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
@juniorprincewang
juniorprincewang / 90c0.c
Created February 21, 2020 14:22
NVIDIA NVC0 compute process using MMIO
// https://people.freedesktop.org/~chrisbmr/90c0.c
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <float.h>
#include <libdrm/nouveau.h>
@juniorprincewang
juniorprincewang / a0c0-counter.c
Created February 21, 2020 14:16
NVIDIA NVE4 compute process using MMIO
//from https://people.freedesktop.org/~chrisbmr/a0c0-counter.c
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <float.h>
#include <unistd.h>
#include <assert.h>
@juniorprincewang
juniorprincewang / no-madvise.c
Created December 26, 2019 06:24 — forked from niedbalski/no-madvise.c
madvise tests
niedbalski@theos-mobile:~$ cat test-madvise.c
#include <sys/mman.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
int main(void) {
size_t size = sysconf(_SC_PAGE_SIZE) * 6; //24K
@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
@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 / 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>