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
------------
.. 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:
......@@ -22,7 +27,6 @@ tvm.contrib.util
.. automodule:: tvm.contrib.util
:members:
tvm.contrib.cblas
~~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.cblas
......
# 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
......@@ -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)
......@@ -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
......@@ -15,7 +15,7 @@ import socket
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
......@@ -39,7 +39,7 @@ def _server_env():
# 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)
......
# 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
......@@ -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
......@@ -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),
......
......@@ -4,7 +4,7 @@ from __future__ import absolute_import as _abs
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"])
......
......@@ -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) {
......@@ -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;
......@@ -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),
......@@ -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
*/
......@@ -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
*/
......
......@@ -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():
......
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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -2,7 +2,7 @@ import os
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
......@@ -13,7 +13,7 @@ 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):
......
"""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"
......@@ -9,7 +9,7 @@ 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):
......
......@@ -3,7 +3,7 @@ import tvm
import time
import os
import argparse
from tvm.contrib import nvcc_compiler
from tvm.contrib import nvcc
import numpy as np
# Quick knobs
......@@ -17,7 +17,7 @@ UNROLL_WLOAD = True
@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):
......
......@@ -11,7 +11,7 @@ import tvm
import time
import os
import argparse
from tvm.contrib import nvcc_compiler
from tvm.contrib import nvcc
import numpy as np
# Quick knobs
......@@ -24,7 +24,7 @@ SKIP_CHECK = False
@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):
......
......@@ -175,7 +175,7 @@ print(dev_module.get_source())
# - 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()
......
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