Merge pull request #184 from alexander-g/deviceproperties

Device Properties
This commit is contained in:
Alejandro Saucedo 2021-03-12 09:13:09 +00:00 committed by GitHub
commit abd635c0a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 1 deletions

View file

@ -9,6 +9,8 @@
#include "docstrings.hpp"
namespace py = pybind11;
using namespace pybind11::literals; // for the `_a` literal
//used in Core.hpp
py::object kp_debug, kp_info, kp_warning, kp_error;
@ -217,7 +219,24 @@ PYBIND11_MODULE(kp, m) {
py::arg("spirv"),
py::arg("workgroup") = kp::Workgroup(),
py::arg("spec_consts") = kp::Constants(),
py::arg("push_consts") = kp::Constants());
py::arg("push_consts") = kp::Constants())
.def("get_device_properties", [](kp::Manager& self){
const auto properties = self.getDeviceProperties();
py::dict py_props(
"device_name"_a = std::string(properties.deviceName.data()),
"max_work_group_count"_a = py::make_tuple(properties.limits.maxComputeWorkGroupCount[0],
properties.limits.maxComputeWorkGroupCount[1],
properties.limits.maxComputeWorkGroupCount[2]),
"max_work_group_invocations"_a = properties.limits.maxComputeWorkGroupInvocations,
"max_work_group_size"_a = py::make_tuple(properties.limits.maxComputeWorkGroupSize[0],
properties.limits.maxComputeWorkGroupSize[1],
properties.limits.maxComputeWorkGroupSize[2]),
"timestamps_supported"_a = (bool)properties.limits.timestampComputeAndGraphics
);
return py_props;
}, "Return a dict containing information about the device");
#ifdef VERSION_INFO
m.attr("__version__") = VERSION_INFO;

View file

@ -2091,6 +2091,11 @@ class Manager
**/
void clear();
/**
* Return a struct containing information about the device.
**/
vk::PhysicalDeviceProperties getDeviceProperties() const;
private:
// -------------- OPTIONALLY OWNED RESOURCES
std::shared_ptr<vk::Instance> mInstance = nullptr;

View file

@ -447,4 +447,10 @@ Manager::sequence(uint32_t queueIndex, uint32_t totalTimestamps)
return sq;
}
vk::PhysicalDeviceProperties
Manager::getDeviceProperties() const
{
return this->mPhysicalDevice->getProperties();
}
}

View file

@ -153,6 +153,11 @@ class Manager
**/
void clear();
/**
* Return a struct containing information about the device.
**/
vk::PhysicalDeviceProperties getDeviceProperties() const;
private:
// -------------- OPTIONALLY OWNED RESOURCES
std::shared_ptr<vk::Instance> mInstance = nullptr;

View file

@ -62,3 +62,10 @@ TEST(TestManager, TestMultipleSequences)
EXPECT_EQ(tensorOutput->vector(), std::vector<float>({ 0, 4, 12 }));
}
TEST(TestManager, TestDeviceProperties)
{
kp::Manager mgr;
const auto properties = mgr.getDeviceProperties();
EXPECT_GT(properties.deviceName.size(), 0);
}