Commit 2ab0bfb5 by Tianqi Chen Committed by GitHub

[RENAME] nvcc_compiler->nvcc, cc_compiler->cc, metal_compiler->xcode (#248)

parent d3efd7fc
...@@ -2,18 +2,23 @@ Contrib APIs ...@@ -2,18 +2,23 @@ Contrib APIs
------------ ------------
.. automodule:: tvm.contrib .. automodule:: tvm.contrib
tvm.contrib.nvcc_compiler tvm.contrib.nvcc
~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.nvcc_compiler .. automodule:: tvm.contrib.nvcc
:members:
tvm.contrib.cc
~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.cc
:members: :members:
tvm.contrib.cc_compiler tvm.contrib.xcode
~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.cc_compiler .. automodule:: tvm.contrib.xcode
:members: :members:
tvm.contrib.rpc tvm.contrib.rpc
~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.rpc .. automodule:: tvm.contrib.rpc
:members: :members:
...@@ -22,7 +27,6 @@ tvm.contrib.util ...@@ -22,7 +27,6 @@ tvm.contrib.util
.. automodule:: tvm.contrib.util .. automodule:: tvm.contrib.util
:members: :members:
tvm.contrib.cblas tvm.contrib.cblas
~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.cblas .. automodule:: tvm.contrib.cblas
......
# pylint: disable=invalid-name # pylint: disable=invalid-name
"""Utility to invoke nvcc compiler in the system""" """Utility to invoke nvcc compiler in the system"""
from __future__ import absolute_import as _abs from __future__ import absolute_import as _abs
import os
import sys import sys
import tempfile
import subprocess import subprocess
from . import util
def compile_source(code, target="ptx", arch=None, def compile_cuda(code, target="ptx", arch=None,
options=None, path_target=None): options=None, path_target=None):
"""Compile cuda code with NVCC from env. """Compile cuda code with NVCC from env.
Parameters Parameters
...@@ -32,11 +31,11 @@ def compile_source(code, target="ptx", arch=None, ...@@ -32,11 +31,11 @@ def compile_source(code, target="ptx", arch=None,
cubin : bytearray cubin : bytearray
The bytearray of the cubin The bytearray of the cubin
""" """
temp_dir = tempfile.mkdtemp() temp = util.tempdir()
if target not in ["cubin", "ptx", "fatbin"]: if target not in ["cubin", "ptx", "fatbin"]:
raise ValueError("target must be in cubin, ptx, fatbin") raise ValueError("target must be in cubin, ptx, fatbin")
temp_code = os.path.join(temp_dir, "my_kernel.cu") temp_code = temp.relpath("my_kernel.cu")
temp_target = os.path.join(temp_dir, "my_kernel.%s" % target) temp_target = temp.relpath("my_kernel.%s" % target)
with open(temp_code, "w") as out_file: with open(temp_code, "w") as out_file:
out_file.write(code) out_file.write(code)
...@@ -68,8 +67,4 @@ def compile_source(code, target="ptx", arch=None, ...@@ -68,8 +67,4 @@ def compile_source(code, target="ptx", arch=None,
cubin = None cubin = None
else: else:
cubin = bytearray(open(file_target, "rb").read()) 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 return cubin
...@@ -15,7 +15,7 @@ import socket ...@@ -15,7 +15,7 @@ import socket
import struct import struct
import logging import logging
import multiprocessing import multiprocessing
from . import util, cc_compiler from . import util, cc
from ..module import load as _load_module from ..module import load as _load_module
from .._ffi.function import _init_api, register_func from .._ffi.function import _init_api, register_func
from .._ffi.ndarray import context as _context from .._ffi.ndarray import context as _context
...@@ -39,7 +39,7 @@ def _server_env(): ...@@ -39,7 +39,7 @@ def _server_env():
# Try create a shared library in remote # Try create a shared library in remote
if path.endswith('.o'): if path.endswith('.o'):
logging.info('Create shared library based on %s', path) logging.info('Create shared library based on %s', path)
cc_compiler.create_shared(path + '.so', path) cc.create_shared(path + '.so', path)
path += '.so' path += '.so'
m = _load_module(path) m = _load_module(path)
logging.info("load_module %s", path) logging.info("load_module %s", path)
......
# pylint: disable=invalid-name # 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 from __future__ import absolute_import as _abs
import sys import sys
import subprocess import subprocess
from . import util 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. """Compile metal with CLI tool from env.
Parameters Parameters
...@@ -16,6 +16,9 @@ def compile_source(code, path_target=None): ...@@ -16,6 +16,9 @@ def compile_source(code, path_target=None):
path_target : str, optional path_target : str, optional
Output file. Output file.
sdk : str, optional
The target platform SDK.
Return Return
------ ------
metallib : bytearray metallib : bytearray
...@@ -30,9 +33,9 @@ def compile_source(code, path_target=None): ...@@ -30,9 +33,9 @@ def compile_source(code, path_target=None):
out_file.write(code) out_file.write(code)
file_target = path_target if path_target else temp_target 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] cmd1 += [temp_code, "-o", temp_ir]
cmd2 = ["xcrun", "-sdk", "macosx", "metallib"] cmd2 = ["xcrun", "-sdk", sdk, "metallib"]
cmd2 += [temp_ir, "-o", file_target] cmd2 += [temp_ir, "-o", file_target]
proc = subprocess.Popen( proc = subprocess.Popen(
' '.join(cmd1) + ";" + ' '.join(cmd2), ' '.join(cmd1) + ";" + ' '.join(cmd2),
......
...@@ -4,7 +4,7 @@ from __future__ import absolute_import as _abs ...@@ -4,7 +4,7 @@ from __future__ import absolute_import as _abs
from collections import namedtuple from collections import namedtuple
from ._ffi.function import ModuleBase, _set_class_module from ._ffi.function import ModuleBase, _set_class_module
from ._ffi.function import _init_api 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"]) ProfileResult = namedtuple("ProfileResult", ["mean"])
......
...@@ -56,7 +56,7 @@ struct SockAddr { ...@@ -56,7 +56,7 @@ struct SockAddr {
} }
/*! /*!
* \brief set the address * \brief set the address
* \param url the url of the address * \param host the url of the address
* \param port the port of address * \param port the port of address
*/ */
void Set(const char *host, int port) { void Set(const char *host, int port) {
...@@ -86,7 +86,7 @@ struct SockAddr { ...@@ -86,7 +86,7 @@ struct SockAddr {
&buf[0], buf.length()); &buf[0], buf.length());
#else #else
const char *s = inet_ntop(AF_INET, &addr.sin_addr, const char *s = inet_ntop(AF_INET, &addr.sin_addr,
&buf[0], buf.length()); &buf[0], static_cast<socklen_t>(buf.length()));
#endif #endif
CHECK(s != nullptr) << "cannot decode address"; CHECK(s != nullptr) << "cannot decode address";
std::ostringstream os; std::ostringstream os;
...@@ -138,7 +138,7 @@ class Socket { ...@@ -138,7 +138,7 @@ class Socket {
} }
/*! /*!
* \brief bind the socket to an address * \brief bind the socket to an address
* \param addr * \param addr The address to be binded
*/ */
void Bind(const SockAddr &addr) { void Bind(const SockAddr &addr) {
if (bind(sockfd, reinterpret_cast<const sockaddr*>(&addr.addr), if (bind(sockfd, reinterpret_cast<const sockaddr*>(&addr.addr),
...@@ -342,9 +342,9 @@ class TCPSocket : public Socket { ...@@ -342,9 +342,9 @@ class TCPSocket : public Socket {
} }
/*! /*!
* \brief send data using the 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 len the size of the buffer
* \param flags extra flags * \param flag extra flags
* \return size of data actually sent * \return size of data actually sent
* return -1 if error occurs * return -1 if error occurs
*/ */
...@@ -367,7 +367,7 @@ class TCPSocket : public Socket { ...@@ -367,7 +367,7 @@ class TCPSocket : public Socket {
/*! /*!
* \brief peform block write that will attempt to send all data out * \brief peform block write that will attempt to send all data out
* can still return smaller than request when error occurs * 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 * \param len the size of the buffer
* \return size of data actually sent * \return size of data actually sent
*/ */
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import tvm import tvm
import os import os
import struct import struct
from tvm.contrib import util, cc_compiler as cc, rpc from tvm.contrib import util, cc, rpc
import numpy as np import numpy as np
def test_llvm_add_pipeline(): def test_llvm_add_pipeline():
......
import tvm import tvm
from tvm.contrib import cc_compiler as cc, util from tvm.contrib import cc, util
import ctypes import ctypes
import os import os
import numpy as np import numpy as np
......
...@@ -8,6 +8,8 @@ make doc ...@@ -8,6 +8,8 @@ make doc
jsdoc web/tvm_runtime.js web/README.md || exit -1 jsdoc web/tvm_runtime.js web/README.md || exit -1
mv out docs/_build/html/jsdoc || exit -1 mv out docs/_build/html/jsdoc || exit -1
rm -rf python/tvm/*.pyc python/tvm/*/*.pyc
cd docs cd docs
PYTHONPATH=../python make html || exit -1 PYTHONPATH=../python make html || exit -1
cd _build/html cd _build/html
......
...@@ -3,6 +3,8 @@ export PYTHONPATH=python:apps/extension/python ...@@ -3,6 +3,8 @@ export PYTHONPATH=python:apps/extension/python
export PYTHONPATH=${PYTHONPATH}:apps/graph_executor/python:apps/graph_executor/nnvm/python export PYTHONPATH=${PYTHONPATH}:apps/graph_executor/python:apps/graph_executor/nnvm/python
export LD_LIBRARY_PATH=lib:${LD_LIBRARY_PATH} export LD_LIBRARY_PATH=lib:${LD_LIBRARY_PATH}
rm -rf python/tvm/*.pyc python/tvm/*/*.pyc
# Test TVM # Test TVM
make cython || exit -1 make cython || exit -1
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
export PYTHONPATH=python 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 python -m nose -v tests/python/unittest || exit -1
TVM_FFI=ctypes python3 -m nose -v tests/python/unittest || exit -1 TVM_FFI=ctypes python3 -m nose -v tests/python/unittest || exit -1
......
...@@ -2,7 +2,7 @@ import os ...@@ -2,7 +2,7 @@ import os
import tvm import tvm
import numpy as np import numpy as np
from scipy import signal from scipy import signal
from tvm.contrib import nvcc_compiler from tvm.contrib import nvcc
import topi import topi
from topi.nn.util import get_const_tuple from topi.nn.util import get_const_tuple
...@@ -13,7 +13,7 @@ USE_MANUAL_CODE = False ...@@ -13,7 +13,7 @@ USE_MANUAL_CODE = False
@tvm.register_func @tvm.register_func
def tvm_callback_cuda_compile(code): 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 return ptx
def write_code(code, fname): def write_code(code, fname):
......
"""Example code to do square matrix multiplication.""" """Example code to do square matrix multiplication."""
import tvm import tvm
import os import os
from tvm.contrib import nvcc_compiler from tvm.contrib import nvcc
import numpy as np import numpy as np
TASK="gemm" TASK="gemm"
...@@ -9,7 +9,7 @@ USE_MANUAL_CODE = False ...@@ -9,7 +9,7 @@ USE_MANUAL_CODE = False
@tvm.register_func @tvm.register_func
def tvm_callback_cuda_compile(code): 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 return ptx
def write_code(code, fname): def write_code(code, fname):
......
...@@ -3,7 +3,7 @@ import tvm ...@@ -3,7 +3,7 @@ import tvm
import time import time
import os import os
import argparse import argparse
from tvm.contrib import nvcc_compiler from tvm.contrib import nvcc
import numpy as np import numpy as np
# Quick knobs # Quick knobs
...@@ -17,7 +17,7 @@ UNROLL_WLOAD = True ...@@ -17,7 +17,7 @@ UNROLL_WLOAD = True
@tvm.register_func @tvm.register_func
def tvm_callback_cuda_compile(code): def tvm_callback_cuda_compile(code):
"""Use nvcc compiler for better perf.""" """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 return ptx
def write_code(code, fname): def write_code(code, fname):
......
...@@ -11,7 +11,7 @@ import tvm ...@@ -11,7 +11,7 @@ import tvm
import time import time
import os import os
import argparse import argparse
from tvm.contrib import nvcc_compiler from tvm.contrib import nvcc
import numpy as np import numpy as np
# Quick knobs # Quick knobs
...@@ -24,7 +24,7 @@ SKIP_CHECK = False ...@@ -24,7 +24,7 @@ SKIP_CHECK = False
@tvm.register_func @tvm.register_func
def tvm_callback_cuda_compile(code): def tvm_callback_cuda_compile(code):
"""Use nvcc compiler for better perf.""" """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 return ptx
def write_code(code, fname): def write_code(code, fname):
......
...@@ -175,7 +175,7 @@ print(dev_module.get_source()) ...@@ -175,7 +175,7 @@ print(dev_module.get_source())
# - Then it saves the device module into a ptx file. # - Then it saves the device module into a ptx file.
# - cc.create_shared calls a env compiler(gcc) to create a shared library # - 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 from tvm.contrib import util
temp = util.tempdir() temp = util.tempdir()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment