|
| 1 | +# Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import os |
| 16 | + |
| 17 | +import pandas as pd |
| 18 | +import pytest |
| 19 | +from cloudai.schema.test_template.nccl_test.report_generation_strategy import NcclTestReportGenerationStrategy |
| 20 | + |
| 21 | + |
| 22 | +@pytest.fixture |
| 23 | +def setup_test_environment(tmpdir): |
| 24 | + # Create a temporary directory for the test |
| 25 | + test_dir = tmpdir.mkdir("test_env") |
| 26 | + |
| 27 | + # Create the mock stdout.txt file |
| 28 | + stdout_content = """ |
| 29 | + # Using devices |
| 30 | + # Rank 0 Group 0 Pid 111111 on server001 device 0 [0xaa] NVIDIA H200 64GB HBM3 |
| 31 | + # Rank 1 Group 0 Pid 222222 on server001 device 1 [0xbb] NVIDIA H200 64GB HBM3 |
| 32 | + # Rank 2 Group 0 Pid 333333 on server001 device 2 [0xcc] NVIDIA H200 64GB HBM3 |
| 33 | + # Rank 3 Group 0 Pid 444444 on server001 device 3 [0xdd] NVIDIA H200 64GB HBM3 |
| 34 | + # Rank 4 Group 0 Pid 555555 on server001 device 4 [0xee] NVIDIA H200 64GB HBM3 |
| 35 | + # Rank 5 Group 0 Pid 666666 on server001 device 5 [0xff] NVIDIA H200 64GB HBM3 |
| 36 | + # Rank 6 Group 0 Pid 777777 on server001 device 6 [0x11] NVIDIA H200 64GB HBM3 |
| 37 | + # Rank 7 Group 0 Pid 888888 on server001 device 7 [0x22] NVIDIA H200 64GB HBM3 |
| 38 | + NCCL version 1.23.4+cuda11.2 |
| 39 | + # |
| 40 | + # out-of-place in-place |
| 41 | + # size count type redop root time algbw busbw #wrong time algbw busbw #wrong |
| 42 | + # (B) (elements) (us) (GB/s) (GB/s) (us) (GB/s) (GB/s) |
| 43 | + 1000000 1000000 float sum -1 1.11 10.10 20.20 0 1.12 10.11 20.21 0 |
| 44 | + 2000000 2000000 float sum -1 2.22 20.20 30.30 0 2.23 20.21 30.31 0 |
| 45 | + 3000000 3000000 float sum -1 3.33 30.30 40.40 0 3.34 30.31 40.41 0 |
| 46 | + 4000000 4000000 float sum -1 4.44 40.40 50.50 0 4.45 40.41 50.51 0 |
| 47 | + 5000000 5000000 float sum -1 5.55 50.50 60.60 0 5.56 50.51 60.61 0 |
| 48 | + 6000000 6000000 float sum -1 6.66 60.60 70.70 0 6.67 60.61 70.71 0 |
| 49 | + 7000000 7000000 float sum -1 7.77 70.70 80.80 0 7.78 70.71 80.81 0 |
| 50 | + 8000000 8000000 float sum -1 8.88 80.80 90.90 0 8.89 80.81 90.91 0 |
| 51 | + 9000000 9000000 float sum -1 9.99 90.90 100.10 0 10.00 90.91 100.11 0 |
| 52 | + 10000000 10000000 float sum -1 11.11 100.10 110.20 0 11.12 100.11 110.21 0 |
| 53 | + 11000000 11000000 float sum -1 12.12 110.20 120.30 0 12.13 110.21 120.31 0 |
| 54 | + 12000000 12000000 float sum -1 13.13 120.30 130.40 0 13.14 120.31 130.41 0 |
| 55 | + # Out of bounds values : 0 OK |
| 56 | + # Avg bus bandwidth : 111.111 |
| 57 | + # |
| 58 | + """ |
| 59 | + stdout_path = os.path.join(test_dir, "stdout.txt") |
| 60 | + with open(stdout_path, "w") as f: |
| 61 | + f.write(stdout_content) |
| 62 | + |
| 63 | + return test_dir |
| 64 | + |
| 65 | + |
| 66 | +def test_nccl_report_generation(setup_test_environment): |
| 67 | + test_dir = setup_test_environment |
| 68 | + |
| 69 | + # Instantiate the strategy |
| 70 | + strategy = NcclTestReportGenerationStrategy() |
| 71 | + |
| 72 | + # Validate the directory can be handled |
| 73 | + assert strategy.can_handle_directory(test_dir) is True |
| 74 | + |
| 75 | + # Generate the report |
| 76 | + strategy.generate_report("nccl_test", test_dir) |
| 77 | + |
| 78 | + # Verify the CSV report |
| 79 | + csv_report_path = os.path.join(test_dir, "cloudai_nccl_test_csv_report.csv") |
| 80 | + assert os.path.isfile(csv_report_path), "CSV report was not generated." |
| 81 | + |
| 82 | + # Read the CSV and validate the content |
| 83 | + df = pd.read_csv(csv_report_path) |
| 84 | + assert not df.empty, "CSV report is empty." |
| 85 | + |
| 86 | + # Validate specific values if needed |
| 87 | + # Example: Checking that the first entry matches the expected value |
| 88 | + assert df.iloc[0]["Size (B)"] == 1000000.0, "First row Size (B) does not match." |
| 89 | + assert df.iloc[0]["Algbw (GB/s) Out-of-place"] == 10.10, "First row Algbw (GB/s) Out-of-place does not match." |
| 90 | + assert df.iloc[0]["Busbw (GB/s) Out-of-place"] == 20.20, "First row Busbw (GB/s) Out-of-place does not match." |
| 91 | + |
| 92 | + # Checking that the last entry matches the expected value |
| 93 | + assert df.iloc[-1]["Size (B)"] == 12000000.0, "Last row Size (B) does not match." |
| 94 | + assert df.iloc[-1]["Algbw (GB/s) Out-of-place"] == 120.30, "Last row Algbw (GB/s) Out-of-place does not match." |
| 95 | + assert df.iloc[-1]["Busbw (GB/s) Out-of-place"] == 130.40, "Last row Busbw (GB/s) Out-of-place does not match." |
0 commit comments