Skip to content

MacOS Support#1073

Closed
pvelesko wants to merge 47 commits intomainfrom
macos-clean
Closed

MacOS Support#1073
pvelesko wants to merge 47 commits intomainfrom
macos-clean

Conversation

@pvelesko
Copy link
Copy Markdown
Collaborator

Test Results

Test Pass Rate: 96% (1034/1079 tests passing)

Failing Tests (45 tests - 4%)

  1. Double precision operations (6 tests) and Atomic operations (10 tests) - POCL crashes during clLinkProgram so we have to skip runtime device linking

  2. Host memory registration (6 tests) - Error: hipErrorInvalidValue (Host memory is already registered!)

  3. Stream callbacks (3 tests) - Error: Segmentation fault (exit code 139) Callback execution crashes in POCL callback handlers

Platform Adaptations

LLVM (llvm-project)

  • HipAbortPass: Fixed 4 segmentation faults (null checks, iterator use-after-erase)
  • AlignedAllocation.h: Added UnknownOS handling for SPIRV targets
  • Darwin toolchain: Fixed assertion errors for spirv64 offload targets

chipStar

  • Guarded malloc.h includes with __APPLE__ checks
  • Added memalign() wrapper using posix_memalign() for macOS
  • Replaced Linux-specific headers (linux/limits.h, sys/sysinfo.h) with POSIX alternatives
  • Fixed device code clock() function for macOS (uses busy-wait instead)
  • Platform-specific device memory queries using sysctl instead of Linux /proc

HIP Submodule

  • Removed stdc++fs linking requirement on macOS (filesystem library built into libc++)
  • Fixed hip_test_common.hh device code to work on macOS
  • Platform guards for Windows-specific tests (windows.h)
  • Platform guards for Linux-specific IPC tests (fork, shmat, ftok)

HIPCC

  • Removed libstdc++fs linking on macOS (filesystem in libc++)
  • Fixed executable path detection using macOS _NSGetExecutablePath() instead of /proc/self/exe
  • Added platform-specific path resolution in getExecutablePath()

@pvelesko pvelesko mentioned this pull request Oct 27, 2025
17 tasks
@pvelesko pvelesko force-pushed the macos-clean branch 29 times, most recently from d684b49 to 4b149b0 Compare October 31, 2025 10:27
pvelesko and others added 26 commits January 12, 2026 12:29
- Add conditional includes with HIP_ENABLE_IF, HIP_IS_* macros
- Add is_signed and is_convertible template specializations
- Replace std::enable_if with HIP_ENABLE_IF throughout
- Replace std::is_integral/signed/convertible with HIP_IS_* macros
- Allows vector types to work in device compilation without std headers
Add template helper to extract element type from vector types,
fixing initialization to properly cast random values to the
correct element type before constructing vectors.
- Add null checks for CGN->getFunction() in getInvertedCGNode
- Add null checks in getOrCreateInvertedCGNode
- Fix use-after-erase bug in popAny function
- Add null checks throughout analyze and processFunctions
- Fix logic bug in mayCallAbort (was checking wrong condition)
- Remove LLVM version conditionals for getNextNonDebugInstruction
- Add explicit static_cast to float/double for math function calls
- Add type_casting_intrinsics.hh include to RegressionTest302
- Fix ambiguous function overload resolution for int arguments
Remove device variable that causes hipspv-link to hang, use constant
value instead. Add hipDeviceSynchronize and proper cleanup.
Wrap host-only includes and main function in __HIP_DEVICE_COMPILE__
guards to prevent host-only code from being processed during device
compilation.
Always use CL/opencl.h instead of Apple's OpenCL/opencl.h framework
headers, to use chipStar's bundled headers consistently.
Completed commits 3, 11, 13-20. Commits 22-30 require structural
changes from macos-clean that have inheritance incompatibilities.
When getKernelByName fails, log all available kernel names to help
diagnose kernel lookup issues.
For unified/SVM memory (like POCL), HostPtr is initially set to DevPtr.
Only error if HostPtr is already set to a DIFFERENT pointer.
- Add CL_DEPRECATED and CL_EXT_SUFFIX__VERSION_* macros for compatibility
- Rename cl_mem_device_address_EXT to cl_mem_device_address_ext (lowercase)
The macos-clean version removed the PASSED output but ctest requires
it to match the PASS regex.
Check if any device variable actually has an initializer before running
the reset kernel. This prevents crashes/hangs when the compiler optimizes
away device variables but the reset kernel still tries to access them.
When there's only one program object (no device libraries), build
directly instead of linking. Also add diagnostic logging for program
binary types when linking multiple objects.
The reset kernel handles both global device variables and static local
variables in device functions. Don't skip it based on global device
variable initializers - static locals need it too.
Add dumpSpirv overload that accepts a name parameter to generate
more descriptive filenames: hip-spirv-<name>-<hash>.spv

In SPVRegister.cc:
- Add getExecutableName() helper (supports macOS and Linux)
- Update SPIR-V dump calls to include executable name in filename

In CHIPBackendOpenCL.cc:
- Update AppendSource lambda to log runtime object names
- Dump runtime device libraries with their function names
  (e.g. atomicAddFloat_native, atomicAddDouble_emulation, ballot_native)

This makes it easier to identify which SPIR-V binaries belong to which
executable or runtime component when debugging.
On macOS (clvk), hipMalloc uses hipMemoryTypeUnified for proper SVM
semantics. On other platforms (POCL, Intel OpenCL, Level Zero), use
hipMemoryTypeDevice which is better supported.
…Vars

Changed early-return condition from OR to AND logic. The reset kernel
must run when it exists, even if ChipVars_ is empty, because static
local variables in device functions are not tracked in ChipVars_ but
still need to be reset by NonSymbolResetKernel.

Fixes hipTestResetStaticVar failure where static local Counter was not
reset to initial value after hipDeviceReset().
- Add LLVM library linking for MODULE targets on macOS
- Use sched_yield instead of pthread_yield on Apple platforms
- Add platform-specific dladdr for finding library path on macOS
- Add minimal ELF definitions for spirv-extractor on macOS
- Cast pthread_t to void* for spdlog formatting on macOS
- Update HIP and HIPCC submodules to macos branches
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant