Cuda Clang and OS X Mavericks

后端 未结 6 1121
遇见更好的自我
遇见更好的自我 2020-11-29 09:37

I\'m currently trying to build a Cuda project with Cmake on MacOS 10.9. My C and C++ compiler are gcc, but it seems that since Mavericks gcc and g++ links to clang, which is

相关标签:
6条回答
  • 2020-11-29 10:08

    The problem actually was there before OS X Mavericks, I had the same problem with Moutain Lion and the answer from Eugene is 100% correct.

    However, it seems that my Geforce card is not recognized as a CUDA capable device since the upgrade to Mavericks and it seems that people using softwares that use CUDA are having the same problems.

    So better not update right now

    0 讨论(0)
  • 2020-11-29 10:18

    Here's a Homebrew recipe that works for me on Lion.

    $ brew cat memtestG80
    require "formula"
    
    # Documentation: https://github.com/Homebrew/homebrew/wiki/Formula-Cookbook
    #                /usr/local/Library/Contributions/example-formula.rb
    # PLEASE REMOVE ALL GENERATED COMMENTS BEFORE SUBMITTING YOUR PULL REQUEST!
    
    # Requires at compile time nvcc from https://developer.nvidia.com/cuda-downloads
    
    # Requires popt at compile time
    
    class Memtestg80 < Formula
      homepage ""
      url "https://github.com/ihaque/memtestG80/archive/master.zip"
      sha1 ""
      version "c4336a69fff07945c322d6c7fc40b0b12341cc4c"
    
      # depends_on "cmake" => :build
      depends_on :x11 # if your formula requires any X11/XQuartz components
    
      def install
        # ENV.deparallelize  # if your formula fails when building in parallel
    
        system "make", "-f", "Makefiles/Makefile.osx", "NVCC=/usr/local/cuda/bin/nvcc -ccbin /usr/bin/clang", "POPT_DIR=/usr/local/Cellar/popt/1.16/lib"
        system "cp", "-a", "memtestG80", "/usr/local/bin"
      end
    
      test do
        # `test do` will create, run in and delete a temporary directory.
        #
        # This test will fail and we won't accept that! It's enough to just replace
        # "false" with the main program this formula installs, but it'd be nice if you
        # were more thorough. Run the test with `brew test memtestG80`.
        #
        # The installed folder is not in the path, so use the entire path to any
        # executables being tested: `system "#{bin}/program", "do", "something"`.
        system "false"
      end
    end
    
    0 讨论(0)
  • 2020-11-29 10:20

    The issue with 10.9 is that gcc is actually clang. Please try latest CUDA toolkit and explicitely point NVCC to use /usr/bin/clang (nvcc -ccbin /usr/bin/clang). This way NVCC will know it's dealing with clang.

    0 讨论(0)
  • 2020-11-29 10:22

    I have just downloaded CUDA 5.5, installed under Mac OSX 10.8.5, with Xcode 5.0.2, and updated command line tools in Xcode. But I couldn't get the CUDA sample "nbody" to compile. I got all kinds of funny error messages, like

     clang error: unsupported option '-dumpspecs'
    I thought I had solved that one by the help of some other web pages, but then other problems kept creeping up (e.g., GLEW not found, CUDA samples path undefined, ...). (And the provided makefiles and cmake files seemed just too contrived, so that I couldn't find the bug.)

    So I rolled my own makefile. I'm posting it here, in the hope that it might help others save some hours.

        #!/usr/bin/make -R
    
        # Simple Makefile for a CUDA sample program
        # (because the provided ones don't work! :-( )
        #
        # We assume that all files in this directory produce one executable.
        # Set your GPU version in variable NVCC below
        #
        # Developed and tested under Mac OS X 10.8.5;
        # under Linux, you probably need to adjust a few paths, compiler options, and #ifdef's.
        #
        # Prerequisites:
        # - CUDA 5.5
        # - The "Command Line Tools" installed via XCode 5
        # - DYLD_FALLBACK_LIBRARY_PATH or DYLD_LIBRARY_PATH must include
        #      /Developer/NVIDIA/CUDA-5.5/lib:/Developer/NVIDIA/CUDA-5.5/samples/common/lib/darwin
        #
        # GZ Dec 2013
    
    
        # -------- variables and settings ---------
        #
    
        CUDA := /Developer/NVIDIA/CUDA-5.5
    
        NVCC := nvcc -ccbin /usr/bin/clang -arch=sm_30 --compiler-options -Wall,-ansi,-Wno-extra-tokens
        #  -ccbin /usr/bin/clang  is needed with XCode 5 under OSX 10.8
        #  -arch=sm_30  is needed for my laptop (it does not provide sm_35)
    
        INCFLAGS := -I $(CUDA)/samples/common/inc
    
        TARGET := nbody
    
        OBJDIR := obj
    
        MAKEFLAGS := kR
    
        .SUFFIXES: .cu .cpp .h
    
        ALLSOURCES := $(wildcard *.cu *.cpp)
        ALLFILES := $(basename $(ALLSOURCES))
        ALLOBJS := $(addsuffix .o,$(addprefix $(OBJDIR)/,$(ALLFILES)))
    
        DEPDIR := depend
    
        # --------- automatic targets --------------
    
        .PHONY: all
        all: $(OBJDIR) $(DEPDIR) $(TARGET) 
            @true
    
        $(OBJDIR):
            mkdir $@
    
    
        # --------- generic rules --------------
    
        UNAME = $(shell uname)
        ifeq ($(UNAME), Darwin)  # Mac OS X
        # OpenGL and GLUT are frameworks
        LDFLAGS = -Xlinker -framework,OpenGL,-framework,GLUT,-L,$(CUDA)/samples/common/lib/darwin,-lGLEW
        endif
    
        $(TARGET): $(ALLOBJS)
            $(NVCC) $^ $(LDFLAGS) -o $@
    
        $(OBJDIR)/%.o: %.cu
            $(NVCC) -c $(INCFLAGS) $ $@
    
        $(DEPDIR)/%.d : %.cpp $(DEPDIR)
            @echo creating dependencies for $ $@
    
        $(DEPDIR):
            mkdir $@
    
    
        # ------ administrative stuff -------
    
        .PHONY: clean
    
        clean:
            rm -f *.o $(TARGET)
            rm -rf $(DEPDIR) $(OBJDIR)
    
    
        echo:
            @echo $(ALLSOURCES)
            @echo $(ALLFILES)
            @echo $(ALLOBJS)
    
    
    0 讨论(0)
  • 2020-11-29 10:28

    Clang become the default compiler with OsX Maverick release, gcc and g++ commands are redirected to the clang compiler. You can download gcc compiler via homebrew and link gcc and g++ commands back to the gcc compiler via following the steps below.

    $ brew install gcc48
    [...]
    
    $ sudo mkdir /usr/bin/backup && sudo mv /usr/bin/gcc /usr/bin/g++ /usr/bin/backup
    $ sudo ln -s /usr/local/bin/gcc-4.8 /usr/bin/gcc
    $ sudo ln -s /usr/local/bin/g++-4.8 /usr/bin/g++
    

    I have found the solution on this article: http://gvsmirnov.ru/blog/tech/2014/02/07/building-openjdk-8-on-osx-maverick.html#all-you-had-to-do-was-follow-the-damn-train-cj

    0 讨论(0)
  • 2020-11-29 10:30

    This is an extension of the answer provided by Eugene:

    The CUDA toolkit download for Mac OSX 10.9 has been posted to the CUDA download page

    It supports XCode 5 on 10.9, and will automatically use clang instead of gcc, FYI.

    IF you are using XCode 5 on 10.8, please see the release notes:

    · On Mac OS X 10.8, if you install XCode 5, including the command-line tools, the gcc compiler will get replaced with clang. You can continue to successfully compile with nvcc from the command-line by using the --ccbin /usr/bin/clang option, which instructs nvcc to use the clang compiler instead of gcc to compile any host code passed to it. However, this solution will not work when building with NSight Eclipse Edition. An alternative solution that will work from the command-line and with NSight Eclipse Edition is to download an older version of the command-line tools package from the Apple Developer website after installing XCode 5, which will re-install gcc to /usr/bin. In order to do this, go to

    http://developer.apple.com/downloads/index.action

    sign in with your Apple ID, and search for command-line tools using the search pane on the left side of the screen.

    0 讨论(0)
提交回复
热议问题