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
c2168c03
Commit
c2168c03
authored
6 years ago
by
Hashim Sharif
Browse files
Options
Downloads
Patches
Plain Diff
Adding utility to compute PSNR
parent
7b661285
No related branches found
No related tags found
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/include/utils.h
+50
-7
50 additions, 7 deletions
llvm/projects/hpvm-tensor-rt/dnn_sources/include/utils.h
with
50 additions
and
7 deletions
llvm/projects/hpvm-tensor-rt/dnn_sources/include/utils.h
+
50
−
7
View file @
c2168c03
...
...
@@ -9,6 +9,7 @@
#include
<bits/stdc++.h>
#include
"../../tensor_runtime/include/tensor.h"
#include
"types.h"
#include
<cmath>
std
::
vector
<
float
>
run_accuracies
;
...
...
@@ -42,9 +43,9 @@ void dumpWeightsToFile(char* file_name, void* weights_ptr){
abort
();
}
printf
(
"size_in_bytes = %lu
\n
"
,
weights
->
size_in_bytes
);
//
printf("size_in_bytes = %lu \n", weights->size_in_bytes);
size_t
bytes_written
=
fwrite
(
weights
->
host_data
,
1
,
weights
->
size_in_bytes
,
fp
);
printf
(
"bytes_written = %lu
\n
"
,
bytes_written
);
//
printf("bytes_written = %lu \n", bytes_written);
fclose
(
fp
);
}
...
...
@@ -209,7 +210,7 @@ void* readInputTensor(const char* file_name, int data_type, int dim1_size, int d
tensor_data
[
i
]
=
(
float
)
file_data
[
i
]
/
255
.
0
f
;
}
printf
(
"tensor_data[%d] = %f
\n
"
,
10
,
tensor_data
[
10
]);
//
printf("tensor_data[%d] = %f \n", 10, tensor_data[10]);
// NOTE: Using NCHW format
struct
Tensor
*
input
=
(
struct
Tensor
*
)
create4DTensor
(
data_type
,
nchw
,
dim1_size
,
dim2_size
,
...
...
@@ -243,7 +244,7 @@ struct Tensor* readTrainedWeights(const char* file_name, int data_type,
fseek
(
file
,
file_header_size
,
SEEK_CUR
);
// Skipping the file header
size_t
bytes_read
=
fread
(
tensor_data
,
1
,
size_in_bytes
,
file
);
printf
(
"size in bytes = %lu, bytes read = %lu
\n
"
,
size_in_bytes
,
bytes_read
);
//
printf("size in bytes = %lu, bytes read = %lu \n", size_in_bytes, bytes_read);
fclose
(
file
);
...
...
@@ -282,7 +283,7 @@ struct Tensor* readInputBatch(const char* file_name, int data_type,
fseek
(
file
,
file_header_size
,
SEEK_SET
);
// Skipping the file header
size_t
bytes_read
=
fread
(
tensor_data
,
1
,
size_in_bytes
,
file
);
printf
(
"size in bytes = %lu, bytes read = %lu
\n
"
,
size_in_bytes
,
bytes_read
);
//
printf("size in bytes = %lu, bytes read = %lu \n", size_in_bytes, bytes_read);
fclose
(
file
);
...
...
@@ -311,7 +312,7 @@ uint8_t* readLabels(const char* labels_file, int num_labels){
fclose
(
file
);
printf
(
"--labels bytes_read = %lu
\n
"
,
bytes_read
);
//
printf("--labels bytes_read = %lu \n", bytes_read);
return
labels
;
}
...
...
@@ -335,7 +336,7 @@ uint8_t* readLabelsBatch(const char* labels_file, int start, int end){
fclose
(
file
);
printf
(
"--labels bytes_read = %lu
\n
"
,
bytes_read
);
//
printf("--labels bytes_read = %lu \n", bytes_read);
return
labels
;
}
...
...
@@ -536,4 +537,46 @@ void dumpExecutionAccuracies(){
float
computePSNRViolation
(
void
*
gold_ptr
,
void
*
approx_ptr
,
float
PSNR_threshold
){
struct
Tensor
*
gold_tensor
=
(
struct
Tensor
*
)
gold_ptr
;
struct
Tensor
*
approx_tensor
=
(
struct
Tensor
*
)
approx_ptr
;
size_t
*
dim_sizes
=
gold_tensor
->
dims
.
dim_sizes
;
size_t
batch_dim
=
dim_sizes
[
0
];
size_t
image_size
=
dim_sizes
[
1
]
*
dim_sizes
[
2
]
*
dim_sizes
[
3
];
printf
(
"batch_dim = %d, image_size = %d
\n
"
,
batch_dim
,
image_size
);
float
*
gold_data
=
(
float
*
)
gold_tensor
->
host_data
;
float
*
approx_data
=
(
float
*
)
approx_tensor
->
host_data
;
int
num_errors
=
0
;
for
(
size_t
i
=
0
;
i
<
batch_dim
;
i
++
){
float
mse_sum
=
0
.
0
;
float
max_val
=
-
999999
;
size_t
offset
=
i
*
image_size
;
for
(
size_t
j
=
0
;
j
<
image_size
;
j
++
){
float
diff
=
gold_data
[
offset
+
j
]
-
approx_data
[
offset
+
j
];
float
diff_square
=
diff
*
diff
;
mse_sum
+=
diff_square
;
if
(
max_val
<
gold_data
[
offset
+
j
]){
max_val
=
gold_data
[
offset
+
j
];
}
}
printf
(
"max_val = %f
\n
"
,
max_val
);
mse_sum
=
mse_sum
/
image_size
;
float
psnr
=
20
*
log10
(
max_val
/
sqrt
(
mse_sum
));
printf
(
"PSNR value = %f
\n
"
,
psnr
);
}
return
0
.
0
;
}
#endif
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