Skip to content

Conversation

@srkreddy1238
Copy link
Contributor

Thanks for contributing to TVM! Please refer to guideline https://docs.tvm.ai/contribute/ for useful information and tips. After the pull request is submitted, please request code reviews from others in the community.

@tqchen
Copy link
Member

tqchen commented Jul 21, 2018

It is a good start, I would recommend to not use swig but directly use the C FFI in Go, and do a bit wrapping to support Module and TVMValue class like in jvm,

c.f. https://github.com/jdeng/gomxnet

@srkreddy1238
Copy link
Contributor Author

@tqchen

Ref. gomxnet above
I see it implements a new API layer for go instead of mxnet original. Do we define a new API layer for go?

Reason I choose swig was to keep the interface maintenance automatic for changes to c_runtime_api.
And both ways here use same unsafe and C packages below.

pls advice.

@tqchen
Copy link
Member

tqchen commented Jul 23, 2018

I think doing a bit minimum wrapping to make things more native to the language(in this case go) is useful, Take a look at tvm4j and the wrapping being done there

@tqchen tqchen added status: review in progress status: need update need update based on feedbacks labels Jul 23, 2018
@srkreddy1238
Copy link
Contributor Author

@tqchen

I checked the tvm4j and tried to wrap few types inside TVMvalue.

I see other challenges in wrapping the go slices to C arrays for TVMValue array itself and other primitive types. golang use slices very common instead of arrays which complicates the interface.

Hand coding slice to a array for all these types via "C" and "unsafe" need more effort and results almost same like the swig generated interface.

Please advice.

@tqchen
Copy link
Member

tqchen commented Jul 24, 2018

I think if we can build an NDArray.copyfrom(go_slice) function, it will work for most case. The data conversion happens inside the function itself, so it is invisible to the users.

BTW, in terms of package name, seems gotvm is a more canonical name for golang projects :)

@srkreddy1238
Copy link
Contributor Author

@tqchen please have a look.
If the code structure and API naming are good I will finish the few pending API and conclude.

@dmlc/tvm-reviewer welcome to review and comment.

@tqchen
Copy link
Member

tqchen commented Jul 28, 2018

@srkreddy1238 Can you do additional wrappings to provide the following class object?

  • TVMFunction
  • TVMModule
  • TVMArray
  • TVMValue(for handling return value conversion)

@srkreddy1238
Copy link
Contributor Author

Sure, I will add above class objects.

@tqchen
Copy link
Member

tqchen commented Jul 28, 2018

Also please add appropriate documentation for user-facing objects and methods, as per https://blog.golang.org/godoc-documenting-go-code

@srkreddy1238
Copy link
Contributor Author

@tqchen

  • Added wrappers for TVMModule, TVMFunction
  • Dropped DLTensor and given TVMArray instead.
  • TVMValue getter/setter for all these types.
  • Documentation as per the standard.
  • golint addition for Make script.

@srkreddy1238
Copy link
Contributor Author

@tqchen ready for review.

Recent changes

  • Simplify the getter and setter on TVMValue user interface.
  • GetFunction and FuncCall are simplified TVMFuncExec which take funcname and variable args.

go/README.md Outdated
@@ -0,0 +1,51 @@
# tvmgo - Golang Frontend for TVM Runtime
Copy link
Member

Choose a reason for hiding this comment

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

gotvm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

#include <tvm/runtime/c_runtime_api.h>
#include <dlpack/dlpack.h>

// Some type devinitions for golang "C"
Copy link
Member

Choose a reason for hiding this comment

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

provide wrapping in c/c++ via extern "C" and __cplusplus

Copy link
Contributor Author

Choose a reason for hiding this comment

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

gotvm.h ideally should be a command followed by import "C"
cgo picks up picks it it from commented code.

No problem, extern works here well.

Done

@@ -0,0 +1,292 @@
/*!
* Copyright (c) 2018 by Contributors
* \brief gotvm native interface definition
Copy link
Member

Choose a reason for hiding this comment

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

unless it is the convention, use gotvm.cc

@tqchen
Copy link
Member

tqchen commented Aug 4, 2018

I made some simple comments, but the wrapping is still a bit raw(it reads more like C rather than Go), here is what we want ideally(note I am not expert in Go, so syntax might be wrong)

mod = gotvm.LoadFromFile("/path/to/mymodule.so")
f1 = mod.GetFunction("myfunction")
# need to debate how to support function invocation, either in normal style or java style
f1.invoke(args) 

myarr = gotvm.empty(shape, ctx);

@tqchen
Copy link
Member

tqchen commented Aug 4, 2018

Actually since, this involves API design discussion, can you please open an RFC issue so that more people can participate? Maybe there are good ideas from the community, I am not expert in Go, so I can only generalize from my experience in other languages

@srkreddy1238
Copy link
Contributor Author

#1559 for a discussion with team.

@srkreddy1238
Copy link
Contributor Author

@tqchen

f1 = mod.GetFunction("myfunction")
f1.invoke(args) 
f1.free()

The new API TVMFunctionExec ideally does all these. I could keep as above based on the duscussion result.

@srkreddy1238 srkreddy1238 force-pushed the go branch 3 times, most recently from 719b1e9 to ae25688 Compare August 14, 2018 05:36
@tqchen tqchen self-assigned this Aug 21, 2018
@tqchen tqchen added this to the v0.5 milestone Aug 21, 2018
@srkreddy1238
Copy link
Contributor Author

Thanks @grwlf. Addressed the review comments.

@tqchen
Copy link
Member

tqchen commented Dec 6, 2018

OK, if there is no further comments, I will merge this PR in 24 hours. Thanks @grwlf for the reviews.

@tqchen tqchen merged commit 1cb602f into apache:master Dec 9, 2018
@tqchen tqchen added status: accepted and removed status: need update need update based on feedbacks status: review in progress labels Dec 9, 2018
@tqchen
Copy link
Member

tqchen commented Dec 9, 2018

Thanks, @grwlf for the detailed reviews, Thanks, @srkreddy1238 for patiently improving the code during the review process. This is now merged. Please send in followup PRs to enable the test in CI

FrozenGene pushed a commit to FrozenGene/tvm that referenced this pull request Dec 27, 2018
@ZihengJiang ZihengJiang mentioned this pull request Feb 1, 2019
wweic pushed a commit to neo-ai/tvm that referenced this pull request Feb 20, 2019
wweic pushed a commit to neo-ai/tvm that referenced this pull request Feb 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants