Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Multicore pusher
# e.g. setgov performance or setgov powersave
function setgov ()
{
for i in {0..7};
do
cpufreq-set -c $i -g $1;
done
}
# setfreq 3.5GHz 3.5GHz
function setfreq()
{
for i in {0..7};
do
cpufreq-set -c $i --min $1 --max $2;
done
}
#!/bin/bash
if [[ -z $(which rdmsr) ]]; then
echo "msr-tools is not installed. Run 'sudo apt-get install msr-tools' to install it." >&2
exit 1
fi
if [[ ! -z $1 && $1 != "enable" && $1 != "disable" ]]; then
echo "Invalid argument: $1" >&2
echo ""
echo "Usage: $(basename $0) [disable|enable]"
exit 1
fi
cores=$(cat /proc/cpuinfo | grep processor | awk '{print $3}')
for core in $cores; do
if [[ $1 == "disable" ]]; then
sudo wrmsr -p${core} 0x1a0 0x4000850089
fi
if [[ $1 == "enable" ]]; then
sudo wrmsr -p${core} 0x1a0 0x850089
fi
state=$(sudo rdmsr -p${core} 0x1a0 -f 38:38)
if [[ $state -eq 1 ]]; then
echo "core ${core}: disabled"
else
echo "core ${core}: enabled"
fi
done
#use cpufreq-set for setting governor and cpu range
#set turbo okff
#use boot param: isolcpus for isolating a cpu from scheduler
EXE=~/work/visualautodiff/autodiffLib/mnist_cnn_adam
export MKL_DYNAMIC=false;
export OMP_NUM_THREADS=4;
export MKL_NUM_THREADS=$OMP_NUM_THREADS;
#cpuMask=`echo "ibase=10; obase=16; 2^(${OMP_NUM_THREADS})-1" | bc`
( kill -SIGSTOP $BASHPID; exec $EXE ) &
X=$!
# putting chrt and taskset before exec does not work
sudo chrt -f -p 99 $X;
#sudo taskset -p $cpuMask $X
sudo taskset -c 0-$[$OMP_NUM_THREADS-1] -p $X
kill -CONT $X
time wait $X
#sudo /usr/share/bcc/tools/cpudist -p $X
# One Liner without stop
EXE=~/work/visualautodiff/autodiffLib/mnist_cnn_adam
export MKL_DYNAMIC=false;
export OMP_NUM_THREADS=4;
export MKL_NUM_THREADS=$OMP_NUM_THREADS;
taskset -c 0-$[$OMP_NUM_THREADS - 1] sudo chrt -f 99 time $cmd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment