diff options
| author | Haocong Luo <richardluo723@gmail.com> | 2026-06-01 20:04:48 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-06-01 20:04:48 +0200 |
| commit | ee802e6c310a2248c74d341d53d57d5948df6468 (patch) | |
| tree | c4cc1654e50cee95e6dbc842c32be3fd374e3f73 | |
| parent | 81860f141ca3103663be80279b3dff7f34cd8fc2 (diff) | |
| parent | a22b6dbc4d93a568d608995e02f5e84d34461a1c (diff) | |
| download | dram-bender-ee802e6c310a2248c74d341d53d57d5948df6468.tar.gz | |
Merge pull request #13 from gussmith23/gus/fix-pybind-gitlink
Misc. fixes to pybind11 bindings
| m--------- | sources/api/ext/pybind11 | 0 | ||||
| -rw-r--r-- | sources/api/platform.h | 2 | ||||
| -rw-r--r-- | sources/api/pySoftMC/Makefile | 2 | ||||
| -rw-r--r-- | sources/api/pySoftMC/README.md | 24 | ||||
| -rw-r--r-- | sources/api/pySoftMC/pySoftMC.cpp | 15 | ||||
| -rw-r--r-- | sources/api/pySoftMC/setup.py | 22 |
6 files changed, 56 insertions, 9 deletions
diff --git a/sources/api/ext/pybind11 b/sources/api/ext/pybind11 new file mode 160000 +Subproject 6079989cf70555d213add249cfb36dad1451979 diff --git a/sources/api/platform.h b/sources/api/platform.h index f79e319..23a3a47 100644 --- a/sources/api/platform.h +++ b/sources/api/platform.h @@ -4,7 +4,7 @@ #include <boost/lockfree/spsc_queue.hpp> #ifdef PYSMC -#include "ext/pybind11/include/pybind11/pybind11.h" +#include <pybind11/pybind11.h> namespace py = pybind11; #endif diff --git a/sources/api/pySoftMC/Makefile b/sources/api/pySoftMC/Makefile index 771df53..0c1d241 100644 --- a/sources/api/pySoftMC/Makefile +++ b/sources/api/pySoftMC/Makefile @@ -8,7 +8,7 @@ program_CXX_OBJS := ${program_CXX_SRCS:.cpp=.o} program_CXX_OBJS := ${program_CXX_OBJS:.c=.o} program_OBJS := $(program_CXX_OBJS) -program_INCLUDE_DIRS := . .. /usr/include/python${python_version} ../ext/pybind11/include/pybind11 +program_INCLUDE_DIRS := . .. /usr/include/python${python_version} ../ext/pybind11/include program_LIBRARY_DIRS := program_LIBRARIES := python${python_version} CPPFLAGS += -g -std=c++14 -pthread -O3 -fPIC -Wall diff --git a/sources/api/pySoftMC/README.md b/sources/api/pySoftMC/README.md new file mode 100644 index 0000000..f59c30f --- /dev/null +++ b/sources/api/pySoftMC/README.md @@ -0,0 +1,24 @@ +# pySoftMC + +Python bindings for the DRAM Bender API via pybind11. + +## Building with `make` + +Requires the pybind11 submodule (`git clone --recursive` or `git submodule update --init --recursive`) and a system Python installation with headers at `/usr/include/python3.X`. + +``` +make +``` + +## Building with `setup.py` + +A more portable alternative that works with virtual environments and pyenv. +Requires pybind11 installed in the active Python environment (`pip install pybind11`); +does not require the pybind11 git submodule. + +``` +pip install pybind11 +python3 setup.py build_ext --inplace +``` + +This uses the active Python interpreter's own build machinery, so it works regardless of where Python is installed. diff --git a/sources/api/pySoftMC/pySoftMC.cpp b/sources/api/pySoftMC/pySoftMC.cpp index 992d9a5..fe81ff2 100644 --- a/sources/api/pySoftMC/pySoftMC.cpp +++ b/sources/api/pySoftMC/pySoftMC.cpp @@ -2,7 +2,7 @@ #include "instruction.h" #include "prog.h" -#include "ext/pybind11/include/pybind11/pybind11.h" +#include <pybind11/pybind11.h> namespace py = pybind11; PYBIND11_MODULE(pySoftMC, m) @@ -12,7 +12,7 @@ PYBIND11_MODULE(pySoftMC, m) .value("READ", PC_TYPE::READ) .value("PRE", PC_TYPE::PRE) .value("ACT", PC_TYPE::ACT) - .value("ZQ", PC_TYPE::ZQ) + .value("SEL_CH", PC_TYPE::SEL_CH) .value("REF", PC_TYPE::REF) .value("CYC", PC_TYPE::CYC) .export_values(); @@ -45,12 +45,12 @@ PYBIND11_MODULE(pySoftMC, m) m.def("SMC_WRITE", &SMC_WRITE, py::arg("bar"), py::arg("ibar"), py::arg("car"), py::arg("icar"), py::arg("BL4"), py::arg("ap")); m.def("SMC_READ", &SMC_READ, py::arg("bar"), py::arg("ibar"), py::arg("car"), py::arg("icar"), py::arg("BL4"), py::arg("ap")); - m.def("SMC_PRE", &SMC_PRE, py::arg("bar"), py::arg("ibar"), py::arg("pall")); - m.def("SMC_ACT", &SMC_ACT, py::arg("bar"), py::arg("ibar"), py::arg("rar"), py::arg("irar")); + m.def("SMC_PRE", &SMC_PRE, py::arg("bar"), py::arg("ibar"), py::arg("pall"), py::arg("rank") = 0); + m.def("SMC_ACT", &SMC_ACT, py::arg("bar"), py::arg("ibar"), py::arg("rar"), py::arg("irar"), py::arg("rank") = 0); + m.def("SMC_SEL_CH", &SMC_SEL_CH, py::arg("channel"), py::arg("pseudo_channel") = 0); - m.def("SMC_ZQ", &SMC_ZQ); - m.def("SMC_REF", &SMC_REF); - m.def("SMC_NOP", &SMC_NOP); + m.def("SMC_REF", &SMC_REF, py::arg("rank") = 0); + m.def("SMC_NOP", &SMC_NOP, py::arg("rank") = 0); m.def("SMC_SRE", &SMC_SRE); m.def("SMC_SRX", &SMC_SRX); @@ -58,6 +58,7 @@ PYBIND11_MODULE(pySoftMC, m) py::class_<SoftMCPlatform>(m, "SoftMCPlatform") .def(py::init()) + .def(py::init<int>(), py::arg("dimm_select")) .def("init", &SoftMCPlatform::init) .def("reset_fpga", &SoftMCPlatform::reset_fpga) .def("execute", &SoftMCPlatform::execute, py::arg("program")) diff --git a/sources/api/pySoftMC/setup.py b/sources/api/pySoftMC/setup.py new file mode 100644 index 0000000..b962937 --- /dev/null +++ b/sources/api/pySoftMC/setup.py @@ -0,0 +1,22 @@ +from setuptools import setup, Extension +import os, pybind11 + +here = os.path.dirname(os.path.abspath(__file__)) +api_dir = os.path.join(here, "..") +pybind11_include = pybind11.get_include() + +ext = Extension( + "pySoftMC", + sources=[ + os.path.join(api_dir, "board.cpp"), + os.path.join(api_dir, "instruction.cpp"), + os.path.join(api_dir, "platform.cpp"), + os.path.join(api_dir, "prog.cpp"), + os.path.join(here, "pySoftMC.cpp"), + ], + include_dirs=[here, api_dir, pybind11_include], + language="c++", + extra_compile_args=["-std=c++14", "-pthread", "-O3", "-DPYSMC"], +) + +setup(name="pySoftMC", ext_modules=[ext]) |
