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
2 changes: 1 addition & 1 deletion src/02hardware/src/devices/nvidia/device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace refactor::hardware {

size_t free, total;
CUDA_ASSERT(cudaMemGetInfo(&free, &total));
auto size = std::min(free, std::max(5ul << 30, total * 4 / 5));
auto size = free * 9 / 10;
cudaDeviceProp prop;
CUDA_ASSERT(cudaGetDeviceProperties(&prop, 0));
size_t alignment = prop.textureAlignment;
Expand Down
16 changes: 15 additions & 1 deletion src/09python_ffi/src/compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,21 @@ namespace refactor::python_ffi {
}

void
Compiler::setInput(size_t index, int dataType, DimVec dims) {
Compiler::setInput(size_t index, pybind11::array data) {
ASSERT(index < _g.internal().topology.globalInputsCount(),
"Input {} not exist", index);

Shape shape(data.ndim(), DimExpr(1));
std::transform(std::execution::unseq,
data.shape(), data.shape() + data.ndim(), shape.begin(),
[](auto const &d) { return DimExpr(d); });
auto ans = Tensor::share(parseNumpyDType(data.dtype()), std::move(shape), {});
std::memcpy(ans->malloc(), data.data(), data.nbytes());
_g.internal().edges[index].tensor = std::move(ans);
}

void
Compiler::setInputInfo(size_t index, int dataType, DimVec dims) {
ASSERT(index < _g.internal().topology.globalInputsCount(),
"Input {} not exist", index);

Expand Down
3 changes: 2 additions & 1 deletion src/09python_ffi/src/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ namespace refactor::python_ffi {
public:
explicit Compiler(frontend::Graph);
void substitute(CStr, int64_t);
void setInput(size_t index, int dataType, DimVec dims);
void setInput(size_t index, pybind11::array);
void setInputInfo(size_t index, int dataType, DimVec dims);
std::unordered_set<std::string> fillEdgeInfo(bool calculate);
Arc<Executor> compileOn(
Arc<hardware::Device> device,
Expand Down
8 changes: 4 additions & 4 deletions src/09python_ffi/src/executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ namespace refactor::python_ffi {
}

void Executor::setInput(count_t i, pybind11::array data) {
i = _stream.graph().topology.globalInputs().at(i);
i = _graph.internal().contiguous().topology.globalInputs().at(i);

auto const &tensor = *_graph.internal().contiguous().edges[i].tensor;
ASSERT(tensor.bytesSize() == static_cast<size_t>(data.nbytes()), "input size mismatch");
_stream.setData(i, data.data(), data.nbytes());
}

void Executor::setInputBlob(count_t i, Arc<hardware::Device::Blob> blob) {
i = _stream.graph().topology.globalInputs().at(i);
i = _graph.internal().contiguous().topology.globalInputs().at(i);

auto const &tensor = *_graph.internal().contiguous().edges[i].tensor;
ASSERT(tensor.bytesSize() == blob->size(), "input size mismatch");
_stream.setData(i, std::move(blob));
}

auto Executor::getOutput(count_t i) const -> pybind11::array {
i = _stream.graph().topology.globalOutputs().at(i);
i = _graph.internal().contiguous().topology.globalOutputs().at(i);

auto const &tensor = *_graph.internal().contiguous().edges[i].tensor;
auto ans = pybind11::array(buildNumpyDType(tensor.dataType), std::move(tensor.shape));
Expand All @@ -58,7 +58,7 @@ namespace refactor::python_ffi {
}

auto Executor::getOutputBlob(count_t i) const -> Arc<hardware::Device::Blob> {
i = _stream.graph().topology.globalOutputs().at(i);
i = _graph.internal().contiguous().topology.globalOutputs().at(i);

return _stream.getData(i);
}
Expand Down
1 change: 1 addition & 0 deletions src/09python_ffi/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace refactor::python_ffi {
py::class_<Compiler , Arc<Compiler>>(m, "Compiler" )
.def("substitute" , &Compiler::substitute , return_::automatic )
.def("set_input" , &Compiler::setInput , return_::automatic )
.def("set_input_info" , &Compiler::setInputInfo , return_::automatic )
.def("check_variables" , &Compiler::fillEdgeInfo , return_::move )
.def("zero_inputs" , &Compiler::zeroInputs , return_::move )
.def("get_tensor" , &Compiler::getTensor , return_::move )
Expand Down