Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions docs/api/python/contrib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@ Contrib APIs
------------
.. automodule:: tvm.contrib

tvm.contrib.nvcc_compiler
~~~~~~~~~~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.nvcc_compiler
tvm.contrib.nvcc
~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.nvcc
:members:

tvm.contrib.cc
~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.cc
:members:

tvm.contrib.cc_compiler
~~~~~~~~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.cc_compiler
tvm.contrib.xcode
~~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.xcode
:members:

tvm.contrib.rpc
~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.rpc
:members:

Expand All @@ -22,7 +27,6 @@ tvm.contrib.util
.. automodule:: tvm.contrib.util
:members:


tvm.contrib.cblas
~~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.cblas
Expand Down
File renamed without changes.
17 changes: 6 additions & 11 deletions python/tvm/contrib/nvcc_compiler.py → python/tvm/contrib/nvcc.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# pylint: disable=invalid-name
"""Utility to invoke nvcc compiler in the system"""
from __future__ import absolute_import as _abs
import os
import sys
import tempfile
import subprocess
from . import util

def compile_source(code, target="ptx", arch=None,
options=None, path_target=None):
def compile_cuda(code, target="ptx", arch=None,
options=None, path_target=None):
"""Compile cuda code with NVCC from env.

Parameters
Expand All @@ -32,11 +31,11 @@ def compile_source(code, target="ptx", arch=None,
cubin : bytearray
The bytearray of the cubin
"""
temp_dir = tempfile.mkdtemp()
temp = util.tempdir()
if target not in ["cubin", "ptx", "fatbin"]:
raise ValueError("target must be in cubin, ptx, fatbin")
temp_code = os.path.join(temp_dir, "my_kernel.cu")
temp_target = os.path.join(temp_dir, "my_kernel.%s" % target)
temp_code = temp.relpath("my_kernel.cu")
temp_target = temp.relpath("my_kernel.%s" % target)

