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

Test/mkl dnn act #11026

Merged
merged 59 commits into from
May 30, 2018
Merged

Test/mkl dnn act #11026

merged 59 commits into from
May 30, 2018

Conversation

azai91
Copy link
Contributor

@azai91 azai91 commented May 22, 2018

Description

(Brief description on what this PR is about)

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at http://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Feature1, tests, (and when applicable, API doc)
  • Feature2, tests, (and when applicable, API doc)

Comments

  • If this change is a backward incompatible change, why must this change be made.
  • Interesting edge cases to note here

@@ -0,0 +1,31 @@
//
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional?

@azai91 azai91 force-pushed the test/mkl-dnn-act branch 2 times, most recently from 13b7a65 to fd39a23 Compare May 22, 2018 23:22
@pengzhao-intel
Copy link
Contributor

@juliusshufan is mkl act test on your test plan? you can work w/ @azai91 for this test.

@azai91 azai91 force-pushed the test/mkl-dnn-act branch 2 times, most recently from 119a21e to 857c3d4 Compare May 23, 2018 04:17
attrs.attrs.dict.insert({"act_type", "relu"});
attrs.attrs.op->attr_parser(&attrs.attrs);
attrs.dispatches.resize(1);
attrs.dispatches[0] = DispatchMode::kFCompute;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need kFComputeEx here. MKLDNN uses kFComputeEx.

for (int i = 0; i < size; i++)
data[i] = i - shift;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only works for the default layout. You need a version for the MKLDNN format as well.

TestArrayShapes tas = GetTestArrayShapes();
std::vector<nnvm::TShape> shapes = tas.shapes;
std::vector<mkldnn::memory::primitive_desc> pds = tas.pds;

std::vector<NDArray> in_arrs;
for (auto shape : shapes) {
in_arrs.emplace_back(shape, Context());
InitArray(&in_arrs.back());
init_fn(&in_arrs.back());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need a version to initialize the MKLDNN NDArray as well.

mshadow::default_real_t *d2 = static_cast<mshadow::default_real_t*>(blob2.dptr_);
EXPECT_EQ(tmp1.shape().Size(), tmp2.shape().Size());
for (size_t i = 0; i < tmp1.shape().Size(); i++) {
EXPECT_EQ(d1[i], std::abs(d2[i]));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

abs? if it's negative, it should be 0.

}
}

void TestOp(const OpAttrs &attrs, InitFunc init_fn, VerifyFunc verify_fn) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function actually can only test unary operators. It's better to have unary in the name

@azai91 azai91 force-pushed the test/mkl-dnn-act branch 8 times, most recently from c987bca to 2d24c60 Compare May 24, 2018 16:29
std::vector<NDArray> in_arrs;
in_arrs.emplace_back(shape, Context());
InitArray(&in_arrs.back());
init_fn(&in_arrs.back(), false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you make them true as well?


// Get a reused version.
nnvm::TShape s(1);
s[0] = shape.Size();
NDArray arr(s, Context());
arr = arr.AsArray(shape, arr.dtype());
InitArray(&arr);
init_fn(&arr, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same here

const TBlob &blob = arr->data();
mshadow::default_real_t *data = blob.dptr<mshadow::default_real_t>();
size_t size = blob.Size();
for (size_t i = 0; i < size; i++)
data[i] = i;
if (is_rand) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_rand inside the for loop ?

const TBlob &blob = arr->data();
mshadow::default_real_t *data = blob.dptr<mshadow::default_real_t>();
size_t size = blob.Size();
int size = blob.Size();
if (is_rand) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_rand should be inside the for loop

@anirudh2290
Copy link
Member

can you fix lint

} else {
in_mem = inputs[i].GetMKLDNNData();
}
in_mem = inputs[i].GetMKLDNNData();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you modify the code here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woops realized it was not the same. reverted.

@azai91 azai91 force-pushed the test/mkl-dnn-act branch 3 times, most recently from ded9ecc to 2e0c42a Compare May 29, 2018 04:59
}
}
}

TEST(IMPERATIVE, UnaryOp) {
OpAttrs attrs = GetCopyOp();
TestUnaryOp(attrs, VerifyCopyResult);
TestUnaryOp(attrs, InitDefaultArray, VerifyCopyResult);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix the indent here.

@piiswrong piiswrong merged commit 92286c9 into apache:master May 30, 2018
rahul003 pushed a commit to rahul003/mxnet that referenced this pull request Jun 4, 2018
* add mkl act unit test

* fix operator name

* use custom ndarray init

* func missing param

* add init fn for act operator test

* remove extra white space

* fix fetch relu operator

* fix get  relu operator name

* add assert abs in verify fn

* remove unused operator

* cast blob ptr to float

* use parsed param

* use attr_parser

* fix header order

* update test fn name

* use relu fn

* add kFComputeEx dispatch

* init posneg mklarray

* fix generating rnd pos neg ints

* output arrays are rnd generated

* test that getinputarrays creates view and mkldnn arrays

* add more output types

* fix typo

* fix gettestput test

* create arrattr struct to display arr info

* refactor initarray

* print arr description in verify fn

* use long int string interpolation

* fix alias params

* iterate over dims

* print c_str

* print output info

* improve print message

* improve print

* fix new lines in output

* refactor print messages

* fix typos

* fix lint issues

* fix rebase

* pass ndarray as ptr

* store copy of ndarray in attrs obj

* fix rem inits

* fix dispatch size

* move print earlier

* use createmkldnnmem helper fun

* fix lint

* refactor if else statement

* use buffer ndarray

* fix spacing

* fix refactor

* revert sum refactor

* use fallback compute

* fix typo

* fix lint

* use fallbackcompute fn for act operator

* convert activation impl funcs to fxcompute std

* remove unused var

* move unused variable

* fix indent
zheng-da pushed a commit to zheng-da/incubator-mxnet that referenced this pull request Jun 28, 2018
* add mkl act unit test

* fix operator name

* use custom ndarray init

* func missing param

* add init fn for act operator test

* remove extra white space

* fix fetch relu operator

* fix get  relu operator name

* add assert abs in verify fn

* remove unused operator

* cast blob ptr to float

* use parsed param

* use attr_parser

* fix header order

* update test fn name

* use relu fn

* add kFComputeEx dispatch

* init posneg mklarray

* fix generating rnd pos neg ints

* output arrays are rnd generated

* test that getinputarrays creates view and mkldnn arrays

* add more output types

* fix typo

* fix gettestput test

* create arrattr struct to display arr info

* refactor initarray

* print arr description in verify fn

* use long int string interpolation

* fix alias params

* iterate over dims

* print c_str

* print output info

* improve print message

* improve print

* fix new lines in output

* refactor print messages

* fix typos

* fix lint issues

* fix rebase

* pass ndarray as ptr

* store copy of ndarray in attrs obj

* fix rem inits

* fix dispatch size

* move print earlier

* use createmkldnnmem helper fun

* fix lint

* refactor if else statement

* use buffer ndarray

* fix spacing

* fix refactor

* revert sum refactor

* use fallback compute

* fix typo

* fix lint

* use fallbackcompute fn for act operator

* convert activation impl funcs to fxcompute std

* remove unused var

* move unused variable

* fix indent
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants