提交 6e6944cf 编写于 作者: X xiaolil1

Revert "Revert "fix quantize bug and add debug log""

This reverts commit 5f3a2e84.
上级 94e0a673
...@@ -350,10 +350,29 @@ std::cout<<"fuse_relu = "<<fuse_relu<<" fuse_residual_conn = "<<fuse_residual_c ...@@ -350,10 +350,29 @@ std::cout<<"fuse_relu = "<<fuse_relu<<" fuse_residual_conn = "<<fuse_residual_c
std::vector<float> output_shift_scale; std::vector<float> output_shift_scale;
float sum_scale = 1.0f; float sum_scale = 1.0f;
for(int i=0; i<50; i++){
printf("%f ", (float)*(input_data+i));
}
printf("\n");fflush(stdout);
if(is_INT8){ if(is_INT8){
std::cout<<"this is conv int8 op .............."<<std::endl; std::cout<<"this is conv int8 op .............."<<std::endl;
//unsigned char* a = (unsigned char*)(input_data);
//for(int i=0; i<50; i++){
// printf("%d ", *(a+i));
//}
//printf("\n");
int count = is_multi_channel? (g>1? weights_tz[1]*weights_tz[0] : weights_tz[0]) : 1; int count = is_multi_channel? (g>1? weights_tz[1]*weights_tz[0] : weights_tz[0]) : 1;
float scale_in_data = *(scale_in->data<float>()); float scale_in_data = *(scale_in->data<float>());
for(int i=0; i<50; i++){
printf("%f ", *(input_data+i)/scale_in_data);
}
printf("\n");fflush(stdout);
std::vector<float> scale_weights_data(count); std::vector<float> scale_weights_data(count);
for(int i=0; i<count; i++){ for(int i=0; i<count; i++){
scale_weights_data[i] =*(scale_weights->data<float>() + i); scale_weights_data[i] =*(scale_weights->data<float>() + i);
...@@ -480,7 +499,6 @@ std::cout<<key_conv_pd<<std::endl; ...@@ -480,7 +499,6 @@ std::cout<<key_conv_pd<<std::endl;
user_weights_memory_p, pipeline, is_test); user_weights_memory_p, pipeline, is_test);
} }
std::shared_ptr<mkldnn::memory> dst_memory_p; std::shared_ptr<mkldnn::memory> dst_memory_p;
if(is_INT8){ if(is_INT8){
if (fuse_residual_conn) { if (fuse_residual_conn) {
...@@ -510,7 +528,7 @@ std::cout<<key_conv_pd<<std::endl; ...@@ -510,7 +528,7 @@ std::cout<<key_conv_pd<<std::endl;
handler.AcquireDstMemoryFromPrimitive(to_void_cast<int8_t>(output_data)); handler.AcquireDstMemoryFromPrimitive(to_void_cast<int8_t>(output_data));
} }
} }
std::cout<<"input fmt = "<<input->format()<<" output fmt = "<<output->format()<<" dst fmt = "<<dst_memory_p->get_primitive_desc().desc().data.format<<std::endl; std::cout<<"input fmt = "<<input->format()<<" input dt = "<<paddle::framework::ToMKLDNNDataType(input->type())<<" output fmt = "<<output->format()<<" output dt = "<<paddle::framework::ToMKLDNNDataType(output->type())<<" dst fmt = "<<dst_memory_p->get_primitive_desc().desc().data.format<<" dst dt = "<<dst_memory_p->get_primitive_desc().desc().data.data_type<<std::endl;
} else{ } else{
T* output_data = nullptr; T* output_data = nullptr;
if (fuse_residual_conn) { if (fuse_residual_conn) {
......
...@@ -72,7 +72,7 @@ std::cout<<"this is dequant op ***********"<<std::endl; ...@@ -72,7 +72,7 @@ std::cout<<"this is dequant op ***********"<<std::endl;
auto dst_memory = mkldnn::memory(dst_pd, to_void_cast<float>(output_data)); auto dst_memory = mkldnn::memory(dst_pd, to_void_cast<float>(output_data));
auto reorder_pd = std::shared_ptr<reorder::primitive_desc>( auto reorder_pd = std::shared_ptr<reorder::primitive_desc>(
new reorder::primitive_desc(dst_pd, src_pd, attri)); new reorder::primitive_desc(src_pd, dst_pd, attri));
auto reorder_p= std::shared_ptr<reorder>(new reorder(*reorder_pd, *src_memory_p, dst_memory)); auto reorder_p= std::shared_ptr<reorder>(new reorder(*reorder_pd, *src_memory_p, dst_memory));
pipeline.push_back(*reorder_p); pipeline.push_back(*reorder_p);
......
...@@ -47,9 +47,35 @@ std::cout<<"this is quantize op!!!!!!!!!!!!!!"<<std::endl; ...@@ -47,9 +47,35 @@ std::cout<<"this is quantize op!!!!!!!!!!!!!!"<<std::endl;
std::vector<int> dst_tz = paddle::framework::vectorize2int(output->dims()); std::vector<int> dst_tz = paddle::framework::vectorize2int(output->dims());
const T* input_data = input->data<T>(); const T* input_data = input->data<T>();
T* output_data = output->mutable_data<T>(ctx.GetPlace()); uint8_t* output_data = output->mutable_data<uint8_t>(ctx.GetPlace());
std::vector<T> scale_data = {*(scale->data<T>())}; std::vector<T> scale_data = {*(scale->data<T>())};
FILE *fp = fopen("quant_input.txt","w");
printf("quantize check!!!!\n");
std::vector<int> tz = paddle::framework::vectorize2int(input->dims());
int count=1;
for(int i=0; i<tz.size(); i++){
count*=tz[i];
printf("%d ",tz[i]);
}
printf("\n");
int num=0;
for(int i=0; i<count; i++){
if(num==32){ fprintf(fp,"\n"); num=0;}
fprintf(fp,"%f ", *(input_data+i));
num ++;
}
fprintf(fp,"\n");
fclose(fp);
for(int i=0; i<scale_data.size(); i++){
printf("%f", scale_data[i]);
}
printf("\n");
for(int i=0; i<50; i++){
printf("%f ", (*(input_data+i))*scale_data[0]);
}
printf("\n");
fflush(stdout);
mkldnn::primitive_attr attri; mkldnn::primitive_attr attri;
int mask = 0; int mask = 0;
attri.set_output_scales(mask, scale_data); attri.set_output_scales(mask, scale_data);
...@@ -63,10 +89,10 @@ std::cout<<"this is quantize op!!!!!!!!!!!!!!"<<std::endl; ...@@ -63,10 +89,10 @@ std::cout<<"this is quantize op!!!!!!!!!!!!!!"<<std::endl;
auto dst_md = platform::MKLDNNMemDesc( auto dst_md = platform::MKLDNNMemDesc(
{dst_tz}, memory::data_type::u8, memory::format::nhwc); {dst_tz}, memory::data_type::u8, memory::format::nhwc);
auto dst_pd = mkldnn::memory::primitive_desc(dst_md, engine); auto dst_pd = mkldnn::memory::primitive_desc(dst_md, engine);
auto dst_memory = mkldnn::memory(dst_pd, to_void_cast<T>(output_data)); auto dst_memory = mkldnn::memory(dst_pd, to_void_cast<uint8_t>(output_data));
auto reorder_pd = std::shared_ptr<reorder::primitive_desc>( auto reorder_pd = std::shared_ptr<reorder::primitive_desc>(
new reorder::primitive_desc(dst_pd, src_pd, attri)); new reorder::primitive_desc(src_pd, dst_pd, attri));
auto reorder_p= std::shared_ptr<reorder>(new reorder(*reorder_pd, *src_memory_p, dst_memory)); auto reorder_p= std::shared_ptr<reorder>(new reorder(*reorder_pd, *src_memory_p, dst_memory));
pipeline.push_back(*reorder_p); pipeline.push_back(*reorder_p);
......
...@@ -212,16 +212,18 @@ class MKLDNNHandler { ...@@ -212,16 +212,18 @@ class MKLDNNHandler {
std::shared_ptr<mkldnn::primitive> reorder_p; std::shared_ptr<mkldnn::primitive> reorder_p;
if (mpd != user_mpd) { if (mpd != user_mpd) {
target_memory_p = std::make_shared<mkldnn::memory>(mpd); target_memory_p = std::make_shared<mkldnn::memory>(mpd);
auto reorder_p = std::shared_ptr<mkldnn::reorder> reorder_p;// =
std::make_shared<mkldnn::reorder>(*user_memory_p, *target_memory_p); //std::make_shared<mkldnn::reorder>(*user_memory_p, *target_memory_p);
if(is_INT8){ if(is_INT8){
mkldnn::primitive_attr attri; mkldnn::primitive_attr attri;
attri.set_output_scales(mask, scale_data); attri.set_output_scales(mask, scale_data);
auto reorder_pd = std::shared_ptr<mkldnn::reorder::primitive_desc>( auto reorder_pd = std::shared_ptr<mkldnn::reorder::primitive_desc>(
new mkldnn::reorder::primitive_desc(mpd, user_mpd, attri)); new mkldnn::reorder::primitive_desc(user_mpd, mpd, attri));
auto reorder_p = reorder_p =
std::shared_ptr<mkldnn::reorder>(new mkldnn::reorder(*reorder_pd, *user_memory_p, *target_memory_p)); std::shared_ptr<mkldnn::reorder>(new mkldnn::reorder(*reorder_pd, *user_memory_p, *target_memory_p));
} else{
reorder_p = std::make_shared<mkldnn::reorder>(*user_memory_p, *target_memory_p);
} }
dev_ctx_.SetBlob(key_reorder_p, reorder_p); dev_ctx_.SetBlob(key_reorder_p, reorder_p);
pipeline.push_back(*reorder_p); pipeline.push_back(*reorder_p);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册