Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hpvm-release
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
llvm
hpvm-release
Commits
97612e60
Commit
97612e60
authored
6 years ago
by
Hashim Sharif
Browse files
Options
Downloads
Patches
Plain Diff
Adding source for high performacne CIFAR10 DNN
parent
2d64ab89
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
llvm/projects/hpvm-tensor-rt/dnn_sources/src/alexnet2_cifar10.cc
+205
-0
205 additions, 0 deletions
...ojects/hpvm-tensor-rt/dnn_sources/src/alexnet2_cifar10.cc
with
205 additions
and
0 deletions
llvm/projects/hpvm-tensor-rt/dnn_sources/src/alexnet2_cifar10.cc
0 → 100644
+
205
−
0
View file @
97612e60
#include
<stdio.h>
#include
<stdlib.h>
#include
<unistd.h>
#include
<fcntl.h>
#include
<sys/types.h>
#include
<sys/stat.h>
#include
<string.h>
#include
"../../tensor_runtime/include/tensor_runtime.h"
#include
"../include/utils.h"
bool
Opentuner_run
=
false
;
/* NOTE: Reference Architecture to use for profiling */
void
testCifarNet
(){
int
total_runs
=
1
;
if
(
Opentuner_run
){
total_runs
=
1000000
;
}
printf
(
"********* CIFAR-10 DNN **********
\n
"
);
// FIXIT: Extend this to batch of images - currently 5 images
int
test_batch_size
=
5000
;
//uint8_t* labels = readLabels("../model_params/cifar_keras/labels.bin", test_batch_size);
uint8_t
*
labels
=
readLabels
(
"../model_params/alexnet2_cifar10/test_labels.bin"
,
test_batch_size
);
void
*
input
=
readTrainedWeights
(
"../model_params/alexnet2_cifar10/norm_cifar_input.bin"
,
float_type
,
test_batch_size
,
3
,
32
,
32
);
void
*
conv1_filter
=
readTrainedWeights
(
"../model_params/alexnet2_cifar10/conv1.bin"
,
float_type
,
32
,
3
,
3
,
3
);
void
*
conv1_bias
=
readTrainedWeights
(
"../model_params/alexnet2_cifar10/conv1_bias.bin"
,
float_type
,
1
,
32
,
1
,
1
);
void
*
conv2_filter
=
readTrainedWeights
(
"../model_params/alexnet2_cifar10/conv2.bin"
,
float_type
,
32
,
32
,
3
,
3
);
void
*
conv2_bias
=
readTrainedWeights
(
"../model_params/alexnet2_cifar10/conv2_bias.bin"
,
float_type
,
1
,
32
,
1
,
1
);
void
*
conv3_filter
=
readTrainedWeights
(
"../model_params/alexnet2_cifar10/conv3.bin"
,
float_type
,
64
,
32
,
3
,
3
);
void
*
conv3_bias
=
readTrainedWeights
(
"../model_params/alexnet2_cifar10/conv3_bias.bin"
,
float_type
,
1
,
64
,
1
,
1
);
void
*
conv4_filter
=
readTrainedWeights
(
"../model_params/alexnet2_cifar10/conv4.bin"
,
float_type
,
64
,
64
,
3
,
3
);
void
*
conv4_bias
=
readTrainedWeights
(
"../model_params/alexnet2_cifar10/conv4_bias.bin"
,
float_type
,
1
,
64
,
1
,
1
);
void
*
conv5_filter
=
readTrainedWeights
(
"../model_params/alexnet2_cifar10/conv5.bin"
,
float_type
,
128
,
64
,
3
,
3
);
void
*
conv5_bias
=
readTrainedWeights
(
"../model_params/alexnet2_cifar10/conv5_bias.bin"
,
float_type
,
1
,
128
,
1
,
1
);
void
*
conv6_filter
=
readTrainedWeights
(
"../model_params/alexnet2_cifar10/conv6.bin"
,
float_type
,
128
,
128
,
3
,
3
);
void
*
conv6_bias
=
readTrainedWeights
(
"../model_params/alexnet2_cifar10/conv6_bias.bin"
,
float_type
,
1
,
128
,
1
,
1
);
void
*
fc1_weights
=
readTrainedWeights
(
"../model_params/alexnet2_cifar10/fc1.bin"
,
float_type
,
1
,
1
,
2048
,
10
);
void
*
fc1_bias
=
readTrainedWeights
(
"../model_params/alexnet2_cifar10/fc1_bias.bin"
,
float_type
,
1
,
10
,
1
,
1
);
clearTensorMap
();
for
(
int
i
=
0
;
i
<
total_runs
;
i
++
){
if
(
Opentuner_run
){
char
*
myfifo
=
"/tmp/myfifo"
;
int
fd
=
open
(
myfifo
,
O_RDONLY
);
int
ret_val
=
fcntl
(
fd
,
F_GETFD
);
if
(
ret_val
==
-
1
){
printf
(
"Invalid descriptor
\n
"
);
abort
();
}
char
str
[
100
];
read
(
fd
,
str
,
80
);
if
(
strcmp
(
str
,
"stop_run"
)
==
0
){
abort
();
}
close
(
fd
);
}
readOpenTunerFlags
(
"opentuner_flags"
);
// Resets the OpenTuner counters
// Start power and performnce profiling
startProfiling
();
int
conv_mode
=
1
;
// NOTE: using CROSS_CORRELATION
int
conv_precision
=
0
;
// NOTE: using Float as compute precision. FIXIT: use enum
// NOTE: 'SAME' convolution
void
*
conv1out
=
tensorConvolution
(
input
,
conv1_filter
,
1
,
1
,
1
,
1
,
conv_mode
,
conv_precision
);
tensorAdd
(
conv1out
,
conv1_bias
);
// NOTE: In place operation
void
*
conv1_tanh
=
tensorTanh
(
conv1out
);
// 2nd Layer
void
*
conv2out
=
tensorConvolution
(
conv1_tanh
,
conv2_filter
,
1
,
1
,
1
,
1
,
conv_mode
,
conv_precision
);
tensorAdd
(
conv2out
,
conv2_bias
);
// NOTE: In place operation
void
*
conv2_tanh
=
tensorTanh
(
conv2out
);
void
*
pool2out
=
tensorPooling
(
conv2_tanh
,
0
,
2
,
2
,
0
,
0
,
2
,
2
);
// 3rd Layer
void
*
conv3out
=
tensorConvolution
(
pool2out
,
conv3_filter
,
1
,
1
,
1
,
1
,
conv_mode
,
conv_precision
);
tensorAdd
(
conv3out
,
conv3_bias
);
// NOTE: In place operation
void
*
conv3_tanh
=
tensorTanh
(
conv3out
);
// 4th Layer
void
*
conv4out
=
tensorConvolution
(
conv3_tanh
,
conv4_filter
,
1
,
1
,
1
,
1
,
conv_mode
,
conv_precision
);
tensorAdd
(
conv4out
,
conv4_bias
);
// NOTE: In place operation
void
*
conv4_tanh
=
tensorTanh
(
conv4out
);
void
*
pool4out
=
tensorPooling
(
conv4_tanh
,
0
,
2
,
2
,
0
,
0
,
2
,
2
);
// 5th Layer
void
*
conv5out
=
tensorConvolution
(
pool4out
,
conv5_filter
,
1
,
1
,
1
,
1
,
conv_mode
,
conv_precision
);
tensorAdd
(
conv5out
,
conv5_bias
);
// NOTE: In place operation
void
*
conv5_tanh
=
tensorTanh
(
conv5out
);
// 6th Layer
void
*
conv6out
=
tensorConvolution
(
conv5_tanh
,
conv6_filter
,
1
,
1
,
1
,
1
,
conv_mode
,
conv_precision
);
tensorAdd
(
conv6out
,
conv6_bias
);
// NOTE: In place operation
void
*
conv6_tanh
=
tensorTanh
(
conv6out
);
void
*
pool6out
=
tensorPooling
(
conv6_tanh
,
0
,
2
,
2
,
0
,
0
,
2
,
2
);
// final FC Layer
void
*
gemm1out
=
tensorGemmGPU
(
pool6out
,
fc1_weights
);
void
*
gemm1biasout
=
tensorAdd
(
gemm1out
,
fc1_bias
);
void
*
result
=
tensorSoftmax
(
gemm1biasout
);
printTensorDims
(
result
);
// End profiling and dump output to profile.txt
stopProfiling
();
computeAccuracy2
(
labels
,
test_batch_size
,
result
);
dumpAccuracyNorms
();
freeOutputTensors
();
if
(
Opentuner_run
){
char
*
myfifo
=
"/tmp/myfifo"
;
int
fd_out
=
open
(
myfifo
,
O_WRONLY
);
int
ret_val
=
fcntl
(
fd_out
,
F_GETFD
);
if
(
ret_val
==
-
1
){
printf
(
"Invalid descriptor
\n
"
);
abort
();
}
const
char
*
str
=
"completed***!
\n\0
"
;
write
(
fd_out
,
str
,
80
);
close
(
fd_out
);
}
}
}
int
main
(
int
argc
,
char
*
argv
[]){
if
(
argc
>
1
)
Opentuner_run
=
true
;
llvm_hpvm_initTensorRt
(
1
);
testCifarNet
();
llvm_hpvm_cleanupTensorRt
();
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment