cornell-zhang / heterocl

HeteroCL: A Multi-Paradigm Programming Infrastructure for Software-Defined Heterogeneous Computing
https://cornell-zhang.github.io/heterocl/
Apache License 2.0
322 stars 92 forks source link

Convert a NumPy array to a HeteroCL array of bitwidth larger than 64 #371

Open zhenkun opened 3 years ago

zhenkun commented 3 years ago
A_ = hcl.asarray(np.zeros((10,)), dtype=hcl.Int(128))

will result in:

TypeError: data type 'i16' not understood

numpy seems to support large integers:

>>> a = numpy.array([2**64 * 10])
>>> a
array([184467440737095516160], dtype=object)
>>> a.dtype
dtype('O')
seanlatias commented 3 years ago

Following are some pointers:

  1. In this file, it shows how NumPy arrays interact with the HeteroCL/TVM arrays. https://github.com/cornell-zhang/heterocl/blob/master/python/heterocl/tvm/_ffi/ndarray.py

  2. More specifically, this function loads NumPy arrays into HeteroCL/TVM. https://github.com/cornell-zhang/heterocl/blob/83a4c11f434b672b82c73d42324f7a75c2ebd56f/python/heterocl/tvm/_ffi/ndarray.py#L157

  3. And this function loads HeteroCL/TVM array into NumPy arrays. https://github.com/cornell-zhang/heterocl/blob/83a4c11f434b672b82c73d42324f7a75c2ebd56f/python/heterocl/tvm/_ffi/ndarray.py#L225

  4. This is where we handle the array data copy. https://github.com/cornell-zhang/heterocl/blob/83a4c11f434b672b82c73d42324f7a75c2ebd56f/tvm/src/runtime/c_runtime_api.cc#L415

So there'd be no problem if we just want to copy the NumPy data into HeteroCL (though we need to know the size to copy first, for sure). The problem is, how do we decode that at the LLVM level.