| 1 |
// Copyright Advanced Micro Devices, Inc., or its affiliates. |
| 2 |
// SPDX-License-Identifier: MIT |
| 3 |
|
| 4 |
#include "origami/hardware.hpp" |
| 5 |
#include "origami/streamk.hpp" |
| 6 |
#include "origami/utils.hpp" |
| 7 |
|
| 8 |
#include <nanobind/nanobind.h> |
| 9 |
#include <nanobind/stl/string.h> |
| 10 |
#include <nanobind/stl/vector.h> |
| 11 |
#include <nanobind/stl/map.h> |
| 12 |
#include <nanobind/stl/unordered_map.h> |
| 13 |
#include <nanobind/stl/pair.h> |
| 14 |
#include <nanobind/stl/tuple.h> |
| 15 |
|
| 16 |
using hardware_t = origami::hardware_t; |
| 17 |
|
| 18 |
NB_MODULE(origami, m) |
| 19 |
{ |
| 20 |
nanobind::enum_<hardware_t::architecture_t>(m, "architecture_t") |
| 21 |
.value("gfx942", hardware_t::architecture_t::gfx942) |
| 22 |
.value("gfx950", hardware_t::architecture_t::gfx950) |
| 23 |
.export_values(); |
| 24 |
|
| 25 |
nanobind::enum_<origami::data_type_t>(m, "data_type_t") |
| 26 |
.value("Float", origami::data_type_t::Float) |
| 27 |
.value("ComplexFloat", origami::data_type_t::ComplexFloat) |
| 28 |
.value("ComplexDouble", origami::data_type_t::ComplexDouble) |
| 29 |
.value("Double", origami::data_type_t::Double) |
| 30 |
.value("Half", origami::data_type_t::Half) |
| 31 |
.value("Int8x4", origami::data_type_t::Int8x4) |
| 32 |
.value("Int32", origami::data_type_t::Int32) |
| 33 |
.value("BFloat16", origami::data_type_t::BFloat16) |
| 34 |
.value("Int8", origami::data_type_t::Int8) |
| 35 |
.value("Int64", origami::data_type_t::Int64) |
| 36 |
.value("XFloat32", origami::data_type_t::XFloat32) |
| 37 |
.value("Float8_fnuz", origami::data_type_t::Float8_fnuz) |
| 38 |
.value("BFloat8_fnuz", origami::data_type_t::BFloat8_fnuz) |
| 39 |
.value("Float8BFloat8_fnuz", origami::data_type_t::Float8BFloat8_fnuz) |
| 40 |
.value("BFloat8Float8_fnuz", origami::data_type_t::BFloat8Float8_fnuz) |
| 41 |
.value("Float8", origami::data_type_t::Float8) |
| 42 |
.value("BFloat8", origami::data_type_t::BFloat8) |
| 43 |
.value("Float8BFloat8", origami::data_type_t::Float8BFloat8) |
| 44 |
.value("BFloat8Float8", origami::data_type_t::BFloat8Float8) |
| 45 |
.value("Float6", origami::data_type_t::Float6) |
| 46 |
.value("BFloat6", origami::data_type_t::BFloat6) |
| 47 |
.value("Float4", origami::data_type_t::Float4) |
| 48 |
.export_values(); |
| 49 |
|
| 50 |
m.def("int_to_data_type", |
| 51 |
&origami::int_to_data_type, |
| 52 |
"Convert int to data_type_t."); |
| 53 |
|
| 54 |
nanobind::enum_<origami::streamk::reduction_type>(m, "reduction_type") |
| 55 |
.value("Tree", origami::streamk::reduction_type::Tree) |
| 56 |
.value("Parallel", origami::streamk::reduction_type::Parallel) |
| 57 |
.export_values(); |
| 58 |
|
| 59 |
m.def("int_to_reduction_type", |
| 60 |
&origami::streamk::int_to_reduction_type, |
| 61 |
"Convert int to reduction_type."); |
| 62 |
|
| 63 |
nanobind::class_<hardware_t>(m, "hardware_t") |
| 64 |
.def(nanobind::init<hardware_t::architecture_t, |
| 65 |
size_t, |
| 66 |
size_t, |
| 67 |
size_t, |
| 68 |
double, |
| 69 |
double, |
| 70 |
double, |
| 71 |
size_t, |
| 72 |
double, |
| 73 |
size_t, |
| 74 |
std::tuple<double, double, double>>()) |
| 75 |
.def("print", &hardware_t::print) |
| 76 |
.def("print_debug_info", &hardware_t::print_debug_info) |
| 77 |
.def_rw("N_CU", &hardware_t::N_CU) |
| 78 |
.def_rw("lds_capacity", &hardware_t::lds_capacity) |
| 79 |
.def_rw("mem1_perf_ratio", &hardware_t::mem1_perf_ratio) |
| 80 |
.def_rw("mem2_perf_ratio", &hardware_t::mem2_perf_ratio) |
| 81 |
.def_rw("mem3_perf_ratio", &hardware_t::mem3_perf_ratio) |
| 82 |
.def_rw("L2_capacity", &hardware_t::L2_capacity) |
| 83 |
.def_rw("CU_per_L2", &hardware_t::CU_per_L2) |
| 84 |
.def_rw("compute_clock_ghz", &hardware_t::compute_clock_ghz) |
| 85 |
.def_rw("parallel_mi_cu", &hardware_t::parallel_mi_cu) |
| 86 |
.def_rw("mem_bw_per_wg_coefficients", &hardware_t::mem_bw_per_wg_coefficients) |
| 87 |
.def_rw("NUM_XCD", &hardware_t::NUM_XCD); |
| 88 |
|
| 89 |
m.def("get_hardware_for_device", |
| 90 |
&hardware_t::get_hardware_for_device, |
| 91 |
"This gets a hardware object for a device."); |
| 92 |
|
| 93 |
m.def("datatype_to_bits", &origami::data_type_to_bits, "Return the number of bits in a datatype"); |
| 94 |
m.def("string_to_datatype", &origami::string_to_data_type, "Convert a string representation of a datatype into data_type_t enum"); |
| 95 |
m.def("select_best_macro_tile_size", |
| 96 |
&origami::select_best_macro_tile_size, |
| 97 |
"Get best macro tile sizes."); |
| 98 |
m.def("select_reduction", &origami::streamk::select_reduction, "Select best StreamK reduction strategy"); |
| 99 |
m.def("select_grid", &origami::streamk::select_grid, "Select Best StreamK Grid Size"); |
| 100 |
m.def("compute_total_latency", &origami::compute_total_latency, "compute_total_latency"); |
| 101 |
m.def("select_best_wgm", &origami::select_best_wgm, "Get best workgroup mapping."); |
| 102 |
} |