Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
N
ngraph
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ngraph
Commits
c75f7db3
Commit
c75f7db3
authored
Jun 12, 2019
by
nishant.b.patel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move quantized conv tests from test/builder to test/backend
parent
baf1cb00
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
103 deletions
+65
-103
int_executable.hpp
src/ngraph/runtime/interpreter/int_executable.hpp
+65
-1
backend_test.in.cpp
test/backend_test.in.cpp
+0
-0
builder_quantization.cpp
test/builder_quantization.cpp
+0
-102
No files found.
src/ngraph/runtime/interpreter/int_executable.hpp
View file @
c75f7db3
...
...
@@ -51,6 +51,7 @@
#include "ngraph/op/passthrough.hpp"
#include "ngraph/op/product.hpp"
#include "ngraph/op/quantize.hpp"
#include "ngraph/op/quantized_convolution.hpp"
#include "ngraph/op/replace_slice.hpp"
#include "ngraph/op/reshape.hpp"
#include "ngraph/op/result.hpp"
...
...
@@ -1134,12 +1135,75 @@ private:
break
;
}
case
OP_TYPEID
:
:
QuantizedConvolution
:
{
const
op
::
QuantizedConvolution
*
qc
=
static_cast
<
const
op
::
QuantizedConvolution
*>
(
&
node
);
auto
input_element_type
=
qc
->
get_input_element_type
(
0
);
auto
filter_element_type
=
qc
->
get_input_element_type
(
1
);
auto
output_element_type
=
qc
->
get_output_element_type
(
0
);
if
(
input_element_type
==
element
::
u8
&&
filter_element_type
==
element
::
i8
&&
output_element_type
==
element
::
i8
)
{
reference
::
convolution
<
uint8_t
,
int8_t
,
int8_t
,
int32_t
>
(
args
[
0
]
->
get_data_ptr
<
const
uint8_t
>
(),
args
[
1
]
->
get_data_ptr
<
const
int8_t
>
(),
out
[
0
]
->
get_data_ptr
<
int8_t
>
(),
node
.
get_input_shape
(
0
),
node
.
get_input_shape
(
1
),
node
.
get_output_shape
(
0
),
qc
->
get_window_movement_strides
(),
qc
->
get_window_dilation_strides
(),
qc
->
get_padding_below
(),
qc
->
get_padding_above
(),
qc
->
get_data_dilation_strides
(),
args
[
2
]
->
get_data_ptr
<
const
float
>
(),
args
[
3
]
->
get_data_ptr
<
const
uint8_t
>
(),
args
[
4
]
->
get_data_ptr
<
const
float
>
(),
args
[
5
]
->
get_data_ptr
<
const
int8_t
>
(),
args
[
6
]
->
get_data_ptr
<
const
float
>
(),
args
[
7
]
->
get_data_ptr
<
const
int8_t
>
());
}
else
if
(
input_element_type
==
element
::
u8
&&
filter_element_type
==
element
::
u8
&&
output_element_type
==
element
::
u8
)
{
reference
::
convolution
<
uint8_t
,
uint8_t
,
uint8_t
,
int32_t
>
(
args
[
0
]
->
get_data_ptr
<
const
uint8_t
>
(),
args
[
1
]
->
get_data_ptr
<
const
uint8_t
>
(),
out
[
0
]
->
get_data_ptr
<
uint8_t
>
(),
node
.
get_input_shape
(
0
),
node
.
get_input_shape
(
1
),
node
.
get_output_shape
(
0
),
qc
->
get_window_movement_strides
(),
qc
->
get_window_dilation_strides
(),
qc
->
get_padding_below
(),
qc
->
get_padding_above
(),
qc
->
get_data_dilation_strides
(),
args
[
2
]
->
get_data_ptr
<
const
float
>
(),
args
[
3
]
->
get_data_ptr
<
const
uint8_t
>
(),
args
[
4
]
->
get_data_ptr
<
const
float
>
(),
args
[
5
]
->
get_data_ptr
<
const
uint8_t
>
(),
args
[
6
]
->
get_data_ptr
<
const
float
>
(),
args
[
7
]
->
get_data_ptr
<
const
uint8_t
>
());
}
else
{
std
::
stringstream
ss
;
ss
<<
"unsupported element type"
;
throw
std
::
runtime_error
(
ss
.
str
());
}
break
;
}
case
OP_TYPEID
:
:
QuantizedAvgPool
:
case
OP_TYPEID
:
:
QuantizedConvolutionBias
:
case
OP_TYPEID
:
:
QuantizedConvolutionBiasAdd
:
case
OP_TYPEID
:
:
QuantizedConvolutionBiasSignedAdd
:
case
OP_TYPEID
:
:
QuantizedConvolutionRelu
:
case
OP_TYPEID
:
:
QuantizedConvolution
:
case
OP_TYPEID
:
:
QuantizedMaxPool
:
case
OP_TYPEID
:
:
QuantizedDotBias
:
case
OP_TYPEID
:
:
QuantizedDot
:
...
...
test/backend_test.in.cpp
View file @
c75f7db3
This diff is collapsed.
Click to expand it.
test/builder_quantization.cpp
View file @
c75f7db3
...
...
@@ -146,108 +146,6 @@ static void constant_fold(std::shared_ptr<Function> f)
pass_manager
.
run_passes
(
f
);
}
TEST
(
builder
,
scaled_QC
)
{
Shape
shape_a
{
1
,
1
,
3
,
4
};
// input shape
Shape
shape_b
{
1
,
1
,
3
,
3
};
// filter shape
Shape
shape_r
{
1
,
1
,
3
,
4
};
// output shape
vector
<
uint8_t
>
a_data
=
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
0
,
1
,
2
,
3
,
4
};
vector
<
int8_t
>
b_data
=
{
1
,
2
,
3
,
4
,
5
,
0
,
0
,
1
,
2
};
auto
A
=
make_shared
<
op
::
Parameter
>
(
element
::
u8
,
shape_a
);
auto
B
=
make_shared
<
op
::
Parameter
>
(
element
::
i8
,
shape_b
);
auto
C
=
op
::
Constant
::
create
(
element
::
f32
,
Shape
{
1
},
{
0.0
f
});
auto
D
=
op
::
Constant
::
create
(
element
::
f32
,
Shape
{
1
},
{
255.0
f
});
auto
E
=
op
::
Constant
::
create
(
element
::
f32
,
Shape
{
1
},
{
-
127.0
f
});
auto
F
=
op
::
Constant
::
create
(
element
::
f32
,
Shape
{
1
},
{
127.0
f
});
auto
G
=
op
::
Constant
::
create
(
element
::
f32
,
Shape
{
1
},
{
22.0
f
});
auto
H
=
op
::
Constant
::
create
(
element
::
f32
,
Shape
{
1
},
{
90.0
f
});
auto
CV
=
ngraph
::
builder
::
QuantizedConvolutionBuilder
(
A
,
B
,
Strides
{
1
,
1
},
// move_strides
Strides
{
1
,
1
},
// filter_dilation
CoordinateDiff
{
1
,
1
},
// below_pads
CoordinateDiff
{
1
,
1
},
// above_pads
Strides
{
1
,
1
},
// data_dilation
C
,
D
,
E
,
F
,
G
,
H
,
element
::
i8
,
AxisSet
{});
auto
f
=
make_shared
<
Function
>
(
NodeVector
{
CV
},
ParameterVector
{
A
,
B
});
constant_fold
(
f
);
auto
backend
=
runtime
::
Backend
::
create
(
"CPU"
);
// Create some tensors for input/output
auto
a
=
backend
->
create_tensor
(
element
::
u8
,
shape_a
);
copy_data
(
a
,
a_data
);
auto
b
=
backend
->
create_tensor
(
element
::
i8
,
shape_b
);
copy_data
(
b
,
b_data
);
auto
result
=
backend
->
create_tensor
(
element
::
i8
,
shape_r
);
auto
handle
=
backend
->
compile
(
f
);
handle
->
call_with_validate
({
result
},
{
a
,
b
});
EXPECT_EQ
((
vector
<
int8_t
>
{
31
,
48
,
42
,
45
,
54
,
102
,
127
,
61
,
47
,
74
,
61
,
55
}),
read_vector
<
int8_t
>
(
result
));
}
TEST
(
builder
,
dynamic_scaled_QC
)
{
Shape
shape_a
{
1
,
1
,
3
,
4
};
// input shape
Shape
shape_b
{
1
,
1
,
3
,
3
};
// filter shape
Shape
shape_r
{
1
,
1
,
3
,
4
};
// output shape
vector
<
uint8_t
>
a_data
=
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
0
,
1
,
2
,
3
,
4
};
vector
<
int8_t
>
b_data
=
{
1
,
2
,
3
,
4
,
5
,
0
,
0
,
1
,
2
};
auto
A
=
make_shared
<
op
::
Parameter
>
(
element
::
u8
,
shape_a
);
auto
B
=
make_shared
<
op
::
Parameter
>
(
element
::
i8
,
shape_b
);
auto
C
=
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
Shape
{
1
});
auto
D
=
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
Shape
{
1
});
auto
E
=
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
Shape
{
1
});
auto
F
=
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
Shape
{
1
});
auto
G
=
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
Shape
{
1
});
auto
H
=
make_shared
<
op
::
Parameter
>
(
element
::
f32
,
Shape
{
1
});
auto
CV
=
ngraph
::
builder
::
QuantizedConvolutionBuilder
(
A
,
B
,
Strides
{
1
,
1
},
// move_strides
Strides
{
1
,
1
},
// filter_dilation
CoordinateDiff
{
1
,
1
},
// below_pads
CoordinateDiff
{
1
,
1
},
// above_pads
Strides
{
1
,
1
},
// data_dilation
C
,
D
,
E
,
F
,
G
,
H
,
element
::
i8
,
AxisSet
{});
auto
f
=
make_shared
<
Function
>
(
NodeVector
{
CV
},
ParameterVector
{
A
,
B
,
C
,
D
,
E
,
F
,
G
,
H
});
auto
backend
=
runtime
::
Backend
::
create
(
"CPU"
);
// Create some tensors for input/output
auto
a
=
backend
->
create_tensor
(
element
::
u8
,
shape_a
);
copy_data
(
a
,
a_data
);
auto
b
=
backend
->
create_tensor
(
element
::
i8
,
shape_b
);
copy_data
(
b
,
b_data
);
auto
d
=
backend
->
create_tensor
(
element
::
f32
,
Shape
{
1
});
copy_data
(
d
,
vector
<
float
>
{
0.0
f
});
auto
e
=
backend
->
create_tensor
(
element
::
f32
,
Shape
{
1
});
copy_data
(
e
,
vector
<
float
>
{
255.0
f
});
auto
e_a
=
backend
->
create_tensor
(
element
::
f32
,
Shape
{
1
});
copy_data
(
e_a
,
vector
<
float
>
{
-
127.0
f
});
auto
g
=
backend
->
create_tensor
(
element
::
f32
,
Shape
{
1
});
copy_data
(
g
,
vector
<
float
>
{
127.0
f
});
auto
h
=
backend
->
create_tensor
(
element
::
f32
,
Shape
{
1
});
copy_data
(
h
,
vector
<
float
>
{
22.0
f
});
auto
i
=
backend
->
create_tensor
(
element
::
f32
,
Shape
{
1
});
copy_data
(
i
,
vector
<
float
>
{
90.0
f
});
auto
result
=
backend
->
create_tensor
(
element
::
i8
,
shape_r
);
auto
handle
=
backend
->
compile
(
f
);
handle
->
call_with_validate
({
result
},
{
a
,
b
,
d
,
e
,
e_a
,
g
,
h
,
i
});
EXPECT_EQ
((
vector
<
int8_t
>
{
31
,
48
,
42
,
45
,
54
,
102
,
127
,
61
,
47
,
74
,
61
,
55
}),
read_vector
<
int8_t
>
(
result
));
}
TEST
(
builder
,
scaled_QC_with_relu
)
{
Shape
shape_a
{
1
,
1
,
3
,
3
};
// input shape
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment