Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tic
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenyuanbo
tic
Commits
a364af8f
Commit
a364af8f
authored
May 13, 2019
by
Siva
Committed by
Tianqi Chen
May 13, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[GOLANG] Some fixes for golang latest version compiler. #3119 (#3182)
parent
6a4d71ff
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
26 deletions
+26
-26
golang/src/bytearray.go
+2
-2
golang/src/function.go
+10
-10
golang/src/module.go
+3
-3
golang/src/ndarray.go
+11
-11
No files found.
golang/src/bytearray.go
View file @
a364af8f
...
@@ -51,7 +51,7 @@ func (tbytearray ByteArray) nativeCPtr() (retVal uintptr) {
...
@@ -51,7 +51,7 @@ func (tbytearray ByteArray) nativeCPtr() (retVal uintptr) {
// `val` is the golang string object from which the ByteArray is initialized.
// `val` is the golang string object from which the ByteArray is initialized.
func
(
tbytearray
ByteArray
)
setData
(
val
string
)
{
func
(
tbytearray
ByteArray
)
setData
(
val
string
)
{
bufPtr
:=
((
*
C
.
TVMByteArray
)(
unsafe
.
Pointer
(
tbytearray
)))
.
data
bufPtr
:=
((
*
C
.
TVMByteArray
)(
unsafe
.
Pointer
(
tbytearray
)))
.
data
if
bufPtr
==
(
*
_Ctype_
char
)(
C
.
NULL
)
{
if
bufPtr
==
(
*
C
.
char
)(
C
.
NULL
)
{
C
.
free
(
unsafe
.
Pointer
(
bufPtr
))
C
.
free
(
unsafe
.
Pointer
(
bufPtr
))
}
}
...
@@ -74,7 +74,7 @@ func (tbytearray ByteArray) getData() (retVal []byte) {
...
@@ -74,7 +74,7 @@ func (tbytearray ByteArray) getData() (retVal []byte) {
// returns newly created ByteArray.
// returns newly created ByteArray.
func
newByteArray
(
val
[]
byte
)
(
retVal
ByteArray
)
{
func
newByteArray
(
val
[]
byte
)
(
retVal
ByteArray
)
{
handle
:=
ByteArray
(
C
.
malloc
(
C
.
sizeof_TVMByteArray
))
handle
:=
ByteArray
(
C
.
malloc
(
C
.
sizeof_TVMByteArray
))
((
*
C
.
TVMByteArray
)(
unsafe
.
Pointer
(
handle
)))
.
data
=
(
*
_Ctype_
char
)(
C
.
NULL
)
((
*
C
.
TVMByteArray
)(
unsafe
.
Pointer
(
handle
)))
.
data
=
(
*
C
.
char
)(
C
.
NULL
)
((
*
C
.
TVMByteArray
)(
unsafe
.
Pointer
(
handle
)))
.
size
=
0
((
*
C
.
TVMByteArray
)(
unsafe
.
Pointer
(
handle
)))
.
size
=
0
handle
.
setData
(
string
(
val
))
handle
.
setData
(
string
(
val
))
retVal
=
handle
retVal
=
handle
...
...
golang/src/function.go
View file @
a364af8f
...
@@ -123,7 +123,7 @@ func GetGlobalFunction(funcname string) (retVal *Function, err error) {
...
@@ -123,7 +123,7 @@ func GetGlobalFunction(funcname string) (retVal *Function, err error) {
cfuncname
:=
C
.
CString
(
funcname
)
cfuncname
:=
C
.
CString
(
funcname
)
ret
:=
(
int32
)(
C
.
TVMFuncGetGlobal
(
cfuncname
,
ret
:=
(
int32
)(
C
.
TVMFuncGetGlobal
(
cfuncname
,
(
*
_Ctype_
TVMFunctionHandle
)(
unsafe
.
Pointer
(
&
funp
))))
(
*
C
.
TVMFunctionHandle
)(
unsafe
.
Pointer
(
&
funp
))))
C
.
free
(
unsafe
.
Pointer
(
cfuncname
))
C
.
free
(
unsafe
.
Pointer
(
cfuncname
))
if
ret
!=
0
{
if
ret
!=
0
{
...
@@ -229,12 +229,12 @@ func nativeTVMFuncCall(funp *Function, argValues []*Value, typeCodes []int32,
...
@@ -229,12 +229,12 @@ func nativeTVMFuncCall(funp *Function, argValues []*Value, typeCodes []int32,
retValues
[]
*
Value
,
retTypeCode
*
int32
)
(
err
error
)
{
retValues
[]
*
Value
,
retTypeCode
*
int32
)
(
err
error
)
{
nargValues
:=
nativeFromGoSlice
(
argValues
)
nargValues
:=
nativeFromGoSlice
(
argValues
)
nretValues
:=
nativeFromGoSlice
(
retValues
)
nretValues
:=
nativeFromGoSlice
(
retValues
)
result
:=
(
int32
)(
C
.
TVMFuncCall
(
_Ctype_
TVMFunctionHandle
(
*
funp
),
result
:=
(
int32
)(
C
.
TVMFuncCall
(
C
.
TVMFunctionHandle
(
*
funp
),
(
*
_Ctype_
TVMValue
)(
unsafe
.
Pointer
(
nargValues
)),
(
*
C
.
TVMValue
)(
unsafe
.
Pointer
(
nargValues
)),
(
*
_Ctype_
int
)(
unsafe
.
Pointer
(
&
(
typeCodes
[
0
]))),
(
*
C
.
int
)(
unsafe
.
Pointer
(
&
(
typeCodes
[
0
]))),
C
.
int
(
len
(
argValues
)),
C
.
int
(
len
(
argValues
)),
(
*
_Ctype_
TVMValue
)(
unsafe
.
Pointer
(
nretValues
)),
(
*
C
.
TVMValue
)(
unsafe
.
Pointer
(
nretValues
)),
(
*
_Ctype_
int
)(
unsafe
.
Pointer
(
retTypeCode
))))
(
*
C
.
int
)(
unsafe
.
Pointer
(
retTypeCode
))))
nativeToGoSlice
(
nargValues
,
argValues
,
typeCodes
)
nativeToGoSlice
(
nargValues
,
argValues
,
typeCodes
)
nativeToGoSlice
(
nretValues
,
retValues
,
(
*
[
1
<<
31
]
int32
)(
unsafe
.
Pointer
(
retTypeCode
))[
:
1
:
1
])
nativeToGoSlice
(
nretValues
,
retValues
,
(
*
[
1
<<
31
]
int32
)(
unsafe
.
Pointer
(
retTypeCode
))[
:
1
:
1
])
C
.
free
(
unsafe
.
Pointer
(
nargValues
))
C
.
free
(
unsafe
.
Pointer
(
nargValues
))
...
@@ -312,9 +312,9 @@ func goTVMCallback(args C.native_voidp, typeCodes C.native_voidp, numArgs int32,
...
@@ -312,9 +312,9 @@ func goTVMCallback(args C.native_voidp, typeCodes C.native_voidp, numArgs int32,
// Handle KStr, KBytes: Local finalizers shouldn't try freeing them.
// Handle KStr, KBytes: Local finalizers shouldn't try freeing them.
retValues
[
0
]
.
isLocal
=
false
retValues
[
0
]
.
isLocal
=
false
apiRet
:=
(
int32
)
(
C
.
TVMCFuncSetReturn
(
_Ctype_
TVMRetValueHandle
(
retArg
),
apiRet
:=
(
int32
)
(
C
.
TVMCFuncSetReturn
(
C
.
TVMRetValueHandle
(
retArg
),
(
*
_Ctype_
TVMValue
)(
unsafe
.
Pointer
(
nretValues
)),
(
*
C
.
TVMValue
)(
unsafe
.
Pointer
(
nretValues
)),
(
*
_Ctype_
int
)(
unsafe
.
Pointer
(
&
retTypeCode
)),
1
))
(
*
C
.
int
)(
unsafe
.
Pointer
(
&
retTypeCode
)),
1
))
C
.
free
(
unsafe
.
Pointer
(
nretValues
))
C
.
free
(
unsafe
.
Pointer
(
nretValues
))
if
apiRet
!=
0
{
if
apiRet
!=
0
{
errStr
:=
string
(
"TVMCFuncSetReturn failed "
)
errStr
:=
string
(
"TVMCFuncSetReturn failed "
)
...
@@ -372,7 +372,7 @@ func RegisterFunction(args ...interface{}) (err error) {
...
@@ -372,7 +372,7 @@ func RegisterFunction(args ...interface{}) (err error) {
cfuncname
:=
C
.
CString
(
funcname
)
cfuncname
:=
C
.
CString
(
funcname
)
result
:=
(
int32
)
(
C
.
TVMFuncRegisterGlobal
(
cfuncname
,
result
:=
(
int32
)
(
C
.
TVMFuncRegisterGlobal
(
cfuncname
,
_Ctype_
TVMFunctionHandle
(
*
fhandle
),
C
.
TVMFunctionHandle
(
*
fhandle
),
0
));
// Override = False
0
));
// Override = False
C
.
free
(
unsafe
.
Pointer
(
cfuncname
))
C
.
free
(
unsafe
.
Pointer
(
cfuncname
))
if
result
!=
0
{
if
result
!=
0
{
...
...
golang/src/module.go
View file @
a364af8f
...
@@ -64,7 +64,7 @@ func LoadModuleFromFile(modpath string, args ...interface{}) (retVal *Module, er
...
@@ -64,7 +64,7 @@ func LoadModuleFromFile(modpath string, args ...interface{}) (retVal *Module, er
ret
:=
(
int32
)(
C
.
TVMModLoadFromFile
(
cmodpath
,
ret
:=
(
int32
)(
C
.
TVMModLoadFromFile
(
cmodpath
,
cmodtype
,
cmodtype
,
(
*
_Ctype_
TVMModuleHandle
)(
unsafe
.
Pointer
(
&
modp
))))
(
*
C
.
TVMModuleHandle
)(
unsafe
.
Pointer
(
&
modp
))))
C
.
free
(
unsafe
.
Pointer
(
cmodpath
))
C
.
free
(
unsafe
.
Pointer
(
cmodpath
))
C
.
free
(
unsafe
.
Pointer
(
cmodtype
))
C
.
free
(
unsafe
.
Pointer
(
cmodtype
))
...
@@ -117,10 +117,10 @@ func (tvmmodule *Module) GetFunction (
...
@@ -117,10 +117,10 @@ func (tvmmodule *Module) GetFunction (
var
funp
uintptr
var
funp
uintptr
cfuncname
:=
C
.
CString
(
funcname
)
cfuncname
:=
C
.
CString
(
funcname
)
ret
:=
(
int32
)(
C
.
TVMModGetFunction
((
_Ctype_
TVMModuleHandle
)(
*
tvmmodule
),
ret
:=
(
int32
)(
C
.
TVMModGetFunction
((
C
.
TVMModuleHandle
)(
*
tvmmodule
),
cfuncname
,
cfuncname
,
C
.
int
(
queryImports
),
C
.
int
(
queryImports
),
(
*
_Ctype_
TVMFunctionHandle
)(
unsafe
.
Pointer
(
&
funp
))))
(
*
C
.
TVMFunctionHandle
)(
unsafe
.
Pointer
(
&
funp
))))
C
.
free
(
unsafe
.
Pointer
(
cfuncname
))
C
.
free
(
unsafe
.
Pointer
(
cfuncname
))
if
ret
!=
0
{
if
ret
!=
0
{
...
...
golang/src/ndarray.go
View file @
a364af8f
...
@@ -48,7 +48,7 @@ func (parray Array) nativeCPtr() (retVal uintptr) {
...
@@ -48,7 +48,7 @@ func (parray Array) nativeCPtr() (retVal uintptr) {
}
}
func
(
parray
Array
)
nativeCopyFrom
(
data
unsafe
.
Pointer
,
datalen
int
)
(
err
error
)
{
func
(
parray
Array
)
nativeCopyFrom
(
data
unsafe
.
Pointer
,
datalen
int
)
(
err
error
)
{
ret
:=
C
.
TVMArrayCopyFromBytes
((
*
_Ctype_
TVMArray
)(
unsafe
.
Pointer
(
parray
.
nativeCPtr
())),
ret
:=
C
.
TVMArrayCopyFromBytes
((
*
C
.
TVMArray
)(
unsafe
.
Pointer
(
parray
.
nativeCPtr
())),
data
,
data
,
C
.
ulong
(
datalen
))
C
.
ulong
(
datalen
))
if
ret
!=
0
{
if
ret
!=
0
{
...
@@ -66,7 +66,7 @@ func (parray Array) nativeCopyFrom(data unsafe.Pointer, datalen int) (err error)
...
@@ -66,7 +66,7 @@ func (parray Array) nativeCopyFrom(data unsafe.Pointer, datalen int) (err error)
func
(
parray
Array
)
CopyFrom
(
val
interface
{})
(
err
error
)
{
func
(
parray
Array
)
CopyFrom
(
val
interface
{})
(
err
error
)
{
var
data
unsafe
.
Pointer
var
data
unsafe
.
Pointer
var
datalen
int
var
datalen
int
dtype
:=
((
*
_Ctype_
TVMArray
)(
unsafe
.
Pointer
(
parray
)))
.
dtype
dtype
:=
((
*
C
.
TVMArray
)(
unsafe
.
Pointer
(
parray
)))
.
dtype
switch
val
.
(
type
)
{
switch
val
.
(
type
)
{
case
[]
int8
:
case
[]
int8
:
...
@@ -127,7 +127,7 @@ func (parray Array) CopyFrom(val interface{}) (err error) {
...
@@ -127,7 +127,7 @@ func (parray Array) CopyFrom(val interface{}) (err error) {
}
}
func
(
parray
Array
)
nativeCopyTo
(
data
unsafe
.
Pointer
,
datalen
int
)
(
err
error
){
func
(
parray
Array
)
nativeCopyTo
(
data
unsafe
.
Pointer
,
datalen
int
)
(
err
error
){
ret
:=
C
.
TVMArrayCopyToBytes
((
*
_Ctype_
TVMArray
)(
unsafe
.
Pointer
(
parray
.
nativeCPtr
())),
ret
:=
C
.
TVMArrayCopyToBytes
((
*
C
.
TVMArray
)(
unsafe
.
Pointer
(
parray
.
nativeCPtr
())),
unsafe
.
Pointer
(
data
),
unsafe
.
Pointer
(
data
),
C
.
ulong
(
datalen
))
C
.
ulong
(
datalen
))
...
@@ -150,7 +150,7 @@ func (parray Array) AsSlice() (retVal interface{}, err error) {
...
@@ -150,7 +150,7 @@ func (parray Array) AsSlice() (retVal interface{}, err error) {
for
ii
:=
range
shape
{
for
ii
:=
range
shape
{
size
*=
shape
[
ii
]
size
*=
shape
[
ii
]
}
}
dtype
:=
((
*
_Ctype_
TVMArray
)(
unsafe
.
Pointer
(
parray
)))
.
dtype
dtype
:=
((
*
C
.
TVMArray
)(
unsafe
.
Pointer
(
parray
)))
.
dtype
switch
parray
.
GetDType
()
{
switch
parray
.
GetDType
()
{
case
"int8"
:
case
"int8"
:
...
@@ -222,13 +222,13 @@ func (parray Array) AsSlice() (retVal interface{}, err error) {
...
@@ -222,13 +222,13 @@ func (parray Array) AsSlice() (retVal interface{}, err error) {
// GetNdim returns the number of dimentions in Array
// GetNdim returns the number of dimentions in Array
func
(
parray
Array
)
GetNdim
()
(
retVal
int32
)
{
func
(
parray
Array
)
GetNdim
()
(
retVal
int32
)
{
retVal
=
int32
(((
*
_Ctype_
TVMArray
)(
unsafe
.
Pointer
(
parray
)))
.
ndim
)
retVal
=
int32
(((
*
C
.
TVMArray
)(
unsafe
.
Pointer
(
parray
)))
.
ndim
)
return
return
}
}
// GetShape returns the number of dimentions in Array
// GetShape returns the number of dimentions in Array
func
(
parray
Array
)
GetShape
()
(
retVal
[]
int64
)
{
func
(
parray
Array
)
GetShape
()
(
retVal
[]
int64
)
{
shapePtr
:=
(
*
C
.
int64_t
)(((
*
_Ctype_
TVMArray
)(
unsafe
.
Pointer
(
parray
)))
.
shape
)
shapePtr
:=
(
*
C
.
int64_t
)(((
*
C
.
TVMArray
)(
unsafe
.
Pointer
(
parray
)))
.
shape
)
ndim
:=
parray
.
GetNdim
()
ndim
:=
parray
.
GetNdim
()
shapeSlice
:=
(
*
[
1
<<
31
]
int64
)(
unsafe
.
Pointer
(
shapePtr
))[
:
ndim
:
ndim
]
shapeSlice
:=
(
*
[
1
<<
31
]
int64
)(
unsafe
.
Pointer
(
shapePtr
))[
:
ndim
:
ndim
]
...
@@ -239,14 +239,14 @@ func (parray Array) GetShape() (retVal []int64) {
...
@@ -239,14 +239,14 @@ func (parray Array) GetShape() (retVal []int64) {
// GetDType returns the number of dimentions in Array
// GetDType returns the number of dimentions in Array
func
(
parray
Array
)
GetDType
()
(
retVal
string
)
{
func
(
parray
Array
)
GetDType
()
(
retVal
string
)
{
ret
:=
((
*
_Ctype_
TVMArray
)(
unsafe
.
Pointer
(
parray
)))
.
dtype
ret
:=
((
*
C
.
TVMArray
)(
unsafe
.
Pointer
(
parray
)))
.
dtype
retVal
,
_
=
dtypeFromTVMType
(
*
(
*
pTVMType
)(
unsafe
.
Pointer
(
&
ret
)))
retVal
,
_
=
dtypeFromTVMType
(
*
(
*
pTVMType
)(
unsafe
.
Pointer
(
&
ret
)))
return
return
}
}
// GetCtx returns the number of dimentions in Array
// GetCtx returns the number of dimentions in Array
func
(
parray
Array
)
GetCtx
()
(
retVal
Context
)
{
func
(
parray
Array
)
GetCtx
()
(
retVal
Context
)
{
ret
:=
((
*
_Ctype_
TVMArray
)(
unsafe
.
Pointer
(
parray
)))
.
ctx
ret
:=
((
*
C
.
TVMArray
)(
unsafe
.
Pointer
(
parray
)))
.
ctx
retVal
=
*
(
*
Context
)(
unsafe
.
Pointer
(
&
ret
))
retVal
=
*
(
*
Context
)(
unsafe
.
Pointer
(
&
ret
))
return
return
}
}
...
@@ -267,14 +267,14 @@ func (parray Array) GetCtx() (retVal Context) {
...
@@ -267,14 +267,14 @@ func (parray Array) GetCtx() (retVal Context) {
func
nativeTVMArrayAlloc
(
shape
[]
int64
,
ndim
int32
,
func
nativeTVMArrayAlloc
(
shape
[]
int64
,
ndim
int32
,
dtypeCode
int32
,
dtypeBits
int32
,
dtypeLanes
int32
,
dtypeCode
int32
,
dtypeBits
int32
,
dtypeLanes
int32
,
deviceType
int32
,
deviceID
int32
)
(
retVal
uintptr
,
err
error
)
{
deviceType
int32
,
deviceID
int32
)
(
retVal
uintptr
,
err
error
)
{
ret
:=
(
int32
)(
C
.
TVMArrayAlloc
((
*
_Ctype_
long
)(
&
(
shape
[
0
])),
ret
:=
(
int32
)(
C
.
TVMArrayAlloc
((
*
C
.
long
)(
&
(
shape
[
0
])),
C
.
int
(
ndim
),
C
.
int
(
ndim
),
C
.
int
(
dtypeCode
),
C
.
int
(
dtypeCode
),
C
.
int
(
dtypeBits
),
C
.
int
(
dtypeBits
),
C
.
int
(
dtypeLanes
),
C
.
int
(
dtypeLanes
),
C
.
int
(
deviceType
),
C
.
int
(
deviceType
),
C
.
int
(
deviceID
),
C
.
int
(
deviceID
),
(
*
_Ctype_
TVMArrayHandle
)(
unsafe
.
Pointer
(
&
retVal
))))
(
*
C
.
TVMArrayHandle
)(
unsafe
.
Pointer
(
&
retVal
))))
if
ret
!=
0
{
if
ret
!=
0
{
err
=
errors
.
New
(
getTVMLastError
())
err
=
errors
.
New
(
getTVMLastError
())
return
return
...
@@ -343,6 +343,6 @@ func Empty(shape []int64, args ...interface{}) (parray *Array, err error) {
...
@@ -343,6 +343,6 @@ func Empty(shape []int64, args ...interface{}) (parray *Array, err error) {
//
//
// `ret` indicates the status of this api execution.
// `ret` indicates the status of this api execution.
func
nativeTVMArrayFree
(
parray
Array
)
(
retVal
int32
)
{
func
nativeTVMArrayFree
(
parray
Array
)
(
retVal
int32
)
{
retVal
=
(
int32
)(
C
.
TVMArrayFree
((
*
_Ctype_
TVMArray
)(
unsafe
.
Pointer
(
parray
.
nativeCPtr
()))))
retVal
=
(
int32
)(
C
.
TVMArrayFree
((
*
C
.
TVMArray
)(
unsafe
.
Pointer
(
parray
.
nativeCPtr
()))))
return
return
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment