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
9e1a5ec4
Commit
9e1a5ec4
authored
Jan 17, 2017
by
Tianqi Chen
Committed by
GitHub
Jan 17, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[RUNTIME] Enable OpenCL (#17)
parent
e9ff9a89
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
105 additions
and
18 deletions
+105
-18
Makefile
+16
-1
include/tvm/c_runtime_api.h
+17
-0
make/config.mk
+3
-0
python/tvm/__init__.py
+1
-1
python/tvm/_ctypes/_runtime_api.py
+25
-1
python/tvm/ndarray.py
+1
-0
python/tvm/schedule.py
+1
-1
src/runtime/c_runtime_api.cc
+17
-0
src/runtime/device_api.h
+18
-2
src/runtime/device_api_gpu.h
+1
-10
src/runtime/device_api_opencl.h
+0
-0
tests/python/test_runtime_ndarray.py
+1
-0
tests/travis/run_test.sh
+4
-2
No files found.
Makefile
View file @
9e1a5ec4
...
...
@@ -26,6 +26,7 @@ endif
export
LDFLAGS
=
-pthread
-lm
export
CFLAGS
=
-std
=
c++11
-Wall
-O2
\
-Iinclude
-Idmlc-core
/include
-IHalideIR
/src
-fPIC
export
FRAMEWORKS
=
ifneq
($(ADD_CFLAGS),
NONE)
CFLAGS
+=
$(ADD_CFLAGS)
...
...
@@ -43,6 +44,20 @@ else
CFLAGS
+=
-DTVM_CUDA_RUNTIME
=
0
endif
ifeq
($(USE_OPENCL),
1)
CFLAGS
+=
-DTVM_OPENCL_RUNTIME
=
1
UNAME_S
:=
$(
shell
uname
-s
)
ifeq
($(UNAME_S),
Darwin)
FRAMEWORKS
+=
-framework
OpenCL
else
LDFLAGS
+=
-lOpenCL
endif
else
CFLAGS
+=
-DTVM_OPENCL_RUNTIME
=
0
endif
include
tests/cpp/unittest.mk
test
:
$(TEST)
...
...
@@ -59,7 +74,7 @@ lib/libtvm.a: $(ALL_DEP)
lib/libtvm.so
:
$(ALL_DEP)
@
mkdir
-p
$
(
@D
)
$(CXX)
$(CFLAGS)
-shared
-o
$@
$
(
filter %.o %.a,
$^
)
$(LDFLAGS)
$(CXX)
$(CFLAGS)
$(FRAMEWORKS)
-shared
-o
$@
$
(
filter %.o %.a,
$^
)
$(LDFLAGS)
$(LIB_HALIDE_IR)
:
LIBHALIDEIR
...
...
include/tvm/c_runtime_api.h
View file @
9e1a5ec4
...
...
@@ -151,6 +151,23 @@ typedef TVMArray* TVMArrayHandle;
TVM_DLL
const
char
*
TVMGetLastError
(
void
);
/*!
* \brief Initialize certain type of devices, this may
* not be necessary for all device types. But is needed for OpenCL.
*
* \param dev_mask The device mask of device type to be initialized
* \param option_keys Additional option keys to pass.
* \param option_vals Additional option values to pass
* \param num_options Number of options to be passed into it.
* \param out_code 1: success, 0: already initialized
* \return Whether the function is successful.
*/
TVM_DLL
int
TVMDeviceInit
(
int
dev_mask
,
const
char
**
option_keys
,
const
char
**
option_vals
,
int
num_options
,
int
*
out_code
);
/*!
* \brief Whether the specified context is enabled.
*
* \param ctx The context to be checked.
...
...
make/config.mk
View file @
9e1a5ec4
...
...
@@ -37,6 +37,9 @@ ADD_CFLAGS =
# whether use CUDA during compile
USE_CUDA = 1
# whether use OpenCL during compile
USE_OPENCL = 0
# add the path to CUDA library to link and compile flag
# if you have already add them to environment variable, leave it as NONE
# USE_CUDA_PATH = /usr/local/cuda
...
...
python/tvm/__init__.py
View file @
9e1a5ec4
...
...
@@ -12,7 +12,7 @@ from . import collections
from
.
import
schedule
from
.
import
ndarray
as
nd
from
.ndarray
import
cpu
,
gpu
,
opencl
from
.ndarray
import
cpu
,
gpu
,
opencl
,
init_opencl
from
._base
import
TVMError
from
.function
import
*
python/tvm/_ctypes/_runtime_api.py
View file @
9e1a5ec4
...
...
@@ -7,7 +7,7 @@ import ctypes
import
numpy
as
np
from
.._base
import
_LIB
from
.._base
import
c_array
from
.._base
import
c_array
,
c_str
from
.._base
import
check_call
...
...
@@ -182,6 +182,30 @@ def sync(ctx):
check_call
(
_LIB
.
TVMSynchronize
(
ctx
,
None
))
def
init_opencl
(
**
kwargs
):
"""Initialize the opencl with the options.
Parameters
----------
kwargs : dict
The options
"""
keys
=
[]
vals
=
[]
for
k
,
v
in
kwargs
.
items
():
keys
.
append
(
c_str
(
k
))
vals
.
append
(
c_str
(
v
))
dev_mask
=
ctypes
.
c_int
(
4
)
out_code
=
ctypes
.
c_int
()
check_call
(
_LIB
.
TVMDeviceInit
(
dev_mask
,
c_array
(
ctypes
.
c_char_p
,
keys
),
c_array
(
ctypes
.
c_char_p
,
vals
),
ctypes
.
c_int
(
len
(
keys
)),
ctypes
.
byref
(
out_code
)))
return
out_code
.
value
!=
0
class
NDArrayBase
(
object
):
"""A simple Device/CPU Array object in runtime."""
__slots__
=
[
"handle"
]
...
...
python/tvm/ndarray.py
View file @
9e1a5ec4
...
...
@@ -9,6 +9,7 @@ import numpy as _np
from
._ctypes._runtime_api
import
TVMContext
,
TVMDataType
,
NDArrayBase
from
._ctypes._runtime_api
import
cpu
,
gpu
,
opencl
,
empty
,
sync
from
._ctypes._runtime_api
import
_init_runtime_module
from
._ctypes._runtime_api
import
init_opencl
class
NDArray
(
NDArrayBase
):
...
...
python/tvm/schedule.py
View file @
9e1a5ec4
...
...
@@ -24,7 +24,7 @@ class Schedule(NodeBase):
k
=
k
.
op
if
not
isinstance
(
k
,
_tensor
.
Operation
):
raise
ValueError
(
"Expect schedule key to be Tensor or Operation"
)
if
not
k
in
self
.
stage_map
:
if
k
not
in
self
.
stage_map
:
raise
ValueError
(
"Cannot find the operation
%
s in schedule"
%
(
str
(
k
)))
return
self
.
stage_map
[
k
]
...
...
src/runtime/c_runtime_api.cc
View file @
9e1a5ec4
...
...
@@ -64,6 +64,23 @@ inline size_t GetDataAlignment(TVMArray* arr) {
using
namespace
tvm
::
runtime
;
int
TVMDeviceInit
(
int
dev_mask
,
const
char
**
option_keys
,
const
char
**
option_vals
,
int
num_options
,
int
*
out_code
)
{
API_BEGIN
();
*
out_code
=
1
;
switch
(
dev_mask
)
{
case
kOpenCL
:
{
*
out_code
=
DeviceInit
<
kOpenCL
>
(
option_keys
,
option_vals
,
num_options
);
break
;
}
default:
break
;
}
API_END
();
}
int
TVMContextEnabled
(
TVMContext
ctx
,
int
*
out_enabled
)
{
API_BEGIN
();
...
...
src/runtime/device_api.h
View file @
9e1a5ec4
/*!
* Copyright (c) 2016 by Contributors
* \file device_api.h
x
* \file device_api.h
* \brief Device specific API
*/
#ifndef TVM_RUNTIME_DEVICE_API_H_
...
...
@@ -12,6 +12,21 @@
namespace
tvm
{
namespace
runtime
{
/*!
* \brief Initialize the device.
* \param option_keys Additional option keys to pass.
* \param option_vals Additional option values to pass
* \param num_options Number of options to be passed into it.
* \return 0 if success, 1: if already initialized
* \tparam xpu The device mask.
*/
template
<
TVMDeviceMask
xpu
>
inline
bool
DeviceInit
(
const
char
**
option_keys
,
const
char
**
option_vals
,
int
num_options
)
{
return
true
;
}
/*!
* \brief Whether ctx is enabled.
* \param ctx The device context to perform operation.
* \tparam xpu The device mask.
...
...
@@ -93,7 +108,8 @@ inline void StreamSync(TVMContext ctx, TVMStreamHandle stream);
}
// namespace runtime
}
// namespace tvm
#include "./device_api_gpu.h"
#include "./device_api_cpu.h"
#include "./device_api_gpu.h"
#include "./device_api_opencl.h"
#endif // TVM_RUNTIME_DEVICE_API_H_
src/runtime/device_api_gpu.h
View file @
9e1a5ec4
/*!
* Copyright (c) 2016 by Contributors
* \file
ctx
ice_api_gpu.h
* \file
dev
ice_api_gpu.h
* \brief GPU specific API
*/
#ifndef TVM_RUNTIME_DEVICE_API_GPU_H_
...
...
@@ -14,15 +14,6 @@
namespace
tvm
{
namespace
runtime
{
/*!
* \brief Check CUDA error.
* \param msg Message to print if an error occured.
*/
#define CHECK_CUDA_ERROR(msg) \
{ \
cudaError_t e = cudaGetLastError(); \
CHECK_EQ(e, cudaSuccess) << (msg) << " CUDA: " << cudaGetErrorString(e); \
}
/*!
* \brief Protected CUDA call.
...
...
src/runtime/device_api_opencl.h
0 → 100644
View file @
9e1a5ec4
This diff is collapsed.
Click to expand it.
tests/python/test_runtime_ndarray.py
View file @
9e1a5ec4
...
...
@@ -2,6 +2,7 @@ import tvm
import
numpy
as
np
def
enabled_ctx_list
():
tvm
.
init_opencl
()
ctx_list
=
[
tvm
.
cpu
(
0
),
tvm
.
gpu
(
0
),
tvm
.
opencl
(
0
)]
ctx_list
=
[
ctx
for
ctx
in
ctx_list
if
ctx
.
enabled
]
return
ctx_list
...
...
tests/travis/run_test.sh
View file @
9e1a5ec4
...
...
@@ -16,13 +16,15 @@ fi
cp make/config.mk config.mk
echo
"USE_CUDA=0"
>>
config.mk
echo
"USE_OPENCL=0"
>>
config.mk
if
[
!
${
TRAVIS_OS_NAME
}
==
"osx"
]
;
then
if
[
${
TRAVIS_OS_NAME
}
==
"osx"
]
;
then
echo
"USE_OPENCL=1"
>>
config.mk
else
# use g++-4.8 for linux
if
[
${
CXX
}
==
"g++"
]
;
then
export
CXX
=
g++-4.8
fi
echo
"USE_OPENCL=0"
>>
config.mk
fi
if
[
${
TASK
}
==
"cpp_test"
]
||
[
${
TASK
}
==
"all_test"
]
;
then
...
...
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