Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intel Pin tools Scripts for oblivious test #103

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions demo/quantile-mem-trace/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
arr_*.h
test_A
test_B
*.trace
45 changes: 45 additions & 0 deletions demo/quantile-mem-trace/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

## Setup

#### Install Intel Pin
Download the software

wget https://software.intel.com/sites/landingpage/pintool/downloads/pin-3.11-97998-g7ecce2dac-gcc-linux.tar.gz
cp pin-3.11-97998-g7ecce2dac-gcc-linux.tar.gz ~
cd ~
tar -zxvf pin-3.11-97998-g7ecce2dac-gcc-linux.tar.gz
ln -s ~/pin-3.11-97998-g7ecce2dac-gcc-linux ~/pin-dir

Set environment variable

export PIN_ROOT=~/pin-dir

Build Intel Pin

cd $PIN_ROOT/source/tools
make all

#### Disable ASLR

echo 0 | sudo tee /proc/sys/kernel/randomize_va_space

## Run the tests

#### Build the source files
This will auto generate files `arr_A.h` and `arr_B.h` containing random arrays, and then build the programs `test_A.cc` and `test_B.cc`.

**src/common/quantile.h should be replaced by src/common/pin_quantile.h**

**because logging and Macro would effect compile and memtrace.**

./make.sh

#### Execute the tests and capture memory trace
./profile_script.sh

#### Compare memory traces
Compare the memory traces captured during the runs. Trace files `test_A` and `test_B` traces should show no difference between them.

diff test_A.trace test_B.trace

Repeat the steps to run the tests with different random inputs.
10 changes: 10 additions & 0 deletions demo/quantile-mem-trace/gen_arr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

FILE="arr_$1.h"
echo "std::vector<int> V = {" > $FILE

for i in {1..999}
do
echo -n $RANDOM"," >> $FILE
done
echo -n $RANDOM "};" >> $FILE
19 changes: 19 additions & 0 deletions demo/quantile-mem-trace/make.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

set -e

ret=$(cat /proc/sys/kernel/randomize_va_space)
if [ $ret -ne 0 ]; then
echo "ASLR is NOT disabled. Please disable ASLR."
exit 1
fi

#echo "Generating random arrays"
./gen_arr.sh A
./gen_arr.sh B

echo "Building"
g++ -w -O2 -fno-strict-aliasing test_A.cc ../../src/common/quantile.cc ../../src/common/obl_primitives.cc -I../../ -I../../dmlc-core/include -I../../include -o test_A -std=c++11 -mavx2
g++ -w -O2 -fno-strict-aliasing test_B.cc ../../src/common/quantile.cc ../../src/common/obl_primitives.cc -I../../ -I../../dmlc-core/include -I../../include -o test_B -std=c++11 -mavx2

echo "Done"
7 changes: 7 additions & 0 deletions demo/quantile-mem-trace/profile_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
echo "start test"
$PIN_ROOT/pin -t $PIN_ROOT/source/tools/ManualExamples/obj-intel64/pinatrace.so -- ./test_A;
mv pinatrace.out test_A.trace;

$PIN_ROOT/pin -t $PIN_ROOT/source/tools/ManualExamples/obj-intel64/pinatrace.so -- ./test_B;
mv pinatrace.out test_B.trace;
36 changes: 36 additions & 0 deletions demo/quantile-mem-trace/test_A.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <src/common/obl_primitives.h>
#include <src/common/quantile.h>
#include <stdlib.h>

#include <algorithm>
#include <iostream>
#include <vector>

#include "arr_A.h"
using namespace xgboost::common;

int main(int argc, char* argv[]) {
WXQuantileSketch<float, float>::SummaryContainer out;
WXQuantileSketch<float, float> sketchs;
sketchs.Init(64, 1.0);
sketchs.limit_size = 50;
sketchs.nlevel = 3;
sketchs.inqueue.queue.resize(sketchs.limit_size * 2);
for (size_t i = 0; i < 100; i++) {
sketchs.inqueue.Push(V[i], 1);
}

WXQuantileSketch<float, float>::SummaryContainer sa;
WXQuantileSketch<float, float>::SummaryContainer sb;
sa.Reserve(sketchs.inqueue.queue.size());
sb.Reserve(sketchs.inqueue.queue.size());
out.Reserve(sketchs.inqueue.queue.size());
// test for MakeSummaryOblivious
sketchs.inqueue.MakeSummaryOblivious(&out);
sb.CopyFromSize(out, 30);
sa.CopyFromSize(out, 30);
// test fo ObliviousSetPrune
out.ObliviousSetPrune(out,10);
// test for ObliviousSetCombine
out.ObliviousSetCombine(sa,sb);
}
36 changes: 36 additions & 0 deletions demo/quantile-mem-trace/test_B.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <src/common/obl_primitives.h>
#include <src/common/quantile.h>
#include <stdlib.h>

#include <algorithm>
#include <iostream>
#include <vector>

#include "arr_B.h"
using namespace xgboost::common;

int main(int argc, char* argv[]) {
WXQuantileSketch<float, float>::SummaryContainer out;
WXQuantileSketch<float, float> sketchs;
sketchs.Init(64, 1.0);
sketchs.limit_size = 50;
sketchs.nlevel = 3;
sketchs.inqueue.queue.resize(sketchs.limit_size * 2);
for (size_t i = 0; i < 100; i++) {
sketchs.inqueue.Push(V[i], 1);
}

WXQuantileSketch<float, float>::SummaryContainer sa;
WXQuantileSketch<float, float>::SummaryContainer sb;
sa.Reserve(sketchs.inqueue.queue.size());
sb.Reserve(sketchs.inqueue.queue.size());
out.Reserve(sketchs.inqueue.queue.size());
// test for MakeSummaryOblivious
sketchs.inqueue.MakeSummaryOblivious(&out);
sb.CopyFromSize(out, 30);
sa.CopyFromSize(out, 30);
// test fo ObliviousSetPrune
out.ObliviousSetPrune(out,10);
// test for ObliviousSetCombine
out.ObliviousSetCombine(sa,sb);
}
Loading