MCPcopy Create free account
hub / github.com/KnowingNothing/MatmulTutorial / KernelHardwareInfo

Class KernelHardwareInfo

cutlass.py/hw_info.py:44–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42
43@dataclass
44class KernelHardwareInfo:
45 device_id: int = 0
46 sm_count: int = 0
47
48 @staticmethod
49 def query_device_multiprocessor_count(device_id: int = 0, arch: str = "90a"):
50 cuda_header_code = f"""
51#include <cuda_runtime.h>
52#include <iostream>
53static constexpr int device_id = {device_id};
54 """
55 cuda_code = """
56int main() {
57 cudaError_t result = cudaSetDevice(device_id);
58 if (result != cudaSuccess) {
59 std::cerr << "cudaSetDevice() returned error "
60 << cudaGetErrorString(result) << std::endl;
61 return 1;
62 }
63 int multiprocessor_count;
64 result = cudaDeviceGetAttribute(&multiprocessor_count,
65 cudaDevAttrMultiProcessorCount, device_id);
66 if (result != cudaSuccess) {
67 std::cerr << "cudaDeviceGetAttribute() returned error "
68 << cudaGetErrorString(result) << std::endl;
69 return 1;
70 }
71 std::cout << multiprocessor_count << std::endl;
72 return 0;
73}
74 """
75 # Combine the header and main CUDA code
76 full_cuda_code = cuda_header_code + cuda_code
77
78 # Write the CUDA code to a temporary file
79 with open("temp_query_device.cu", "w") as file:
80 file.write(full_cuda_code)
81
82 # Compile the CUDA code using nvcc
83 compile_command = (
84 f"nvcc -arch=sm_{arch} temp_query_device.cu -o temp_query_device"
85 )
86 try:
87 subprocess.run(
88 compile_command,
89 check=True,
90 shell=True,
91 text=True,
92 stderr=subprocess.PIPE,
93 )
94 except subprocess.CalledProcessError as e:
95 print(f"Compilation failed: {e.stderr}")
96 return -1
97
98 # Run the compiled binary and capture the output
99 try:
100 result = subprocess.run(
101 "./temp_query_device", capture_output=True, text=True, check=True

Callers 1

tile_scheduler.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected