From d1bf263e0719e9d9067a1edf8642cf38b0c0a6cb Mon Sep 17 00:00:00 2001 From: koubaa Date: Tue, 10 Dec 2024 09:33:15 -0600 Subject: [PATCH 01/10] Add more information about device to the python bindings Signed-off-by: koubaa --- python/src/main.cpp | 8 +++++++- python/src/utils.hpp | 14 ++++++++++++++ src/Manager.cpp | 6 ++++++ src/include/kompute/Manager.hpp | 8 ++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/python/src/main.cpp b/python/src/main.cpp index 3bddce88..94c1f4b2 100644 --- a/python/src/main.cpp +++ b/python/src/main.cpp @@ -733,7 +733,13 @@ PYBIND11_MODULE(kp, m) return kp::py::vkPropertiesToDict(properties); }, - "Return a dict containing information about the device"); + "Return a dict containing information about the device") + .def( + "get_device_features", + [](kp::Manager& self) { + return kp::py::vkFeaturesToDict(self.getDeviceFeatures()); + }, + "Return a dict containing information about the device features"); auto atexit = py::module_::import("atexit"); atexit.attr("register")(py::cpp_function([]() { diff --git a/python/src/utils.hpp b/python/src/utils.hpp index 69cd2a65..4b2e6108 100644 --- a/python/src/utils.hpp +++ b/python/src/utils.hpp @@ -23,10 +23,24 @@ vkPropertiesToDict(const vk::PhysicalDeviceProperties& properties) pybind11::make_tuple(properties.limits.maxComputeWorkGroupSize[0], properties.limits.maxComputeWorkGroupSize[1], properties.limits.maxComputeWorkGroupSize[2]), + "max_push_constants_size"_a = + properties.limits.maxPushConstantsSize, "timestamps_supported"_a = (bool)properties.limits.timestampComputeAndGraphics); return pyDict; } + +static pybind11::dict +vkFeaturesToDict(const vk::PhysicalDeviceFeatures& features) +{ + pybind11::dict pyDict( + "robust_buffer_access"_a = (bool)features.robustBufferAccess, + "shader_float64"_a = (bool)features.shaderFloat64, + "shader_int64"_a = (bool)features.shaderInt64, + "shader_int16"_a = (bool)features.shaderInt16 + ); + return pyDict; +} } } diff --git a/src/Manager.cpp b/src/Manager.cpp index 32577db1..4086c4af 100644 --- a/src/Manager.cpp +++ b/src/Manager.cpp @@ -483,6 +483,12 @@ Manager::getDeviceProperties() const return this->mPhysicalDevice->getProperties(); } +vk::PhysicalDeviceFeatures +Manager::getDeviceFeatures() const +{ + return this->mPhysicalDevice->getFeatures(); +} + std::vector Manager::listDevices() const { diff --git a/src/include/kompute/Manager.hpp b/src/include/kompute/Manager.hpp index 097f6971..42ab4131 100644 --- a/src/include/kompute/Manager.hpp +++ b/src/include/kompute/Manager.hpp @@ -505,6 +505,14 @@ class Manager **/ vk::PhysicalDeviceProperties getDeviceProperties() const; + /** + * Information about the current device features. + * + * @return vk::PhysicalDeviceFeatures containing information about the + *device features + **/ + vk::PhysicalDeviceFeatures getDeviceFeatures() const; + /** * List the devices available in the current vulkan instance. * From 627f4d9980cc8c3434831d4843e945e87e245f4c Mon Sep 17 00:00:00 2001 From: koubaa Date: Tue, 10 Dec 2024 09:36:39 -0600 Subject: [PATCH 02/10] add tests Signed-off-by: koubaa --- python/test/test_kompute.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python/test/test_kompute.py b/python/test/test_kompute.py index c05cca74..66969452 100644 --- a/python/test/test_kompute.py +++ b/python/test/test_kompute.py @@ -279,8 +279,12 @@ def test_mgr_utils(): props = mgr.get_device_properties() assert "device_name" in props + assert "max_push_constants_size" in props devices = mgr.list_devices() assert len(devices) > 0 assert "device_name" in devices[0] + + feats = mgr.get_device_features() + assert "shader_float64" in feats From b57583778703ba9cf4949fdc488ece9f53b1df68 Mon Sep 17 00:00:00 2001 From: koubaa Date: Tue, 10 Dec 2024 10:32:13 -0600 Subject: [PATCH 03/10] add feature request Signed-off-by: koubaa --- python/src/docstrings.hpp | 29 +++++++++++++++------- python/src/main.cpp | 23 ++++++++++++++++-- src/Manager.cpp | 43 +++++++++++++++++++++++---------- src/include/kompute/Manager.hpp | 24 ++++++++++++++++-- 4 files changed, 93 insertions(+), 26 deletions(-) diff --git a/python/src/docstrings.hpp b/python/src/docstrings.hpp index 21ed0f15..93bb70fa 100644 --- a/python/src/docstrings.hpp +++ b/python/src/docstrings.hpp @@ -538,17 +538,11 @@ R"doc(Base constructor and default used which creates the base resources including choosing the device 0 by default.)doc"; static const char *__doc_kp_Manager_Manager_2 = -R"doc(Similar to base constructor but allows for further configuration to -use when creating the Vulkan resources. +R"doc(Similar to base constructor but allows selection of the +device Parameter ``physicalDeviceIndex``: - The index of the physical device to use - -Parameter ``familyQueueIndices``: - (Optional) List of queue indices to add for explicit allocation - -Parameter ``desiredExtensions``: - The desired extensions to load from physicalDevice)doc"; + The index of the physical device to use)doc"; static const char *__doc_kp_Manager_Manager_3 = R"doc(Manager constructor which allows your own vulkan application to @@ -566,6 +560,23 @@ Parameter ``device``: Parameter ``physicalDeviceIndex``: Index for vulkan physical device used)doc"; +static const char *__doc_kp_Manager_Manager_4 = +R"doc(Similar to second constructor but allows for further configuration to +control the requested features of the Vulkan device. + +Parameter ``device``: + The index of the physical device to use + +Parameter ``family_queue_indices``: + (Optional) List of queue indices to add for explicit allocation + +Parameter ``desired_extensions``: + The desired extensions to load from physicalDevice + +Parameter ``desired_features``: + The desired featutures to request from the physicalDevice)doc"; + + static const char *__doc_kp_Manager_algorithm = R"doc(Default non-template function that can be used to create algorithm objects which provides default types to the push and spec constants as diff --git a/python/src/main.cpp b/python/src/main.cpp index 94c1f4b2..878b3512 100644 --- a/python/src/main.cpp +++ b/python/src/main.cpp @@ -65,6 +65,14 @@ PYBIND11_MODULE(kp, m) py::module_ np = py::module_::import("numpy"); + py::class_( + m, "PhysicalDeviceFeatures") + .def(py::init()) + .def_readwrite("robust_buffer_access", &vk::PhysicalDeviceFeatures::robustBufferAccess) + .def_readwrite("shader_float64", &vk::PhysicalDeviceFeatures::shaderFloat64) + .def_readwrite("shader_int64", &vk::PhysicalDeviceFeatures::shaderInt64) + .def_readwrite("shader_int16", &vk::PhysicalDeviceFeatures::shaderInt16); + py::enum_(m, "DataTypes") .value("bool", kp::Memory::DataTypes::eBool, @@ -288,12 +296,23 @@ PYBIND11_MODULE(kp, m) py::class_>( m, "Manager", DOC(kp, Manager)) .def(py::init(), DOC(kp, Manager, Manager)) - .def(py::init(), DOC(kp, Manager, Manager_2)) + .def(py::init(), + DOC(kp, Manager, Manager_2), + py::arg("device") = 0) .def(py::init&, const std::vector&>(), - DOC(kp, Manager, Manager_2), + DOC(kp, Manager, Manager_3), + py::arg("device") = 0, + py::arg("family_queue_indices") = std::vector(), + py::arg("desired_extensions") = std::vector()) + .def(py::init&, + const std::vector&>(), + DOC(kp, Manager, Manager_4), py::arg("device") = 0, + py::arg("desired_features") = vk::PhysicalDeviceFeatures(), py::arg("family_queue_indices") = std::vector(), py::arg("desired_extensions") = std::vector()) .def("destroy", &kp::Manager::destroy, DOC(kp, Manager, destroy)) diff --git a/src/Manager.cpp b/src/Manager.cpp index 4086c4af..89c583db 100644 --- a/src/Manager.cpp +++ b/src/Manager.cpp @@ -33,9 +33,20 @@ debugMessageCallback(VkDebugReportFlagsEXT /*flags*/, } #endif +static void setUpLogger() { + // Make sure the logger is setup +#if !KOMPUTE_OPT_LOG_LEVEL_DISABLED + logger::setupLogger(); +#endif +} + Manager::Manager() - : Manager(0) { + this->mManageResources = true; + setUpLogger(); + this->createInstance(); + this->createDevice( + {}, 0, {}, nullptr); } Manager::Manager(uint32_t physicalDeviceIndex, @@ -43,15 +54,22 @@ Manager::Manager(uint32_t physicalDeviceIndex, const std::vector& desiredExtensions) { this->mManageResources = true; + setUpLogger(); + this->createInstance(); + this->createDevice( + familyQueueIndices, physicalDeviceIndex, desiredExtensions, nullptr); +} -// Make sure the logger is setup -#if !KOMPUTE_OPT_LOG_LEVEL_DISABLED - logger::setupLogger(); -#endif - +Manager::Manager(uint32_t physicalDeviceIndex, + const vk::PhysicalDeviceFeatures& desiredFeatures, + const std::vector& familyQueueIndices, + const std::vector& desiredExtensions) +{ + this->mManageResources = true; + setUpLogger(); this->createInstance(); this->createDevice( - familyQueueIndices, physicalDeviceIndex, desiredExtensions); + familyQueueIndices, physicalDeviceIndex, desiredExtensions, &desiredFeatures); } Manager::Manager(std::shared_ptr instance, @@ -64,10 +82,7 @@ Manager::Manager(std::shared_ptr instance, this->mPhysicalDevice = physicalDevice; this->mDevice = device; -// Make sure the logger is setup -#if !KOMPUTE_OPT_LOG_LEVEL_DISABLED - logger::setupLogger(); -#endif + setUpLogger(); } Manager::~Manager() @@ -312,7 +327,8 @@ Manager::clear() void Manager::createDevice(const std::vector& familyQueueIndices, uint32_t physicalDeviceIndex, - const std::vector& desiredExtensions) + const std::vector& desiredExtensions, + const vk::PhysicalDeviceFeatures* pDesiredFeatures) { KP_LOG_DEBUG("Kompute Manager creating Device"); @@ -436,7 +452,8 @@ Manager::createDevice(const std::vector& familyQueueIndices, {}, {}, validExtensions.size(), - validExtensions.data()); + validExtensions.data(), + pDesiredFeatures); this->mDevice = std::make_shared(); physicalDevice.createDevice( diff --git a/src/include/kompute/Manager.hpp b/src/include/kompute/Manager.hpp index 42ab4131..3e4933b8 100644 --- a/src/include/kompute/Manager.hpp +++ b/src/include/kompute/Manager.hpp @@ -30,13 +30,32 @@ class Manager * @param physicalDeviceIndex The index of the physical device to use * @param familyQueueIndices (Optional) List of queue indices to add for * explicit allocation - * @param desiredExtensions The desired extensions to load from + * @param desiredExtensions (Optional) The desired extensions to load from * physicalDevice + * @param desiredFeatures (Optional) The desired features to include + * in the physical device */ Manager(uint32_t physicalDeviceIndex, const std::vector& familyQueueIndices = {}, const std::vector& desiredExtensions = {}); + /** + * Similar to second constructor but allows for further configuration + * for Vulkan device features. + * + * @param physicalDeviceIndex The index of the physical device to use + * @param desiredFeatures The desired features to request from the + * physical device + * @param familyQueueIndices (Optional) List of queue indices to add for + * explicit allocation + * @param desiredExtensions (Optional) The desired extensions to load from + * physicalDevice + */ + Manager(uint32_t physicalDeviceIndex, + const vk::PhysicalDeviceFeatures& desiredFeatures, + const std::vector& familyQueueIndices = {}, + const std::vector& desiredExtensions = {}); + /** * Manager constructor which allows your own vulkan application to integrate * with the kompute use. @@ -555,7 +574,8 @@ class Manager void createInstance(); void createDevice(const std::vector& familyQueueIndices = {}, uint32_t hysicalDeviceIndex = 0, - const std::vector& desiredExtensions = {}); + const std::vector& desiredExtensions = {}, + const vk::PhysicalDeviceFeatures* pDesiredFeatures = nullptr); }; } // End namespace kp From fa4e4f086f657fabc56cf76d75ebb82591e1b1f6 Mon Sep 17 00:00:00 2001 From: koubaa Date: Tue, 10 Dec 2024 10:34:41 -0600 Subject: [PATCH 04/10] test Signed-off-by: koubaa --- python/test/test_kompute.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/python/test/test_kompute.py b/python/test/test_kompute.py index 66969452..c12f5fdd 100644 --- a/python/test/test_kompute.py +++ b/python/test/test_kompute.py @@ -288,3 +288,8 @@ def test_mgr_utils(): feats = mgr.get_device_features() assert "shader_float64" in feats + +def test_mgr_request_features(): + features = kp.PhysicalDeviceFeatures() + features.shader_float64 = True + mgr = kp.Manager(0, features) From f5b00f893f7b2acda46f9be86cda7362d12f58a7 Mon Sep 17 00:00:00 2001 From: koubaa Date: Tue, 10 Dec 2024 10:36:20 -0600 Subject: [PATCH 05/10] fix c++ test Signed-off-by: koubaa --- test/TestAsyncOperations.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/TestAsyncOperations.cpp b/test/TestAsyncOperations.cpp index 92ec664b..9caeaed8 100644 --- a/test/TestAsyncOperations.cpp +++ b/test/TestAsyncOperations.cpp @@ -79,7 +79,7 @@ TEST(TestAsyncOperations, TestManagerParallelExecution) EXPECT_EQ(inputsSyncB[i]->vector(), resultSync); } - kp::Manager mgrAsync(0, { 0, 2 }); + kp::Manager mgrAsync(0, std::vector{ 0, 2 }); std::vector> inputsAsyncB; From 6668ba77faea5c42a48f1c99390b3fb76707c79a Mon Sep 17 00:00:00 2001 From: koubaa Date: Tue, 10 Dec 2024 12:34:31 -0600 Subject: [PATCH 06/10] test Signed-off-by: koubaa --- python/test/test_kompute.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/test/test_kompute.py b/python/test/test_kompute.py index c12f5fdd..2089c219 100644 --- a/python/test/test_kompute.py +++ b/python/test/test_kompute.py @@ -291,5 +291,5 @@ def test_mgr_utils(): def test_mgr_request_features(): features = kp.PhysicalDeviceFeatures() - features.shader_float64 = True - mgr = kp.Manager(0, features) + #features.shader_float64 = True + #mgr = kp.Manager(0, features) From fcb8db9d01c1f710ac88d86cdc602737b6b9dfa7 Mon Sep 17 00:00:00 2001 From: koubaa Date: Tue, 10 Dec 2024 12:36:58 -0600 Subject: [PATCH 07/10] add float64 option Signed-off-by: koubaa --- python/test/test_kompute.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/test/test_kompute.py b/python/test/test_kompute.py index 2089c219..6f3454f1 100644 --- a/python/test/test_kompute.py +++ b/python/test/test_kompute.py @@ -291,5 +291,5 @@ def test_mgr_utils(): def test_mgr_request_features(): features = kp.PhysicalDeviceFeatures() - #features.shader_float64 = True + features.shader_float64 = True #mgr = kp.Manager(0, features) From 1e45ab52d1768521208e3a2def3f97f5b9ee51b2 Mon Sep 17 00:00:00 2001 From: koubaa Date: Tue, 10 Dec 2024 12:40:12 -0600 Subject: [PATCH 08/10] use constructor Signed-off-by: koubaa --- python/test/test_kompute.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/test/test_kompute.py b/python/test/test_kompute.py index 6f3454f1..52efcd0b 100644 --- a/python/test/test_kompute.py +++ b/python/test/test_kompute.py @@ -292,4 +292,6 @@ def test_mgr_utils(): def test_mgr_request_features(): features = kp.PhysicalDeviceFeatures() features.shader_float64 = True - #mgr = kp.Manager(0, features) + + kp_log.setLevel(logging.DEBUG) + mgr = kp.Manager(0, features) From ab3e221e63d512c9d24d778835d3451e6930ddfa Mon Sep 17 00:00:00 2001 From: koubaa Date: Tue, 10 Dec 2024 12:45:43 -0600 Subject: [PATCH 09/10] forked tests Signed-off-by: koubaa --- Makefile | 2 +- python/test/requirements-dev.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 8ef01643..b79115a8 100644 --- a/Makefile +++ b/Makefile @@ -160,7 +160,7 @@ vs_run_tests: vs_build_tests #### PYTHONG #### test_python: - python3 -m pytest -s --log-cli-level=DEBUG -v python/test/ + python3 -m pytest --forked -s --log-cli-level=DEBUG -v python/test/ ####### Run CI Commands ####### diff --git a/python/test/requirements-dev.txt b/python/test/requirements-dev.txt index 99d811d3..42d36fe7 100644 --- a/python/test/requirements-dev.txt +++ b/python/test/requirements-dev.txt @@ -1,4 +1,4 @@ pyshader==0.7.0 numpy==1.22.4 pytest==7.1.2 - +pytest-xdist==3.6.1 From cf4f25532ccf12cb408ac83cbeb779ef3c6e172c Mon Sep 17 00:00:00 2001 From: koubaa Date: Tue, 10 Dec 2024 13:00:24 -0600 Subject: [PATCH 10/10] fix requirements Signed-off-by: koubaa --- python/test/requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/test/requirements-dev.txt b/python/test/requirements-dev.txt index 42d36fe7..765484c6 100644 --- a/python/test/requirements-dev.txt +++ b/python/test/requirements-dev.txt @@ -1,4 +1,4 @@ pyshader==0.7.0 numpy==1.22.4 pytest==7.1.2 -pytest-xdist==3.6.1 +pytest-forked==1.6.0