with open(temp_code, "w") as out_file:
out_file.write(code)
Expand Down Expand Up @@ -68,8 +67,4 @@ def compile_source(code, target="ptx", arch=None,
cubin = None
else:
cubin = bytearray(open(file_target, "rb").read())
os.remove(temp_code)
if os.path.exists(temp_target):
os.remove(temp_target)
os.rmdir(temp_dir)
return cubin
4 changes: 2 additions & 2 deletions python/tvm/contrib/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import struct
import logging
import multiprocessing
from . import util, cc_compiler
from . import util, cc
from ..module import load as _load_module
from .._ffi.function import _init_api, register_func
from .._ffi.ndarray import context as _context
Expand All @@ -39,7 +39,7 @@ def load_module(file_name):
# Try create a shared library in remote
if path.endswith('.o'):
logging.info('Create shared library based on %s', path)
cc_compiler.create_shared(path + '.so', path)
cc.create_shared(path + '.so', path)
path += '.so'
m = _load_module(path)
logging.info("load_module %s", path)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# pylint: disable=invalid-name
"""Utility to invoke metal compiler in the CLI system"""
"""Utility to invoke Xcode compiler toolchain"""
from __future__ import absolute_import as _abs
import sys
import subprocess
from . import util

def compile_source(code, path_target=None):
def compile_metal(code, path_target=None, sdk="macosx"):
"""Compile metal with CLI tool from env.

Parameters
Expand All @@ -16,6 +16,9 @@ def compile_source(code, path_target=None):
path_target : str, optional
Output file.

sdk : str, optional
The target platform SDK.

Return
------
metallib : bytearray
Expand All @@ -30,9 +33,9 @@ def compile_source(code, path_target=None):
out_file.write(code)
file_target = path_target if path_target else temp_target

cmd1 = ["xcrun", "-sdk", "macosx", "metal", "-O3"]
cmd1 = ["xcrun", "-sdk", sdk, "metal", "-O3"]
cmd1 += [temp_code, "-o", temp_ir]
cmd2 = ["xcrun", "-sdk", "macosx", "metallib"]
cmd2 = ["xcrun", "-sdk", sdk, "metallib"]
cmd2 += [temp_ir, "-o", file_target]
proc = subprocess.Popen(
' '.join(cmd1) + ";" + ' '.join(cmd2),
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from collections import namedtuple
from ._ffi.function import ModuleBase, _set_class_module
from ._ffi.function import _init_api
from .contrib import cc_compiler as _cc, util as _util
from .contrib import cc as _cc, util as _util

ProfileResult = namedtuple("ProfileResult", ["mean"])

Expand Down
12 changes: 6 additions & 6 deletions src/common/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct SockAddr {
}
/*!
* \brief set the address
* \param url the url of the address
* \param host the url of the address
* \param port the port of address
*/
void Set(const char *host, int port) {
Expand Down Expand Up @@ -86,7 +86,7 @@ struct SockAddr {
&buf[0], buf.length());
#else
const char *s = inet_ntop(AF_INET, &addr.sin_addr,
&buf[0], buf.length());
&buf[0], static_cast<socklen_t>(buf.length()));
#endif
CHECK(s != nullptr) << "cannot decode address";
std::ostringstream os;
Expand Down Expand Up @@ -138,7 +138,7 @@ class Socket {
}
/*!
* \brief bind the socket to an address
* \param addr
* \param addr The address to be binded
*/
void Bind(const SockAddr &addr) {
if (bind(sockfd, reinterpret_cast<const sockaddr*>(&addr.addr),
Expand Down Expand Up @@ -342,9 +342,9 @@ class TCPSocket : public Socket {
}
/*!
* \brief send data using the socket
* \param buf the pointer to the buffer
* \param buf_ the pointer to the buffer
* \param len the size of the buffer
* \param flags extra flags
* \param flag extra flags
* \return size of data actually sent
* return -1 if error occurs
*/
Expand All @@ -367,7 +367,7 @@ class TCPSocket : public Socket {
/*!
* \brief peform block write that will attempt to send all data out
* can still return smaller than request when error occurs
* \param buf the pointer to the buffer
* \param buf_ the pointer to the buffer
* \param len the size of the buffer
* \return size of data actually sent
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/python/unittest/test_codegen_cross_llvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import tvm
import os
import struct
from tvm.contrib import util, cc_compiler as cc, rpc
from tvm.contrib import util, cc, rpc
import numpy as np

def test_llvm_add_pipeline():
Expand Down
2 changes: 1 addition & 1 deletion tests/python/unittest/test_module_load.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import tvm
from tvm.contrib import cc_compiler as cc, util
from tvm.contrib import cc, util
import ctypes
import os
import numpy as np
Expand Down
2 changes: 2 additions & 0 deletions tests/scripts/task_python_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ make doc
jsdoc web/tvm_runtime.js web/README.md || exit -1
mv out docs/_build/html/jsdoc || exit -1

rm -rf python/tvm/*.pyc python/tvm/*/*.pyc

cd docs
PYTHONPATH=../python make html || exit -1
cd _build/html
Expand Down
2 changes: 2 additions & 0 deletions tests/scripts/task_python_integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export PYTHONPATH=python:apps/extension/python
export PYTHONPATH=${PYTHONPATH}:apps/graph_executor/python:apps/graph_executor/nnvm/python
export LD_LIBRARY_PATH=lib:${LD_LIBRARY_PATH}

rm -rf python/tvm/*.pyc python/tvm/*/*.pyc

# Test TVM
make cython || exit -1

Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/task_python_unittest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

export PYTHONPATH=python

rm -rf python/tvm/*.pyc
rm -rf python/tvm/*.pyc python/tvm/*/*.pyc

TVM_FFI=ctypes python -m nose -v tests/python/unittest || exit -1
TVM_FFI=ctypes python3 -m nose -v tests/python/unittest || exit -1
Expand Down
4 changes: 2 additions & 2 deletions topi/recipe/conv/depthwise_conv2d_map_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import tvm
import numpy as np
from scipy import signal
from tvm.contrib import nvcc_compiler
from tvm.contrib import nvcc

import topi
from topi.nn.util import get_const_tuple
Expand All @@ -13,7 +13,7 @@

@tvm.register_func
def tvm_callback_cuda_compile(code):
ptx = nvcc_compiler.compile_source(code, target="ptx", options=["-arch=sm_52"])
ptx = nvcc.compile_cuda(code, target="ptx", options=["-arch=sm_52"])
return ptx

def write_code(code, fname):
Expand Down
4 changes: 2 additions & 2 deletions topi/recipe/gemm/cuda_gemm_square.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"""Example code to do square matrix multiplication."""
import tvm
import os
from tvm.contrib import nvcc_compiler
from tvm.contrib import nvcc
import numpy as np

TASK="gemm"
USE_MANUAL_CODE = False

@tvm.register_func
def tvm_callback_cuda_compile(code):
ptx = nvcc_compiler.compile_source(code, target="ptx", options=["-arch=sm_52"])
ptx = nvcc.compile_cuda(code, target="ptx", options=["-arch=sm_52"])
return ptx

def write_code(code, fname):
Expand Down
4 changes: 2 additions & 2 deletions topi/recipe/rnn/lstm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import time
import os
import argparse
from tvm.contrib import nvcc_compiler
from tvm.contrib import nvcc
import numpy as np

# Quick knobs
Expand All @@ -17,7 +17,7 @@
@tvm.register_func
def tvm_callback_cuda_compile(code):
"""Use nvcc compiler for better perf."""
ptx = nvcc_compiler.compile_source(code, target="ptx", options=["-arch=sm_52"])
ptx = nvcc.compile_cuda(code, target="ptx", options=["-arch=sm_52"])
return ptx

def write_code(code, fname):
Expand Down
4 changes: 2 additions & 2 deletions topi/recipe/rnn/matexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import time
import os
import argparse
from tvm.contrib import nvcc_compiler
from tvm.contrib import nvcc
import numpy as np

# Quick knobs
Expand All @@ -24,7 +24,7 @@
@tvm.register_func
def tvm_callback_cuda_compile(code):
"""Use nvcc compiler for better perf."""
ptx = nvcc_compiler.compile_source(code, target="ptx", options=["-arch=sm_52"])
ptx = nvcc.compile_cuda(code, target="ptx", options=["-arch=sm_52"])
return ptx

def write_code(code, fname):
Expand Down
2 changes: 1 addition & 1 deletion tutorials/python/get_started.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
# - Then it saves the device module into a ptx file.
# - cc.create_shared calls a env compiler(gcc) to create a shared library
#
from tvm.contrib import cc_compiler as cc
from tvm.contrib import cc
from tvm.contrib import util

temp = util.tempdir()
Expand Down