+ "rocshmem_test.py": "import torch\nfrom torch.utils.cpp_extension import load_inline\nimport os\n\ndef test_rocshmem_compilation():\n \"\"\"Test ROCshmem compilation using PyTorch's load_inline\"\"\"\n \n print(\"=== ROCshmem PyTorch Inline Test ===\")\n \n # C++ source code for ROCshmem test\n cpp_source = \"\"\"\n #include <rocshmem.hpp>\n #include <iostream>\n #include <torch/extension.h>\n \n void test_rocshmem() {\n std::cout << \"Testing ROCshmem compilation...\" << std::endl;\n \n // Just test that we can compile and link with rocshmem\n // Don't actually initialize since we may not have proper MPI setup\n std::cout << \"ROCshmem headers included successfully!\" << std::endl;\n std::cout << \"Compilation test passed!\" << std::endl;\n }\n \n PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {\n m.def(\"test_rocshmem\", &test_rocshmem, \"Test ROCshmem compilation\");\n }\n \"\"\"\n \n # Set up include paths and libraries\n rocm_path = os.environ.get('ROCM_PATH', '/opt/rocm')\n rocshmem_path = os.environ.get('ROCSHMEM_INSTALL_DIR', '/home/runner/rocshmem')\n ompi_path = os.environ.get('OMPI_INSTALL_DIR', '/opt/openmpi')\n\n include_dirs = [\n f\"{rocm_path}/include\",\n f\"{rocshmem_path}/include/rocshmem\",\n f\"{ompi_path}/include\"\n ]\n\n library_dirs = [\n f\"{rocm_path}/lib\",\n f\"{rocshmem_path}/lib\",\n f\"{ompi_path}/lib\"\n ]\n\n libraries = [\n \"rocshmem\",\n \"mpi\", \n \"amdhip64\",\n \"hsa-runtime64\"\n ]\n\n ldflags = []\n for lib_dir in library_dirs:\n ldflags.append(f\"-L{lib_dir}\")\n\n for lib in libraries:\n ldflags.append(f\"-l{lib}\")\n\n extra_cflags = [f\"-I{include_dir}\" for include_dir in include_dirs]\n\n extra_ldflags = [\n \"--hip-link\"\n ] + ldflags\n \n try:\n # Use torch.utils.cpp_extension.load_inline to compile\n rocshmem_module = load_inline(\n name=\"rocshmem_test\",\n cpp_sources=cpp_source,\n extra_cflags=extra_cflags,\n extra_ldflags=extra_ldflags,\n verbose=True\n )\n \n print(\"Compilation successful!\")\n print(\"Linking successful!\")\n \n # Run the test\n rocshmem_module.test_rocshmem()\n \n print(\"ROCshmem test completed successfully!\")\n return True\n \n except Exception as e:\n print(f\"ROCshmem test failed: {e}\")\n return False\n\nif __name__ == \"__main__\":\n test_rocshmem_compilation()"
0 commit comments