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

enable ngraph context in mxnet #350

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open

enable ngraph context in mxnet #350

wants to merge 22 commits into from

Conversation

ashokei
Copy link
Contributor

@ashokei ashokei commented Jul 28, 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

@ashokei ashokei requested a review from mbrookhart July 28, 2018 00:11
@@ -204,7 +201,8 @@ class Graph : public Node {
context_(context),
enable_fprop_cache(enable_fprop_cache) {
fprop_cache = std::make_shared<ngraph::FpropCache>();
is_reuse_mem = context.dev_type != mxnet::Context::kNNP;
is_reuse_mem = context.dev_type == mxnet::Context::CPU().dev_type ||
Copy link
Contributor Author

Choose a reason for hiding this comment

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

you can use enum directly, instead of creating default and getting its type. Also, we may want to reuse mem for "ngraph:cpu" (i guess we expect users to use mx.cpu(), but just in case they decide to use ngraph:cpu).

@@ -459,6 +459,10 @@ void Compiler::DeepCopy(const nnvm::Graph& graph) {
}

bool bad_type(const NodePtr& node) {
if (!ngraph_context_fallback() &&
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we need a test for this functionality, were you able to check by exporting env.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, getting an error if I export the env variable, doesn't make much sense, will debug.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed.

@mbrookhart mbrookhart changed the title [WIP] enable ngraph context in mxnet enable ngraph context in mxnet Jul 31, 2018
@mbrookhart mbrookhart requested a review from cconvey July 31, 2018 22:28
std::pair<std::string, int32_t> NGraphContextFromDevID(int32_t dev_id) {
int32_t backend_num = dev_id >> 16;
int32_t device_num = dev_id - (backend_num << 16);
std::cout << "NGraphContextfromDevID " << backends.at(backend_num) << " " << device_num << " " << dev_id << std::endl;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

may have to remove std::cout's.

@@ -34,6 +34,8 @@
#include <nnvm/op.h>
#include <nnvm/tuple.h>
#include <nnvm/symbolic.h>
// ngraph context
#include <mxnet/ngraph_context.h>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ngraph build guard ?

@@ -150,14 +154,14 @@ struct Context {
* \return cpu::kDevMask or gpu::kDevMask
*/
inline DeviceType dev_mask() const {
if (dev_type == kCPUPinned || dev_type == kCPUShared || dev_type == kNNP) return kCPU;
if (dev_type == kCPUPinned || dev_type == kCPUShared || dev_type == kNGraph) return kCPU;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

may give compile error if built without MXNET_USE_NGRAPH

Copy link
Contributor

Choose a reason for hiding this comment

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

Made kNGraph always compile to avoid this, but throws an error if python attempts to initialize an nGraph context when mxnet wasn't compiled with nGraph.

@ransford2011
Copy link
Contributor

It didn't build for me @ashokei .

@ransford2011
Copy link
Contributor

ransford2011 commented Aug 1, 2018

This is the error I saw when I built with 18.04 src/ngraph/ngraph_utils.cc: In function 'ngraph_bridge::NgraphNodePtr ngraph_bridge::ensure_vector_only_shape(ngraph_bridge::NgraphNodePtr)': src/ngraph/ngraph_utils.cc:141:27: error: no match for 'operator<<' (operand types are 'std::basic_ostream<char>' and 'const ngraph::Shape') os << "Tensor shape " << n_shape << " is not in vector-plus-axes form."; ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~

I built with 16.04 and I got something similar

@mbrookhart
Copy link
Contributor

You need to update your version of nGraph, Adam Proctor broke something a few days ago.

@ransford2011
Copy link
Contributor

ransford2011 commented Aug 2, 2018

.
----------------------------------------------------------------------
OK
Aborted

ashokei pushed a commit that referenced this pull request Oct 24, 2018
```julia
julia> x = mx.NDArray([1 2; 3 4; 5 6])
3×2 mx.NDArray{Int64,2} @ CPU0:
 1  2
 3  4
 5  6

julia> size(x, 1, 2, 3, 4)
(3, 2, 1, 1)
```
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.

4 participants