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/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 3bddce88..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,14 +296,25 @@ 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)) .def("sequence", &kp::Manager::sequence, @@ -733,7 +752,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/python/test/requirements-dev.txt b/python/test/requirements-dev.txt index 99d811d3..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-forked==1.6.0 diff --git a/python/test/test_kompute.py b/python/test/test_kompute.py index c05cca74..52efcd0b 100644 --- a/python/test/test_kompute.py +++ b/python/test/test_kompute.py @@ -279,8 +279,19 @@ 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 + +def test_mgr_request_features(): + features = kp.PhysicalDeviceFeatures() + features.shader_float64 = True + + kp_log.setLevel(logging.DEBUG) + mgr = kp.Manager(0, features) diff --git a/src/Manager.cpp b/src/Manager.cpp index 32577db1..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( @@ -483,6 +500,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..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. @@ -505,6 +524,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. * @@ -547,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 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;