@@ -125,14 +125,16 @@ class FCMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
125
125
126
126
auto input = ctx.Input <Tensor>(" Input" );
127
127
auto w = ctx.Input <Tensor>(" W" );
128
+ auto bias = ctx.Input <Tensor>(" Bias" );
128
129
129
130
PADDLE_ENFORCE (input->dims ().size () == 2 || input->dims ().size () == 4 ,
130
131
" Input must be with 2 or 4 dimensions, i.e. NCHW" );
131
- // TODO(intel): the src weight is io and mkldnn weight need be transposed !
132
+ // TODO(intel friends): the native weight format is io,
133
+ // but the mkldnn weight format is oihw, which may need be transposed.
132
134
PADDLE_ENFORCE (w->dims ().size () == 2 || w->dims ().size () == 4 ,
133
135
" Weights must be with 2 or 4 dimensions, i.e. OI or OIHW" );
134
136
135
- bool with_bias = ctx. Attr < bool >( " bias_attr " ) ;
137
+ bool with_bias = bias != nullptr ;
136
138
MKLDNNMD<Tensor> md (input, w, with_bias);
137
139
138
140
std::shared_ptr<mkldnn::inner_product_forward::primitive_desc> pd =
@@ -155,6 +157,7 @@ class FCMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
155
157
auto dst_memory = mem.dst (output_data);
156
158
auto src_memory = mem.src (input_data);
157
159
auto weights_memory = mem.weights (w_data);
160
+ // TODO(intel friends): bias memory should also be obtain from bias->data()
158
161
auto bias_memory = mem.bias ();
159
162
160
163
auto forward = with_bias ? mkldnn::inner_product_forward (
@@ -217,7 +220,8 @@ class FCMKLDNNGradOpKernel : public paddle::framework::OpKernel<T> {
217
220
const Tensor* out_grad = ctx.Input <Tensor>(framework::GradVarName (" Out" ));
218
221
const T* out_grad_data = out_grad->data <T>();
219
222
220
- bool with_bias = ctx.Attr <bool >(" bias_attr" );
223
+ auto bias = ctx.Input <Tensor>(" Bias" );
224
+ bool with_bias = bias != nullptr ;
221
225
222
226
MKLDNNMD<Tensor> md (input, w, with_bias);
223
227
MKLDNNMemory mem (&md, mkldnn_engine);
0 commit comments