Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Ignore operation req type for to tensor
Browse files Browse the repository at this point in the history
  • Loading branch information
sandeep-krishnamurthy committed Feb 7, 2019
1 parent 3b6e265 commit 14bedee
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/operator/image/image_random-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,15 @@ inline bool ToTensorType(const nnvm::NodeAttrs& attrs,

// Operator Implementation

template<int req>
struct totensor_forward {
template<typename DType>
MSHADOW_XINLINE static void Map(uint32_t c, float* out_data, const DType* in_data,
const int length, const int channel, const int step,
const float normalize_factor = 255.0f) {
#pragma omp parallel for
for (int i = 0; i < length; ++i) {
KERNEL_ASSIGN(out_data[step + c*length + i], req,
(in_data[step + i*channel + c]) / normalize_factor);
out_data[step + c*length + i] =
(in_data[step + i*channel + c]) / normalize_factor;
}
}
};
Expand All @@ -97,19 +96,16 @@ template<typename xpu>
void ToTensorImpl(const OpContext &ctx,
const std::vector<TBlob> &inputs,
const std::vector<TBlob> &outputs,
const std::vector<OpReqType> &req,
const int length,
const uint32_t channel,
const int step = 0) {
mshadow::Stream<xpu> *s = ctx.get_stream<xpu>();

MSHADOW_TYPE_SWITCH(inputs[0].type_flag_, DType, {
MXNET_ASSIGN_REQ_SWITCH(req[0], req_type, {
float* output = outputs[0].dptr<float>();
DType* input = inputs[0].dptr<DType>();
mxnet_op::Kernel<totensor_forward<req_type>, xpu>::Launch(
mxnet_op::Kernel<totensor_forward, xpu>::Launch(
s, channel, output, input, length, channel, step);
});
});
}

Expand All @@ -121,13 +117,12 @@ void ToTensorOpForward(const nnvm::NodeAttrs &attrs,
const std::vector<TBlob> &outputs) {
CHECK_EQ(inputs.size(), 1U);
CHECK_EQ(outputs.size(), 1U);
CHECK_EQ(req.size(), 1U);

// 3D Input - (h, w, c)
if (inputs[0].ndim() == 3) {
const int length = inputs[0].shape_[0] * inputs[0].shape_[1];
const uint32_t channel = inputs[0].shape_[2];
ToTensorImpl<xpu>(ctx, inputs, outputs, req, length, channel);
ToTensorImpl<xpu>(ctx, inputs, outputs, length, channel);
} else if (inputs[0].ndim() == 4) {
// 4D input (n, h, w, c)
const int batch_size = inputs[0].shape_[0];
Expand All @@ -137,7 +132,7 @@ void ToTensorOpForward(const nnvm::NodeAttrs &attrs,

#pragma omp parallel for
for (auto n = 0; n < batch_size; ++n) {
ToTensorImpl<xpu>(ctx, inputs, outputs, req, length, channel, n*step);
ToTensorImpl<xpu>(ctx, inputs, outputs, length, channel, n*step);
}
}
}
Expand Down

0 comments on commit 14bedee

Please sign in to comment.