Skip to content
Closed
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
7 changes: 7 additions & 0 deletions include/tvm/runtime/c_runtime_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
TVM_EXTERN_C {
/*! \brief type of array index. */
typedef int64_t tvm_index_t;

/*! \brief Extension device types in TVM */
typedef enum {
/*! \brief Simulated on board RAM */
kVPI = 9
} TVMDeviceExtType;

/*!
* \brief The type code in TVMType
* \note TVMType is used in two places.
Expand Down
2 changes: 2 additions & 0 deletions include/tvm/runtime/packed_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ class TVMArgValue : public TVMPODValue_ {
return value_.v_type;
}
operator PackedFunc() const {
if (type_code_ == kNull) return PackedFunc();
TVM_CHECK_TYPE_CODE(type_code_, kFuncHandle);
return *ptr<PackedFunc>();
}
Expand Down Expand Up @@ -350,6 +351,7 @@ class TVMRetValue : public TVMPODValue_ {
return value_.v_type;
}
operator PackedFunc() const {
if (type_code_ == kNull) return PackedFunc();
TVM_CHECK_TYPE_CODE(type_code_, kFuncHandle);
return *ptr<PackedFunc>();
}
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from . import module

from . import ndarray as nd
from .ndarray import cpu, gpu, opencl, cl
from .ndarray import cpu, gpu, opencl, cl, vpi

from ._base import TVMError
from .api import *
Expand Down
13 changes: 12 additions & 1 deletion python/tvm/_ctypes/_ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class TVMContext(ctypes.Structure):
MASK2STR = {
1 : 'cpu',
2 : 'gpu',
4 : 'opencl'
4 : 'opencl',
9 : 'vpi'
}
def __init__(self, device_id, device_type):
super(TVMContext, self).__init__()
Expand Down Expand Up @@ -76,6 +77,16 @@ def opencl(dev_id=0):
"""
return TVMContext(dev_id, 4)

def vpi(dev_id=0):
"""Construct a VPI simulated device

Parameters
----------
dev_id : int, optional
The integer device id
"""
return TVMContext(dev_id, 9)


def numpyasarray(np_data):
"""Return a TVMArray representation of a numpy array.
Expand Down
14 changes: 13 additions & 1 deletion python/tvm/addon/verilog.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __init__(self, handle):
super(VPISession, self).__init__(handle)
self.proc = None
self.execpath = None
self.yield_callbacks = []

def __del__(self):
self.proc.kill()
Expand Down Expand Up @@ -47,6 +48,8 @@ def __getattr__(self, name):

def yield_until_posedge(self):
"""Yield until next posedge"""
for f in self.yield_callbacks:
f()
return _api_internal._vpi_SessYield(self)

def shutdown(self):
Expand Down Expand Up @@ -222,7 +225,16 @@ def session(file_name):
env['TVM_HREAD_PIPE'] = str(read_host)
env['TVM_HWRITE_PIPE'] = str(write_host)

proc = subprocess.Popen(cmd, env=env, close_fds=False)
try:
# close_fds does not work well for all python3
# Use pass_fds instead.
# pylint: disable=unexpected-keyword-arg
pass_fds = (read_device, write_device, read_host, write_host)
proc = subprocess.Popen(cmd, pass_fds=pass_fds, env=env)
except TypeError:
# This is effective for python2
proc = subprocess.Popen(cmd, close_fds=False, env=env)

# close device side pipe
os.close(read_device)
os.close(write_device)
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as _np

from ._ctypes._ndarray import TVMContext, TVMType, NDArrayBase
from ._ctypes._ndarray import cpu, gpu, opencl, empty, sync
from ._ctypes._ndarray import cpu, gpu, opencl, vpi, empty, sync
from ._ctypes._ndarray import _init_ndarray_module
from ._ctypes._function import Function

Expand Down
Loading