Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First API test #153

Merged
merged 9 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@ jobs:
- name: Run arch-specific UMD unit tests
run: |
${{ env.TEST_OUTPUT_DIR }}/umd/${{ inputs.arch }}/unit_tests
- name: Run additional UMD tests

- name: Run PCI tests
run: |
${{ env.TEST_OUTPUT_DIR }}/umd/test_pcie_device/test_pcie_device


- name: Run API tests
run: |
${{ env.TEST_OUTPUT_DIR }}/umd/api/api_tests
3 changes: 3 additions & 0 deletions device/pcie/pci_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ inline void memcpy_from_device(void *dest, const void *src, std::size_t num_byte
std::vector<int> device_ids;
std::string path = "/dev/tenstorrent/";

if (!std::filesystem::exists(path)) {
return device_ids;
}
for (const auto& entry : std::filesystem::directory_iterator(path)) {
std::string filename = entry.path().filename().string();

Expand Down
2 changes: 1 addition & 1 deletion device/tt_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ class tt_SiliconDevice: public tt_device
* @param perform_harvesting Allow the driver to modify the SOC descriptors per chip.
* @param simulated_harvesting_masks
*/
tt_SiliconDevice(const std::string &sdesc_path, const std::string &ndesc_path = "", const std::set<chip_id_t> &target_devices = {},
tt_SiliconDevice(const std::string &sdesc_path, const std::string &ndesc_path, const std::set<chip_id_t> &target_devices,
const uint32_t &num_host_mem_ch_per_mmio_device = 1, const std::unordered_map<std::string, std::int32_t>& dynamic_tlb_config_ = {},
const bool skip_driver_allocs = false, const bool clean_system_resources = false, bool perform_harvesting = true, std::unordered_map<chip_id_t, uint32_t> simulated_harvesting_masks = {});

Expand Down
4 changes: 3 additions & 1 deletion device/tt_silicon_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,10 @@ tt_SiliconDevice::tt_SiliconDevice(const std::string &sdesc_path, const std::str
auto available_device_ids = detect_available_device_ids();
m_num_pci_devices = available_device_ids.size();

if (!skip_driver_allocs)
if (!skip_driver_allocs) {
log_info(LogSiliconDriver, "Detected {} PCI device{} : {}", m_num_pci_devices, (m_num_pci_devices > 1) ? "s":"", available_device_ids);
log_debug(LogSiliconDriver, "Passed target devices: {}", target_devices);
}

if (ndesc_path == "") {
ndesc = tt_ClusterDescriptor::create_for_grayskull_cluster(target_devices, available_device_ids);
Expand Down
3 changes: 2 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ target_include_directories(test_common INTERFACE
if (MASTER_PROJECT)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/microbenchmark)
endif()
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/api)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/pcie)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/simulation)
if($ENV{ARCH_NAME} STREQUAL "wormhole_b0")
Expand All @@ -42,4 +43,4 @@ else()
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/$ENV{ARCH_NAME})
endif()

add_custom_target(umd_tests DEPENDS umd_unit_tests simulation_tests test_pcie_device)
add_custom_target(umd_tests DEPENDS umd_unit_tests simulation_tests test_pcie_device api_tests)
10 changes: 10 additions & 0 deletions tests/api/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(API_TESTS_SRCS
test_cluster.cpp
)

add_executable(api_tests ${API_TESTS_SRCS})
target_link_libraries(api_tests PRIVATE test_common)
set_target_properties(api_tests PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/test/umd/api
OUTPUT_NAME api_tests
)
79 changes: 79 additions & 0 deletions tests/api/test_cluster.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@

#include <gtest/gtest.h>
#include "fmt/xchar.h"

#include <algorithm>
#include <filesystem>
#include <string>
#include <vector>

#include "tests/test_utils/generate_cluster_desc.hpp"

// TODO: change to tt_cluster
#include "device/tt_device.h"
#include "device/tt_cluster_descriptor.h"

// TODO: do proper renaming.
using Cluster = tt_SiliconDevice;

// These tests are intended to be run with the same code on all kinds of systems:
// E75, E150, E300
// N150. N300
// Galaxy

// This test should be one line only.
TEST(ApiTest, OpenAllChips) {

// TODO: This should not be needed. And could be part of the cluster descriptor probably.
// Note that cluster descriptor holds logical ids of chips.
// Which are different than physical PCI ids, which are /dev/tenstorrent/N ones.
// You have to see if physical PCIe is GS before constructing a cluster descriptor.
std::vector<int> pci_device_ids = PCIDevice::enumerate_devices();
std::set<int> pci_device_ids_set (pci_device_ids.begin(), pci_device_ids.end());

tt::ARCH device_arch = tt::ARCH::GRAYSKULL;
if (!pci_device_ids.empty()) {
// TODO: This should be removed from the API, the driver itself should do it.
int physical_device_id = pci_device_ids[0];
// TODO: remove logical_device_id
PCIDevice pci_device (physical_device_id, 0);
device_arch = pci_device.get_arch();
}

// TODO: Make this test work on a host system without any tt devices.
if (pci_device_ids.empty()) {
std::cout << "No Tenstorrent devices found. Skipping test." << std::endl;
return;
}

// TODO: remove getting manually cluster descriptor from yaml.
std::string yaml_path = test_utils::GetClusterDescYAML();
// TODO: Remove the need to do this, allow default constructor to construct with all chips.
std::unique_ptr<tt_ClusterDescriptor> cluster_desc;
if (device_arch == tt::ARCH::GRAYSKULL) {
cluster_desc = tt_ClusterDescriptor::create_for_grayskull_cluster(pci_device_ids_set, pci_device_ids);
} else {
cluster_desc = tt_ClusterDescriptor::create_from_yaml(yaml_path);
}
std::unordered_set<int> detected_num_chips = cluster_desc->get_all_chips();

// TODO: make this unordered vs set conversion not needed.
std::set<chip_id_t> detected_num_chips_set (detected_num_chips.begin(), detected_num_chips.end());


// TODO: This would be incorporated inside SocDescriptor.
std::string soc_path;
if (device_arch == tt::ARCH::GRAYSKULL) {
soc_path = test_utils::GetAbsPath("tests/soc_descs/grayskull_10x12.yaml");
} else if (device_arch == tt::ARCH::WORMHOLE || device_arch == tt::ARCH::WORMHOLE_B0) {
soc_path = test_utils::GetAbsPath("tests/soc_descs/wormhole_b0_8x10.yaml");
} else if (device_arch == tt::ARCH::BLACKHOLE) {
soc_path = test_utils::GetAbsPath("tests/soc_descs/blackhole_140_arch_no_eth.yaml");
} else {
throw std::runtime_error("Unsupported architecture");
}


// TODO: Don't pass each of these arguments.
Cluster umd_cluster = Cluster(soc_path, device_arch == tt::ARCH::GRAYSKULL ? "" : yaml_path, detected_num_chips_set);
}