1.   
    Join Date
    Feb 2011
    Posts
    153
    System
    Gigabyte GA-Z77-DS3H
    CPU
    Intel Core i7-3770
    Graphics
    Gigabyte GV-N780OC-3GD (rev. 2.0)
    Online
    MacAndor is offline
    Android Phone iPhone MacBook Pro
    #1

    Fix for OpenCL crash with GK110B based cards


    So...

    You're probably here because you have a GK110B based GPU which crashes with all OpenCL apps. I managed to stop the crashes and here's a guide for y'all.

    THIS WILL STOP THE CRASHES, DOES NOT ADD THE PROPER SUPPORT!

    AFTER UPDATING THE OS, RE-CREATE YOUR OPENCL BACKUP!

    First of all:
    • USE AT OWN RISK, I AM NOT RESPONSIBLE FOR DAMAGE, BLABLABLA (you know the deal...)
    • TESTED ON 10.9.0, 10.9.1, 10.9.2
    • DON'T FORGET TO BACKUP THE FRAMEWORK BEFORE MODIFYING


    What I did:
    • Disabled GPU OpenCL support (FOR ALL GPUs).
    • CPU OpenCL is still supported (NOT IGPU)
    • CUDA is still supported


    What you need:
    • Xcode (for codesigning)
    • A hex editor (I'll be using Hex Fiend)


    Creating a backup:
    There are multiple ways of doing this, but this is what I usually do.

    • Open Terminal

    Code:
    sudo -s
    <enter password>
    cd /System/Library/Frameworks/OpenCL.framework/Versions/A/
    cp OpenCL OpenCL.bkp
    Now you will have the original version as "OpenCL.bkp" next to the modded version
    Caution: after updating the OS re-create the backup because it will be the backup of the older version, and you donít really want to revert to that.

    The Guide:
    1. Create a Certificate for codesigning (if you don't have one already)
      1. Open Keychain Access
      2. Go to Keychain Access > Certificate Assistant > Create a Certificate...
        • Give it a name like "OpenCLFWKCS" (I will use this name later)
        • Identity Type: Self Signed Root
        • Certificate Type: Code Signing
        • Create
    2. Copy the file somewhere where you can edit it (for example to your desktop with Terminal)
      Code:
      cp /System/Library/Frameworks/OpenCL.framework/Versions/A/OpenCL ~/Desktop/OpenCL
    3. Open the editable copy of your OpenCL file in a hex editor
      • For 10.9.0 and 10.9.1
        WARNING: THERE SHOULD ONLY BE ONE MATCH
        Code:
        64-bit
        Replace: E83DE10100F6C3057413
           With: E83DE10100F6C3007413
        32-bit
        Replace: E81EF901008B4508A8057418
           With: E81EF901008B4508A8007418
      • For 10.9.2
        WARNING: THERE SHOULD ONLY BE ONE MATCH
        Code:
        64-bit
        Replace: E831E30100F6C3057413
           With: E831E30100F6C3007413
        32-bit
        Replace: 8B4508A80574188D8638010000
           With: 8B4508A80074188D8638010000
      • For 10.9.3 (Quick Thanks to MyAss)
        WARNING: THERE SHOULD ONLY BE ONE MATCH
        Code:
        64-bit
        Replace: E8DFE30100F6C3057413
           With: E8DFE30100F6C3007413
        32-bit
        Replace: 8B4508A80574188D8638010000
           With: 8B4508A80074188D8638010000
    4. Copy back the edited version of the OpenCL file to the framework (with Terminal)
      Code:
      sudo cp ~/Desktop/OpenCL /System/Library/Frameworks/OpenCL.framework/Versions/A/OpenCL
    5. Resign the OpenCL framework
      Code:
      sudo codesign -fs "OpenCLFWKCS" /System/Library/Frameworks/OpenCL.framework/Versions/A/OpenCL
    6. Restart


    How to revert:
    This applies when the backup method was the one mentioned above.

    • Boot chameleon with -s

    Code:
    /sbin/mount -uw /
    cd /System/Library/Frameworks/OpenCL.framework/Versions/A/
    cp OpenCL.bkp OpenCL
    Why I won't share the binary:
    Because I codesigned it sorry

    Caution:
    • Do not share the modified executable
    • Do not share the created certificate


    Tested with:
    Preview (jpg, png), Xcode (assistant view), LuxMark, Safari, Premiere Pro CC (trial) and others

    Fast walkthrough on what I modified:
    When an app is using the OpenCL library nothing special happens until the library gets the first call. When this happens, OpenCL initialises itself.
    This is in the /System/Library/Frameworks/OpenCL.framework/Versions/A/OpenCL file at offset <0x21734> (in 10.9.0 and 10.9.1). (If you wanít to tag along, then you probably need a disassembler)
    This initialisation block contains three pthread_once calls for three different functions.
    • The first probably does some basic initialisation
    • The second initialises CPU support
    • The third initialises GPU support - this is what we donít want

    Lucky for us, this is in an "if" block, which is something like this:
    Code:
    if (x & 5) { pthread_once(...); }
    For non-programmers x & 5 is a bitwise AND operation (http://en.wikipedia.org/wiki/Bitwise_operation#AND)
    If you bitwise AND any value with zero, the result will be zero.

    If we donít want it to call pthread_once, we only need to change the condition to this:
    Code:
    if (x & 0) { pthread_once(...); }
    There is no way it will call it now
    If you look at the patch, this is exactly what I did, the only real difference in the search hex and the replace hex is a 5->0 change.

    Updates:
    - Added 32 & 64-bit patches for 10.9.3, thanks to MyAss
    - Added 32 & 64-bit patches for 10.9.2, guide is more verbose
    - Added 32-bit patch for 10.9.0 and 10.9.1

  2.   
    Join Date
    Aug 2010
    Posts
    469
    System
    GA-Z77X-UP5 TH
    CPU
    3770K
    Graphics
    HD4000 & GTX 770
    Geekbench Score
    17026
    Online
    genzai is offline
    iPhone MacBook Air Mac Mini
    #2

    Fix for OpenCL crash with GK110B based cards


    Quote Originally Posted by MacAndor View Post

    Detailed description of what the hell I did will come a bit later.
    Thank you. Very clear. very straightforward. I am interested how you found that bit of binary mod goodness

    One question... Why caution against sharing the modified (unsigned) executable? then people could just sign it themselves and avoid the hex editing if they wanted.

    Thanks,
    g\

  3.   
    Join Date
    Feb 2011
    Posts
    153
    System
    Gigabyte GA-Z77-DS3H
    CPU
    Intel Core i7-3770
    Graphics
    Gigabyte GV-N780OC-3GD (rev. 2.0)
    Online
    MacAndor is offline
    Android Phone iPhone MacBook Pro
    #3

    Fix for OpenCL crash with GK110B based cards


    Quote Originally Posted by genzai View Post
    Thank you. Very clear. very straightforward. I am interested how you found that bit of binary mod goodness

    One question... Why caution against sharing the modified (unsigned) executable? then people could just sign it themselves and avoid the hex editing if they wanted.

    Thanks,
    g\
    It took me a few days to check how the system handles OpenCL. This took a considerable amount of disassembling (drivers, graphics libraries) and reading all that. Thankfully I have experience with arm, x86 and x86-64 assembly code, so I could understand it fairly easily. After understanding the workings of it, it was only a question of where the modification would be the best.

    I already made a walkthrough but I didn't publish it because I'm not sure if that complies with tonymac forum rules, so I sent them a question whether it's ok or not.

    On the caution part, the OpenCL framework is not part of Apple's open source packages. Thus distributing the executable is probably not legal. There's a fair chance that no one in the world would give a sh*t, but in my opinion, better be safe then sorry.

  4. Administrator
      
    Join Date
    Nov 2009
    Posts
    6,269
    System
    GA-Z87X-UD7-TH
    CPU
    i7-4770K
    Graphics
    GTX 770
    Online
    tonymacx86 is offline
    iPhone MacBook Pro Mac Mini Apple PowerBook
    #4

    Fix for OpenCL crash with GK110B based cards


    Good work! Sure- go ahead and post the experimental files and guide for people to test. Unfortunately I dont have a 780 or 780 Ti to test, but I'll be following along!


  5.   
    Join Date
    Feb 2011
    Posts
    153
    System
    Gigabyte GA-Z77-DS3H
    CPU
    Intel Core i7-3770
    Graphics
    Gigabyte GV-N780OC-3GD (rev. 2.0)
    Online
    MacAndor is offline
    Android Phone iPhone MacBook Pro
    #5

    Fix for OpenCL crash with GK110B based cards


    Quote Originally Posted by tonymacx86 View Post
    Good work! Sure- go ahead and post the experimental files and guide for people to test. Unfortunately I dont have a 780 or 780 Ti to test, but I'll be following along!

    Thanks! Updated the first post with small walkthrough.

  6.   
    Join Date
    Sep 2011
    Posts
    17
    System
    Mavericks 10.9.1
    CPU
    Intel Core i5-2500K
    Graphics
    nVidia GTX 780Ti
    Online
    BaskoRazglas is offline
    iPhone MacBook Air
    #6

    Fix for OpenCL crash with GK110B based cards


    Awesome work, thanks a lot!

    Just a quick question, before I attempt this. Once NVIDIA, hopefully, sees the light, and implements OpenCL support for GK100b, what steps will I need to take make it fully GPU-accelerated again?

    And... can you please provide some info for us completely coding-illeterates. What does "backing up the framework" mean? I know that "if you don't know that, you probably shouldn't attempt this" but I'm without my OSX for a month now so I'm ready for an "all in" approach

  7.   
    Join Date
    Feb 2011
    Posts
    153
    System
    Gigabyte GA-Z77-DS3H
    CPU
    Intel Core i7-3770
    Graphics
    Gigabyte GV-N780OC-3GD (rev. 2.0)
    Online
    MacAndor is offline
    Android Phone iPhone MacBook Pro
    #7

    Fix for OpenCL crash with GK110B based cards


    Quote Originally Posted by BaskoRazglas View Post
    Awesome work, thanks a lot!

    Just a quick question, before I attempt this. Once NVIDIA, hopefully, sees the light, and implements OpenCL support for GK100b, what steps will I need to take make it fully GPU-accelerated again?

    And... can you please provide some info for us completely coding-illeterates. What does "backing up the framework" mean? I know that "if you don't know that, you probably shouldn't attempt this" but I'm without my OSX for a month now so I'm ready for an "all in" approach
    Updated first post.
    Making it fully GPU-accelerated again is the same as the "How to revert" part, but you don't need to boot chameleon with -s, you can simply open Terminal, type sudo -s and do the cd and cp commands (which are in the description).

  8.   
    Join Date
    Jun 2013
    Posts
    46
    System
    Gigabyte GA-Z87X-UD5H
    CPU
    Core i7-4770K
    Graphics
    EVGA 03G-P4-3784-KR GeForce GTX 780
    Online
    SquishyTia is offline
    Android Phone Mac Pro PowerMac Quadra
    #8

    Fix for OpenCL crash with GK110B based cards


    Thank you, MacAndor, for taking the time to find this workaround for us. I know it isn't "ideal", but it gets the job done and lets us have a relatively stable system as a result. Beggars can't be choosers.
    My Build: Gigabyte GA-Z87X-UD5H - Core i7-4770K - EVGA 03G-P4-3784-KR GeForce GTX 780

  9.   
    Join Date
    Feb 2011
    Posts
    153
    System
    Gigabyte GA-Z77-DS3H
    CPU
    Intel Core i7-3770
    Graphics
    Gigabyte GV-N780OC-3GD (rev. 2.0)
    Online
    MacAndor is offline
    Android Phone iPhone MacBook Pro
    #9

    Fix for OpenCL crash with GK110B based cards


    I'm happy this doesn't only solve my problem

  10. Join Date
    Aug 2013
    Posts
    39
    Online
    Crazylegsmurphy is offline
    #10

    Fix for OpenCL crash with GK110B based cards


    Awesome job!

    I do have a few questions before I move forward with this, if you don't mind. While I enjoy making my computer work, I also like learning as I go.

    1. What exactly is this doing, and why does this work?

    2. What, if any other issues could we see by doing this (will it cause other programs to stop working, ie. Adobe products)?

    3. Do we have to have developer status, or can anyone make this work?

    4. What are the risks (hardware/software) in doing this?

    Thanks for your time figuring this out, and for providing the info!

Page 1 of 21 12311 ... Last