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
ec7df083
Commit
ec7df083
authored
3 years ago
by
Hashim Sharif
Browse files
Options
Downloads
Patches
Plain Diff
Fixing tensorUtils definitions to avoid undefs in LLVM IR
parent
b5f03378
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
hpvm/include/nvdla/tensorUtils.h
+92
-17
92 additions, 17 deletions
hpvm/include/nvdla/tensorUtils.h
with
92 additions
and
17 deletions
hpvm/include/nvdla/tensorUtils.h
+
92
−
17
View file @
ec7df083
...
...
@@ -15,41 +15,111 @@ std::string model_params_path = "../../test/dnn_benchmarks/model_params/";
struct
Tensor
*
readTrainedWeights
(
const
char
*
file_name
,
int
data_type
,
long
int
dim1_size
,
long
int
dim2_size
,
long
int
dim3_size
,
long
int
dim4_size
)
{
__attribute__
((
noinline
))
struct
Tensor
*
readTrainedWeights
(
const
char
*
file_name
,
int
data_type
,
long
int
dim1_size
,
long
int
dim2_size
,
long
int
dim3_size
,
long
int
dim4_size
)
{
int
type_size
=
4
;
// NOTE: Assuming floating point tensors
long
int
num_elems
=
dim1_size
*
dim2_size
*
dim3_size
*
dim4_size
;
long
int
size_in_bytes
=
type_size
*
dim1_size
*
dim2_size
*
dim3_size
*
dim4_size
;
float
*
tensor_data
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
num_elems
);
int
file_header_size
=
0
;
FILE
*
file
=
fopen
(
file_name
,
"rb"
);
if
(
file
==
NULL
)
{
printf
(
"Data file %s is not found. Aborting...
\n
"
,
file_name
);
abort
();
}
fseek
(
file
,
file_header_size
,
SEEK_CUR
);
// Skipping the file header
size_t
bytes_read
=
fread
(
tensor_data
,
1
,
size_in_bytes
,
file
);
fclose
(
file
);
// Returning a dummy tensor
struct
Tensor
*
weightsTensor
=
new
struct
Tensor
;
return
weightsTensor
;
}
struct
Tensor
*
readInputBatch
(
const
char
*
file_name
,
long
data_type
,
long
start
,
long
end
,
long
dim2_size
,
long
dim3_size
,
long
dim4_size
)
{
__attribute__
((
noinline
))
struct
Tensor
*
readInputBatch
(
const
char
*
file_name
,
long
data_type
,
long
start
,
long
end
,
long
dim2_size
,
long
dim3_size
,
long
dim4_size
)
{
long
int
dim1_size
=
end
-
start
;
// FIXIT: Don't assume floating point types
long
int
type_size
=
4
;
// NOTE: Assuming floating point tensors
long
int
num_elems
=
dim1_size
*
dim2_size
*
dim3_size
*
dim4_size
;
long
int
size_in_bytes
=
type_size
*
dim1_size
*
dim2_size
*
dim3_size
*
dim4_size
;
float
*
tensor_data
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
num_elems
);
long
int
file_header_size
=
type_size
*
start
*
dim2_size
*
dim3_size
*
dim4_size
;
FILE
*
file
=
fopen
(
file_name
,
"rb"
);
if
(
file
==
NULL
)
{
printf
(
"Data file %s is not found. Aborting...
\n
"
,
file_name
);
abort
();
}
fseek
(
file
,
file_header_size
,
SEEK_SET
);
// Skipping the file header
size_t
bytes_read
=
fread
(
tensor_data
,
1
,
size_in_bytes
,
file
);
fclose
(
file
);
// Creating and returning empty tensor
struct
Tensor
*
inputTensor
=
new
struct
Tensor
;
return
inputTensor
;
}
uint8_t
*
readLabels
(
const
char
*
labels_file
,
int
num_labels
)
{
__attribute__
((
noinline
))
uint8_t
*
readLabels
(
const
char
*
labels_file
,
int
num_labels
)
{
uint8_t
*
dummyLabels
=
(
uint8_t
*
)
malloc
(
sizeof
(
uint8_t
)
*
num_labels
);
return
dummyLabels
;
uint8_t
*
labels
=
(
uint8_t
*
)
malloc
(
sizeof
(
uint8_t
)
*
num_labels
);
FILE
*
file
=
fopen
(
labels_file
,
"rb"
);
if
(
file
==
NULL
)
{
printf
(
"Data file %s is not found. Aborting...
\n
"
,
labels_file
);
abort
();
}
size_t
bytes_read
=
fread
(
labels
,
1
,
sizeof
(
uint8_t
)
*
num_labels
,
file
);
fclose
(
file
);
return
labels
;
}
uint32_t
*
readLabels3
(
const
char
*
labels_file
,
int
num_labels
)
{
__attribute__
((
noinline
))
uint32_t
*
readLabels3
(
const
char
*
labels_file
,
int
num_labels
)
{
uint32_t
*
labels
=
(
uint32_t
*
)
malloc
(
sizeof
(
uint32_t
)
*
num_labels
);
FILE
*
file
=
fopen
(
labels_file
,
"rb"
);
if
(
file
==
NULL
)
{
printf
(
"Data file %s is not found. Aborting...
\n
"
,
labels_file
);
abort
();
}
uint32_t
*
dummyLabels
=
(
uint32_t
*
)
malloc
(
sizeof
(
uint32_t
)
*
num_labels
);
return
dummyLabels
;
size_t
bytes_read
=
fread
(
labels
,
1
,
sizeof
(
uint32_t
)
*
num_labels
,
file
);
fclose
(
file
);
return
labels
;
}
uint32_t
*
readLabelsBatch3
(
const
char
*
labels_file
,
int
start
,
int
end
)
{
__attribute__
((
noinline
))
uint32_t
*
readLabelsBatch3
(
const
char
*
labels_file
,
int
start
,
int
end
)
{
long
int
num_labels
=
end
-
start
;
uint32_t
*
dummyLabels
=
(
uint32_t
*
)
malloc
(
sizeof
(
uint32_t
)
*
num_labels
);
return
dummyLabels
;
uint32_t
*
labels
=
(
uint32_t
*
)
malloc
(
sizeof
(
uint32_t
)
*
num_labels
);
FILE
*
file
=
fopen
(
labels_file
,
"rb"
);
if
(
file
==
NULL
)
{
printf
(
"Data file %s is not found. Aborting...
\n
"
,
labels_file
);
abort
();
}
size_t
bytes_read
=
fread
(
labels
,
1
,
sizeof
(
uint32_t
)
*
num_labels
,
file
);
fclose
(
file
);
return
labels
;
}
...
...
@@ -63,9 +133,14 @@ float computeAccuracy3(uint32_t *labels, void *result_ptr) {
// tensor_runtime.h empty definitions - for NVDLA-based compilation to work (functions not actually used)
void
*
create4DTensor
(
int
data_type
,
int
data_format
,
size_t
dim1_size
,
size_t
dim2_size
,
size_t
dim3_size
,
size_t
dim4_size
){
__attribute__
((
noinline
))
void
*
create4DTensor
(
int
data_type
,
int
data_format
,
size_t
dim1_size
,
size_t
dim2_size
,
size_t
dim3_size
,
size_t
dim4_size
){
long
int
type_size
=
4
;
// NOTE: Assuming floating point tensors
long
int
num_elems
=
dim1_size
*
dim2_size
*
dim3_size
*
dim4_size
;
long
int
size_in_bytes
=
type_size
*
dim1_size
*
dim2_size
*
dim3_size
*
dim4_size
;
struct
Tensor
*
weightsTensor
=
new
struct
Tensor
;
return
weightsTensor
;
}
...
...
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