Skip to content

Commit

Permalink
Merge pull request #184 from alexander-g/deviceproperties
Browse files Browse the repository at this point in the history
Device Properties
  • Loading branch information
axsaucedo committed Mar 12, 2021
2 parents 8ec1f80 + d71d169 commit abd635c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
21 changes: 20 additions & 1 deletion python/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions single_include/kompute/Kompute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,4 +447,10 @@ Manager::sequence(uint32_t queueIndex, uint32_t totalTimestamps)
return sq;
}

vk::PhysicalDeviceProperties
Manager::getDeviceProperties() const
{
return this->mPhysicalDevice->getProperties();
}

}
5 changes: 5 additions & 0 deletions src/include/kompute/Manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions test/TestManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit abd635c

Please sign in to comment.