Skip to content

Commit 6447d85

Browse files
authored
Merge pull request #75 from junjihashimoto/fix/pybind
Fix pybind
2 parents 7dc064c + 89f9097 commit 6447d85

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

bindings/haskell/gpu-cpp.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ library
2626
hs-source-dirs: src
2727
default-language: Haskell2010
2828
ghc-options: -optcxx-std=c++17
29-
extra-libraries: dawn
29+
extra-libraries: webgpu_dawn
3030

3131
executable gpu-cpp
3232
import: warnings

bindings/python/Makefile

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ else
1010
STDLIB := -stdlib=libc++
1111
endif
1212

13-
FLAGS=-shared -fPIC -std=c++17 $(STDLIB) -I$(GPUCPP) -I$(GPUCPP)/third_party/headers -L$(GPUCPP)/third_party/lib -ldawn \
13+
FLAGS=-shared -fPIC -std=c++17 $(STDLIB) -I$(GPUCPP) -I$(GPUCPP)/third_party/headers -L$(GPUCPP)/third_party/lib -lwebgpu_dawn \
1414
`python3 -m pybind11 --includes` \
15-
`python3-config --include --ldflags --embed`
15+
`python3-config --includes --ldflags`
1616

1717
SUFFIX=$(shell $(PYTHON)-config --extension-suffix)
1818

1919
gpu_cpp$(SUFFIX): gpu_cpp.cpp
2020
$(CXX) $(FLAGS) -o $@ $<
21-
install_name_tool -change @rpath/libdawn.dylib $(LIBDIR)/libdawn.dylib gpu_cpp$(SUFFIX)
2221

2322
test: test_gpu_cpp.py gpu_cpp$(SUFFIX)
2423
$(PYTHON) test_gpu_cpp.py

bindings/python/gpu_cpp.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ KernelCode* py_createKernelCode(const std::string &pData, size_t workgroupSize,
4040
return new KernelCode(pData, workgroupSize, (NumType)precision);
4141
}
4242

43-
Kernel* py_createKernel(Context *ctx, const KernelCode *code,
43+
Kernel py_createKernel(Context *ctx, const KernelCode *code,
4444
// const Tensor *dataBindings, size_t numTensors,
4545
const py::list& dataBindings_py,
4646
// const size_t *viewOffsets,
@@ -54,7 +54,7 @@ Kernel* py_createKernel(Context *ctx, const KernelCode *code,
5454
for (auto item : viewOffsets_py) {
5555
viewOffsets.push_back(item.cast<size_t>());
5656
}
57-
return new Kernel(createKernel(*ctx, *code, bindings.data(), bindings.size(), viewOffsets.data(), vector_to_shape(totalWorkgroups)));
57+
return createKernel(*ctx, *code, bindings.data(), bindings.size(), viewOffsets.data(), vector_to_shape(totalWorkgroups));
5858
}
5959

6060
Tensor* py_createTensor(Context *ctx, const std::vector<int> &dims, int dtype) {
@@ -82,9 +82,9 @@ struct GpuAsync {
8282
}
8383
};
8484

85-
GpuAsync* py_dispatchKernel(Context *ctx, Kernel *kernel) {
85+
GpuAsync* py_dispatchKernel(Context *ctx, Kernel kernel) {
8686
auto async = new GpuAsync();
87-
dispatchKernel(*ctx, *kernel, async->promise);
87+
dispatchKernel(*ctx, kernel, async->promise);
8888
return async;
8989
}
9090

@@ -96,12 +96,12 @@ PYBIND11_MODULE(gpu_cpp, m) {
9696
m.doc() = "gpu.cpp plugin";
9797
py::class_<Context>(m, "Context");
9898
py::class_<Tensor>(m, "Tensor");
99-
py::class_<Kernel>(m, "Kernel");
99+
py::class_<RawKernel, std::shared_ptr<RawKernel>>(m, "Kernel");
100100
py::class_<KernelCode>(m, "KernelCode");
101101
py::class_<GpuAsync>(m, "GpuAsync");
102102
m.def("create_context", &py_createContext, py::return_value_policy::take_ownership);
103103
m.def("create_tensor", &py_createTensor, py::return_value_policy::take_ownership);
104-
m.def("create_kernel", &py_createKernel, py::return_value_policy::take_ownership);
104+
m.def("create_kernel", &py_createKernel);
105105
m.def("create_kernel_code", &py_createKernelCode, py::return_value_policy::take_ownership);
106106
m.def("dispatch_kernel", &py_dispatchKernel, py::return_value_policy::take_ownership);
107107
m.def("wait", &py_wait, "Wait for GPU");

0 commit comments

Comments
 (0)