CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
76 lines
2.1 KiB
Python
76 lines
2.1 KiB
Python
# Copyright © Advanced Micro Devices, Inc., or its affiliates.
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
import numpy as np
|
|
import hipdnn_frontend as hipdnn
|
|
|
|
|
|
def run_matmul():
|
|
"""
|
|
Minimal sample: build Matmul graph C = A @ B
|
|
"""
|
|
print("=" * 70)
|
|
print("Matmul Test")
|
|
print("=" * 70)
|
|
|
|
# Dimensions: A [M, K], B [K, N] -> C [M, N]
|
|
M, K, N = 4, 3, 5
|
|
|
|
# Create a handle and graph
|
|
print("\nCreating hipdnn handle...")
|
|
handle = hipdnn.create_handle()
|
|
|
|
graph = hipdnn.Graph()
|
|
graph.set_name("matmul_graph")
|
|
graph.set_io_data_type(hipdnn.DataType.FLOAT)
|
|
graph.set_intermediate_data_type(hipdnn.DataType.FLOAT)
|
|
graph.set_compute_data_type(hipdnn.DataType.FLOAT)
|
|
print("Graph created with FLOAT data type")
|
|
|
|
# Create input tensors
|
|
print("\nCreating tensors...")
|
|
a = hipdnn.Tensor.create([M, K], hipdnn.DataType.FLOAT)
|
|
a.set_name("A")
|
|
b = hipdnn.Tensor.create([K, N], hipdnn.DataType.FLOAT)
|
|
b.set_name("B")
|
|
print(f" A: shape={[M, K]}, uid={a.get_uid()}")
|
|
print(f" B: shape={[K, N]}, uid={b.get_uid()}")
|
|
|
|
# Matmul attributes
|
|
attrs = hipdnn.MatmulAttributes()
|
|
attrs.set_name("matmul_node")
|
|
|
|
print("\nBuilding matmul operation...")
|
|
c = graph.matmul(a, b, attrs)
|
|
if c:
|
|
c.set_name("C")
|
|
c.set_output(True)
|
|
print(f" C: shape={[M, N]}, uid={c.get_uid()}")
|
|
|
|
# Validate, build, and prepare execution
|
|
print("\nValidating graph...")
|
|
validation_result = graph.validate()
|
|
if validation_result.is_good():
|
|
print("✓ Graph validation successful!")
|
|
else:
|
|
print(f"✗ Graph validation failed: {validation_result.get_message()}")
|
|
return
|
|
|
|
print("\nBuilding operation graph...")
|
|
build_result = graph.build_operation_graph(handle)
|
|
if build_result.is_good():
|
|
print("✓ Operation graph built successfully")
|
|
else:
|
|
print(f"✗ Failed to build operation graph: {build_result.get_message()}")
|
|
return
|
|
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
run_matmul()
|
|
except Exception as e:
|
|
print(f"\nError: {e}")
|
|
import traceback
|
|
|
|
traceback.print_exc()
|