diff --git a/libc/cmake/modules/prepare_libc_gpu_build.cmake b/libc/cmake/modules/prepare_libc_gpu_build.cmake --- a/libc/cmake/modules/prepare_libc_gpu_build.cmake +++ b/libc/cmake/modules/prepare_libc_gpu_build.cmake @@ -29,18 +29,20 @@ "GPU.") endif() +# Identify any locally installed GPUs to use for testing. find_program(LIBC_AMDGPU_ARCH NAMES amdgpu-arch PATHS ${LLVM_BINARY_DIR}/bin /opt/rocm/llvm/bin/) -if (LIBC_AMDGPU_ARCH) +if(LIBC_AMDGPU_ARCH) execute_process(COMMAND ${LIBC_AMDGPU_ARCH} OUTPUT_VARIABLE LIBC_AMDGPU_ARCH_OUTPUT OUTPUT_STRIP_TRAILING_WHITESPACE) - string(REPLACE "\n" ";" LIBC_AMDGPU_ARCH_OUTPUT "${LIBC_AMDGPU_ARCH_OUTPUT}") - - list(LENGTH "${LIBC_AMDGPU_ARCH_OUTPUT}" LEN) - message(WARNING ${LEN}) - message(WARNING ${LIBC_AMDGPU_ARCH_OUTPUT}) - list(POP_BACK ${LIBC_AMDGPU_ARCH_OUTPUT} OUT) - message(WARNING ${OUT}) + string(FIND "${LIBC_AMDGPU_ARCH_OUTPUT}" "\n" first_arch_string) + string(SUBSTRING "${LIBC_AMDGPU_ARCH_OUTPUT}" 0 ${first_arch_string} + arch_string) + if(arch_string) + set(LIBC_GPU_TARGET_TRIPLE "amdgcn-amd-amdhsa") + set(LIBC_GPU_TARGET_ARCHITECTURE "${arch_string}") + endif() endif() +# TODO: Check for Nvidia GPUs.