From a685848ccb821058ce48e1aaad7ad93d2bdcdf9e Mon Sep 17 00:00:00 2001 From: Gus Smith Date: Fri, 29 May 2026 09:46:42 -0700 Subject: Add pybind11 gitlink --- sources/api/ext/pybind11 | 1 + 1 file changed, 1 insertion(+) create mode 160000 sources/api/ext/pybind11 diff --git a/sources/api/ext/pybind11 b/sources/api/ext/pybind11 new file mode 160000 index 0000000..6079989 --- /dev/null +++ b/sources/api/ext/pybind11 @@ -0,0 +1 @@ +Subproject commit 6079989cf70555d213add249cfb36dad14519791 -- cgit v1.2.3 From 8c0c60187088b6841be7b1dbaf335eea2bd46468 Mon Sep 17 00:00:00 2001 From: Gus Smith Date: Fri, 29 May 2026 09:57:50 -0700 Subject: Fix include path --- sources/api/pySoftMC/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 -- cgit v1.2.3 From 499d389779f7881054ecd691db7ebea49eb5a492 Mon Sep 17 00:00:00 2001 From: Gus Smith Date: Fri, 29 May 2026 10:01:23 -0700 Subject: Improve makefile portability --- sources/api/pySoftMC/Makefile | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/sources/api/pySoftMC/Makefile b/sources/api/pySoftMC/Makefile index 0c1d241..b03b1a9 100644 --- a/sources/api/pySoftMC/Makefile +++ b/sources/api/pySoftMC/Makefile @@ -1,21 +1,19 @@ -# https://stackoverflow.com/questions/4933285/how-to-determine-python-version-in-makefile -python_version_full := $(wordlist 2,4,$(subst ., ,$(shell python3 --version 2>&1))) -python_version := $(word 1,${python_version_full}).$(word 2,${python_version_full}) - program_NAME := pySoftMC program_CXX_SRCS := $(wildcard ../*.c) $(wildcard ../*.cpp) ./pySoftMC.cpp 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 +python_INCLUDE_FLAGS := $(shell python3-config --includes) +program_INCLUDE_DIRS := . .. ../ext/pybind11/include program_LIBRARY_DIRS := -program_LIBRARIES := python${python_version} +program_LIBRARIES := CPPFLAGS += -g -std=c++14 -pthread -O3 -fPIC -Wall -CPPFLAGS += $(foreach includedir,$(program_INCLUDE_DIRS),-I$(includedir)) -DPYSMC +CPPFLAGS += $(foreach includedir,$(program_INCLUDE_DIRS),-I$(includedir)) $(python_INCLUDE_FLAGS) -DPYSMC LDFLAGS += $(foreach librarydir,$(program_LIBRARY_DIRS),-L$(librarydir)) LDFLAGS += $(foreach library,$(program_LIBRARIES),-l$(library)) +LDFLAGS += $(shell python3-config --ldflags --embed 2>/dev/null || python3-config --ldflags) SHARED_LIB_FLAGS := -shared -fPIC -- cgit v1.2.3 From 45dc9b808298c237af404e45111833526e8151c0 Mon Sep 17 00:00:00 2001 From: Gus Smith Date: Fri, 29 May 2026 10:08:13 -0700 Subject: Update bindings --- sources/api/pySoftMC/pySoftMC.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sources/api/pySoftMC/pySoftMC.cpp b/sources/api/pySoftMC/pySoftMC.cpp index 992d9a5..b7a53bd 100644 --- a/sources/api/pySoftMC/pySoftMC.cpp +++ b/sources/api/pySoftMC/pySoftMC.cpp @@ -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,10 +45,10 @@ 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_SRE", &SMC_SRE); -- cgit v1.2.3 From ac29b5a73986bf6c9413751078c9a234842bcbe4 Mon Sep 17 00:00:00 2001 From: Gus Smith Date: Fri, 29 May 2026 10:26:32 -0700 Subject: Try a different approach via setup.py --- sources/api/pySoftMC/Makefile | 16 +++++++--------- sources/api/pySoftMC/setup.py | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 sources/api/pySoftMC/setup.py diff --git a/sources/api/pySoftMC/Makefile b/sources/api/pySoftMC/Makefile index b03b1a9..f7620f4 100644 --- a/sources/api/pySoftMC/Makefile +++ b/sources/api/pySoftMC/Makefile @@ -4,16 +4,14 @@ program_CXX_OBJS := ${program_CXX_SRCS:.cpp=.o} program_CXX_OBJS := ${program_CXX_OBJS:.c=.o} program_OBJS := $(program_CXX_OBJS) -python_INCLUDE_FLAGS := $(shell python3-config --includes) +PYTHON_INCLUDES ?= $(shell python3-config --includes) +PYTHON_LDFLAGS ?= $(shell python3-config --ldflags --embed 2>/dev/null || python3-config --ldflags) +PYTHON_EXT_SUFFIX ?= $(PYTHON_EXT_SUFFIX) program_INCLUDE_DIRS := . .. ../ext/pybind11/include -program_LIBRARY_DIRS := -program_LIBRARIES := CPPFLAGS += -g -std=c++14 -pthread -O3 -fPIC -Wall -CPPFLAGS += $(foreach includedir,$(program_INCLUDE_DIRS),-I$(includedir)) $(python_INCLUDE_FLAGS) -DPYSMC -LDFLAGS += $(foreach librarydir,$(program_LIBRARY_DIRS),-L$(librarydir)) -LDFLAGS += $(foreach library,$(program_LIBRARIES),-l$(library)) -LDFLAGS += $(shell python3-config --ldflags --embed 2>/dev/null || python3-config --ldflags) +CPPFLAGS += $(foreach includedir,$(program_INCLUDE_DIRS),-I$(includedir)) $(PYTHON_INCLUDES) -DPYSMC +LDFLAGS += $(PYTHON_LDFLAGS) SHARED_LIB_FLAGS := -shared -fPIC @@ -25,10 +23,10 @@ all: $(program_NAME) @- $(RM) $(program_OBJS) $(program_NAME): $(program_OBJS) - $(CC) $(CPPFLAGS) ${SHARED_LIB_FLAGS} $(program_OBJS) -o $(program_NAME)$(shell python3-config --extension-suffix) $(LDFLAGS) + $(CC) $(CPPFLAGS) ${SHARED_LIB_FLAGS} $(program_OBJS) -o $(program_NAME)$(PYTHON_EXT_SUFFIX) $(LDFLAGS) clean: - @- $(RM) $(program_NAME)$(shell python3-config --extension-suffix) + @- $(RM) $(program_NAME)$(PYTHON_EXT_SUFFIX) @- $(RM) $(program_OBJS) distclean: clean diff --git a/sources/api/pySoftMC/setup.py b/sources/api/pySoftMC/setup.py new file mode 100644 index 0000000..c353396 --- /dev/null +++ b/sources/api/pySoftMC/setup.py @@ -0,0 +1,22 @@ +from setuptools import setup, Extension +import os + +here = os.path.dirname(os.path.abspath(__file__)) +api_dir = os.path.join(here, "..") +pybind11_include = os.path.join(here, "../ext/pybind11/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]) -- cgit v1.2.3 From ec9d9e6e7fbe7623d27069789a6a0380a2feb1c2 Mon Sep 17 00:00:00 2001 From: Gus Smith Date: Fri, 29 May 2026 10:33:07 -0700 Subject: Undo some changes we're no longer using --- sources/api/pySoftMC/Makefile | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/sources/api/pySoftMC/Makefile b/sources/api/pySoftMC/Makefile index f7620f4..76f8f6e 100644 --- a/sources/api/pySoftMC/Makefile +++ b/sources/api/pySoftMC/Makefile @@ -1,19 +1,23 @@ +# https://stackoverflow.com/questions/4933285/how-to-determine-python-version-in-makefile +python_version_full := $(wordlist 2,4,$(subst ., ,$(shell python3 --version 2>&1))) +python_version := $(word 1,${python_version_full}).$(word 2,${python_version_full}) + program_NAME := pySoftMC program_CXX_SRCS := $(wildcard ../*.c) $(wildcard ../*.cpp) ./pySoftMC.cpp program_CXX_OBJS := ${program_CXX_SRCS:.cpp=.o} program_CXX_OBJS := ${program_CXX_OBJS:.c=.o} program_OBJS := $(program_CXX_OBJS) -PYTHON_INCLUDES ?= $(shell python3-config --includes) -PYTHON_LDFLAGS ?= $(shell python3-config --ldflags --embed 2>/dev/null || python3-config --ldflags) -PYTHON_EXT_SUFFIX ?= $(PYTHON_EXT_SUFFIX) -program_INCLUDE_DIRS := . .. ../ext/pybind11/include +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 -CPPFLAGS += $(foreach includedir,$(program_INCLUDE_DIRS),-I$(includedir)) $(PYTHON_INCLUDES) -DPYSMC -LDFLAGS += $(PYTHON_LDFLAGS) +CPPFLAGS += $(foreach includedir,$(program_INCLUDE_DIRS),-I$(includedir)) -DPYSMC +LDFLAGS += $(foreach librarydir,$(program_LIBRARY_DIRS),-L$(librarydir)) +LDFLAGS += $(foreach library,$(program_LIBRARIES),-l$(library)) -SHARED_LIB_FLAGS := -shared -fPIC +SHARED_LIB_FLAGS := -shared -fPIC CC=g++ @@ -23,10 +27,10 @@ all: $(program_NAME) @- $(RM) $(program_OBJS) $(program_NAME): $(program_OBJS) - $(CC) $(CPPFLAGS) ${SHARED_LIB_FLAGS} $(program_OBJS) -o $(program_NAME)$(PYTHON_EXT_SUFFIX) $(LDFLAGS) + $(CC) $(CPPFLAGS) ${SHARED_LIB_FLAGS} $(program_OBJS) -o $(program_NAME)$(shell python3-config --extension-suffix) $(LDFLAGS) clean: - @- $(RM) $(program_NAME)$(PYTHON_EXT_SUFFIX) + @- $(RM) $(program_NAME)$(shell python3-config --extension-suffix) @- $(RM) $(program_OBJS) distclean: clean -- cgit v1.2.3 From 307d3a98c1bc83ed4dbcd8156d845d11ae3eaa27 Mon Sep 17 00:00:00 2001 From: Gus Smith Date: Fri, 29 May 2026 10:34:10 -0700 Subject: Add readme --- sources/api/pySoftMC/README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 sources/api/pySoftMC/README.md diff --git a/sources/api/pySoftMC/README.md b/sources/api/pySoftMC/README.md new file mode 100644 index 0000000..3565d46 --- /dev/null +++ b/sources/api/pySoftMC/README.md @@ -0,0 +1,21 @@ +# 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: + +``` +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. -- cgit v1.2.3 From a0539f79a130abdd1ebc4d59e083aa569061d22a Mon Sep 17 00:00:00 2001 From: Gus Smith Date: Fri, 29 May 2026 10:37:52 -0700 Subject: Add back whitespace --- sources/api/pySoftMC/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/api/pySoftMC/Makefile b/sources/api/pySoftMC/Makefile index 76f8f6e..0c1d241 100644 --- a/sources/api/pySoftMC/Makefile +++ b/sources/api/pySoftMC/Makefile @@ -17,7 +17,7 @@ CPPFLAGS += $(foreach includedir,$(program_INCLUDE_DIRS),-I$(includedir)) -DPYSM LDFLAGS += $(foreach librarydir,$(program_LIBRARY_DIRS),-L$(librarydir)) LDFLAGS += $(foreach library,$(program_LIBRARIES),-l$(library)) -SHARED_LIB_FLAGS := -shared -fPIC +SHARED_LIB_FLAGS := -shared -fPIC CC=g++ -- cgit v1.2.3 From db0dc94d8a3161333b21636aacdfb9ce9284a16b Mon Sep 17 00:00:00 2001 From: Gus Smith Date: Fri, 29 May 2026 10:38:26 -0700 Subject: Don't use pybind in submod --- sources/api/pySoftMC/README.md | 5 ++++- sources/api/pySoftMC/setup.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/sources/api/pySoftMC/README.md b/sources/api/pySoftMC/README.md index 3565d46..f59c30f 100644 --- a/sources/api/pySoftMC/README.md +++ b/sources/api/pySoftMC/README.md @@ -12,9 +12,12 @@ make ## Building with `setup.py` -A more portable alternative that works with virtual environments and pyenv: +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 ``` diff --git a/sources/api/pySoftMC/setup.py b/sources/api/pySoftMC/setup.py index c353396..b962937 100644 --- a/sources/api/pySoftMC/setup.py +++ b/sources/api/pySoftMC/setup.py @@ -1,9 +1,9 @@ from setuptools import setup, Extension -import os +import os, pybind11 here = os.path.dirname(os.path.abspath(__file__)) api_dir = os.path.join(here, "..") -pybind11_include = os.path.join(here, "../ext/pybind11/include") +pybind11_include = pybind11.get_include() ext = Extension( "pySoftMC", -- cgit v1.2.3 From d5fe22de89fa904c7bf19320e348258d678142a3 Mon Sep 17 00:00:00 2001 From: Gus Smith Date: Fri, 29 May 2026 11:03:47 -0700 Subject: Add constructor --- sources/api/pySoftMC/pySoftMC.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/sources/api/pySoftMC/pySoftMC.cpp b/sources/api/pySoftMC/pySoftMC.cpp index b7a53bd..6f01620 100644 --- a/sources/api/pySoftMC/pySoftMC.cpp +++ b/sources/api/pySoftMC/pySoftMC.cpp @@ -58,6 +58,7 @@ PYBIND11_MODULE(pySoftMC, m) py::class_(m, "SoftMCPlatform") .def(py::init()) + .def(py::init(), py::arg("dimm_select")) .def("init", &SoftMCPlatform::init) .def("reset_fpga", &SoftMCPlatform::reset_fpga) .def("execute", &SoftMCPlatform::execute, py::arg("program")) -- cgit v1.2.3 From 47f9b1a862ca15a2e10af56456e3c7ec52014db2 Mon Sep 17 00:00:00 2001 From: Gus Smith Date: Fri, 29 May 2026 11:11:40 -0700 Subject: Use system include for pybind --- sources/api/platform.h | 2 +- sources/api/pySoftMC/pySoftMC.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 #ifdef PYSMC -#include "ext/pybind11/include/pybind11/pybind11.h" +#include namespace py = pybind11; #endif diff --git a/sources/api/pySoftMC/pySoftMC.cpp b/sources/api/pySoftMC/pySoftMC.cpp index 6f01620..f8be72e 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 namespace py = pybind11; PYBIND11_MODULE(pySoftMC, m) -- cgit v1.2.3 From a22b6dbc4d93a568d608995e02f5e84d34461a1c Mon Sep 17 00:00:00 2001 From: Gus Smith Date: Fri, 29 May 2026 11:38:11 -0700 Subject: Update bindings --- sources/api/pySoftMC/pySoftMC.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sources/api/pySoftMC/pySoftMC.cpp b/sources/api/pySoftMC/pySoftMC.cpp index f8be72e..fe81ff2 100644 --- a/sources/api/pySoftMC/pySoftMC.cpp +++ b/sources/api/pySoftMC/pySoftMC.cpp @@ -49,8 +49,8 @@ PYBIND11_MODULE(pySoftMC, m) 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_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); -- cgit v1.2.3