# OpenCL, ATI fun and games...  [SOLVED]

## wilf

Hello All,

I am building up a box for running OpenCL against an ATI 5850. I have reached the point where I have wandered off the edge of my knowledge and I'd be very grateful for some useful advice, please.

unpacking and building the stream sdk ati-stream-sdk-v2.01-lnx64 was straightforward, after telling ld where to find the libraries and I can run CLInfo which says  *Quote:*   

> pinky x86_64 # ./CLInfo
> 
> No protocol specified
> 
> Number of platforms:                             1
> ...

 

Great. It can see and use my CPU.

Ah! I need the latest video driver from ATI so that the stream sdk can use the 5850, so off I went bumping into the blocks along the way and resolving problems until all I had left to do was emerge in ati_drivers. *Quote:*   

> pinky opencl # emerge --pretend x11-drivers/ati-drivers.
> 
> These are the packages that would be merged, in order:
> 
> Calculating dependencies... done!
> ...

 At this point I chose to run the driver installation ati-driver-installer-10-4-x86.x86_64.run. You can extract the archive like this:-

```
sh ati-driver-installer-10-4-x86.x86_64.run --extract ati_10.04
```

That all seemed to go swimmingly, /etc/X11/xorg.conf now contains the section 

```
Section "Device"

        Identifier  "aticonfig-Device[0]-0"

        Driver      "fglrx"

        BusID       "PCI:5:0:0"

EndSection
```

 and startx came up with a few windows. When I closed the session, I got the following log... *Quote:*   

> pinky ~ # cat startx.log
> 
> xauth:  creating new authority file /root/.serverauth.4902
> 
> X.Org X Server 1.7.6
> ...

 

My next step was to re-run CLInfo, but it is still not seeing the 5850 and I have a/ run out of ideas b/ run out of useful links from Mr. Google.

Any help will be gratefully appreciated.

Best regards, Paul.Last edited by wilf on Sun May 23, 2010 7:59 am; edited 1 time in total

----------

## wilf

Well, I can see that OpenCL isn't the most exciting topic ATM!

I have done a bit more digging and it was quite obvious when I opened my eyes that the required kernel module fglrx  was not present, a hint was that executing modprobe fglrx failed.

The good news is that the installation had placed the fglrx source in /lib64/modules/fglrx.

I am running a 2.6.34-rc6 kernel although I might build a 2.6.33 kernel as the driver has been known to work with that kernel.

So, building the driver.

I have had a few problems where headers weren't in the places they are in a vanilla kernel, notably include/generated contains headers that fglrx source expects in include/linux so I put some ifdefs in to cope with that.

I have currently hit a problem 

```
pinky build_mod # ./make.sh

AMD kernel module generator version 2.1

OsRelease 2.6.34-rc6, kernel_release=2.6.34-rc6

./make.sh: line 376: [: =: unary operator expected

doing Makefile based build for kernel 2.6.x and higher

rm -rf *.c *.h *.o *.ko *.GCC* .??* *.symvers

make -C /lib/modules/2.6.34-rc6/build SUBDIRS=/lib64/modules/fglrx/build_mod/2.6.x modules

make[1]: Entering directory `/usr/src/linux-2.6.34-rc6'

  CC [M]  /lib64/modules/fglrx/build_mod/2.6.x/firegl_public.o

In file included from /lib64/modules/fglrx/build_mod/2.6.x/firegl_public.c:452:

/lib64/modules/fglrx/build_mod/2.6.x/drm_proc.h: In function 'FGLDRM__vma_info':

/lib64/modules/fglrx/build_mod/2.6.x/drm_proc.h:497: warning: format '%08lx' expects type 'long unsigned int', but argument 5 has type 'phys_addr_t'

/lib64/modules/fglrx/build_mod/2.6.x/firegl_public.c: In function 'KCL_SetPageCache_Array':

/lib64/modules/fglrx/build_mod/2.6.x/firegl_public.c:1325: warning: passing argument 1 of 'KCL_ConvertPageToKernelAddress' makes pointer from integer without a cast

/lib64/modules/fglrx/build_mod/2.6.x/firegl_public.c: In function '__ke__cmpxchg':

/lib64/modules/fglrx/build_mod/2.6.x/firegl_public.c:1482: error: variable or field '__ret' declared void

/lib64/modules/fglrx/build_mod/2.6.x/firegl_public.c:1482: error: variable or field '__old' declared void

/lib64/modules/fglrx/build_mod/2.6.x/firegl_public.c:1482: error: variable or field '__new' declared void

make[2]: *** [/lib64/modules/fglrx/build_mod/2.6.x/firegl_public.o] Error 1

make[1]: *** [_module_/lib64/modules/fglrx/build_mod/2.6.x] Error 2

make[1]: Leaving directory `/usr/src/linux-2.6.34-rc6'

make: *** [kmod_build] Error 2

build failed with return value 2

```

I found a link suggesting this might be a 64 bit related compilation problem so I hacked the Makefile to make sure that the defines set up in /etc/make.conf were being observed but it made no difference.

Again I would be very grateful for any help with this, thanks in advance...

Best regards, Paul.

----------

## wilf

FX: Oooooohh! It's getting exciting.

I love Gentoo, I know it's quiet in here re: OpenCL, but I found this which has a patch which enabled me to build the driver, apart from one further addition of

```
#include <linux/slab.h>
```

 to kcl_wait.c.

Goodness knows what's next. Back to the forums/bugzilla/Mr. Google.

 *Quote:*   

> pinky build_mod # ./make.sh
> 
> AMD kernel module generator version 2.1
> 
> OsRelease 2.6.34-rc6, kernel_release=2.6.34-rc6
> ...

 

I still would like guidance if anyone out there has the requisite skills please.

Best regards, Paul.

----------

## wilf

With module built, the next bit was to install it.

I used the make_install program supplied which isn't very friendly - bombing out with a standard error message almost whatever happens.

```
pinky fglrx # ./make_install.sh verbose verbose

module=fglrx, OS_MOD=/lib64/modules

ModuleFQN=./fglrx.2.6.34-rc6-SMP.ko

AliasFQN=./fglrx.ko

ModuleLogFQN=/lib64/modules/fglrx/make.2.6.34-rc6-SMP.log

major=2, minor=6, patch=34, extra=-rc6, kernel_is_26x=1

TargetFQN=/lib64/modules/2.6.34-rc6/kernel/drivers/char/drm/fglrx.ko

ModuleFQN=./fglrx.2.6.34-rc6-SMP.ko, TargetFQN=/lib64/modules/2.6.34-rc6/kernel/drivers/char/drm/fglrx.ko, NonTargetFQN=

*** WARNING ***

Tailored kernel module for fglrx not present in your system.

You must go to /lib64/modules/fglrx/build_mod subdir

and execute './make.sh' to build a fully customed kernel module.

Afterwards go to /lib64/modules/fglrx and run './make_install.sh'

in order to install the module into your kernel's module repository.

(see readme.txt for more details.)

As of now you can still run your XServer in 2D, but hardware accelerated

OpenGL will not work and 2D graphics will lack performance.

failed.

pinky fglrx # vi make_install.sh

pinky fglrx # ls fglrx.2.6.34-rc6-SMP.ko

ls: cannot access fglrx.2.6.34-rc6-SMP.ko: No such file or directory

pinky fglrx # ls

build_mod  make_install.sh

pinky fglrx # ls build_mod/2.6.x/fglrx

fglrx.ko           fglrx.mod.c        fglrx.mod.o        fglrx.o            fglrxko_pci_ids.h

pinky fglrx # ls build_mod/2.6.x/fglrx.ko

build_mod/2.6.x/fglrx.ko

pinky fglrx # cp !$ .

cp build_mod/2.6.x/fglrx.ko .

pinky fglrx # mv fglrx.ko fglrx.2.6.34-rc6-SMP.ko

pinky fglrx # ./make_install.sh verbose verbose

module=fglrx, OS_MOD=/lib64/modules

ModuleFQN=./fglrx.2.6.34-rc6-SMP.ko

AliasFQN=./fglrx.ko

ModuleLogFQN=/lib64/modules/fglrx/make.2.6.34-rc6-SMP.log

major=2, minor=6, patch=34, extra=-rc6, kernel_is_26x=1

TargetFQN=/lib64/modules/2.6.34-rc6/kernel/drivers/char/drm/fglrx.ko

ModuleFQN=./fglrx.2.6.34-rc6-SMP.ko, TargetFQN=/lib64/modules/2.6.34-rc6/kernel/drivers/char/drm/fglrx.ko, NonTargetFQN=

ModuleFQN exists

kernel module was provided by hardware vendor, OEM or Linux distribution.

** ln -s ./fglrx.2.6.34-rc6-SMP.ko /lib64/modules/2.6.34-rc6/kernel/drivers/char/drm/fglrx.ko

- creating symlink

** depmod

** modprobe

done.

pinky fglrx # modprobe fglrx

pinky fglrx # fglrx

fglrx_xgamma  fglrxinfo

pinky fglrx # fglrxinfo

Error: unable to open display (null)

```

It was looking for the module in the wrong place and the wrong name, I copied the .ko to match the name

```
cp build_mod/2.6.x/fglrx.ko ./fglrx.2.6.33.3-SMP.ko
```

I have just moved back to 2.6.33.3 and recompiled fglrx so I am using the same kernel with fglrx compiled to suit and installed as others who have successfully installed the driver.

```
pinky ~ # uname -r

2.6.33.3
```

I am still getting *Quote:*   

> pinky fglrx # fglrxinfo
> 
> Error: unable to open display (null)

  and if I start X from the console I get *Quote:*   

> pinky ~ # startx
> 
> xauth:  creating new authority file /root/.serverauth.9301
> 
> X.Org X Server 1.7.6
> ...

 lspci gives

```
pinky ~ # lspci

00:00.0 RAM memory: nVidia Corporation MCP65 Memory Controller (rev a3)

00:01.0 ISA bridge: nVidia Corporation MCP65 LPC Bridge (rev a3)

00:01.1 SMBus: nVidia Corporation MCP65 SMBus (rev a1)

00:01.2 RAM memory: nVidia Corporation MCP65 Memory Controller (rev a1)

00:02.0 USB Controller: nVidia Corporation MCP65 USB Controller (rev a3)

00:02.1 USB Controller: nVidia Corporation MCP65 USB Controller (rev a3)

00:06.0 Ethernet controller: nVidia Corporation MCP65 Ethernet (rev a3)

00:08.0 PCI bridge: nVidia Corporation MCP65 PCI bridge (rev a1)

00:09.0 IDE interface: nVidia Corporation MCP65 IDE (rev a1)

00:0a.0 SATA controller: nVidia Corporation MCP65 AHCI Controller (rev a3)

00:0b.0 PCI bridge: nVidia Corporation Device 045b (rev a1)

00:0c.0 PCI bridge: nVidia Corporation MCP65 PCI Express bridge (rev a1)

00:0d.0 PCI bridge: nVidia Corporation MCP65 PCI Express bridge (rev a1)

00:0e.0 PCI bridge: nVidia Corporation MCP65 PCI Express bridge (rev a1)

00:18.0 Host bridge: Advanced Micro Devices [AMD] K8 [Athlon64/Opteron] HyperTransport Technology Configuration

00:18.1 Host bridge: Advanced Micro Devices [AMD] K8 [Athlon64/Opteron] Address Map

00:18.2 Host bridge: Advanced Micro Devices [AMD] K8 [Athlon64/Opteron] DRAM Controller

00:18.3 Host bridge: Advanced Micro Devices [AMD] K8 [Athlon64/Opteron] Miscellaneous Control

05:00.0 VGA compatible controller: ATI Technologies Inc Device 6899

05:00.1 Audio device: ATI Technologies Inc Device aa50
```

 From the XOrg log, it looks like it's trying to open BusID PCI:0@5:0:1 which above is listed as an ATI audio device. Not sure what is going on here.

lsmod gives

```
pinky ~ # lsmod

Module                  Size  Used by

fglrx                2342774  0

```

Right, I really am running out of ideas, help please!

Best regards, Paul.

----------

## wilf

Well, it all goes to show how little I know.

Running 2.6.33.3 and the 10.4 ATI driver, I ran start x, shut it down and checked Xorg.0.log in /var/log.

Looked like it was all working!

So I ran startx again and typed in

```
pinky ~ # cat fglrxinfo.log

display: :0.0  screen: 0

OpenGL vendor string: ATI Technologies Inc.

OpenGL renderer string: ATI Radeon HD 5800 Series

OpenGL version string: 3.2.9756 Compatibility Profile Context
```

Hey Presto! My 5850 is visible!

I expected that once the driver was working, I'd be able to run fglrx specific stuff from any terminal, perhaps as long as some X was running. It seems this is not so, but here is a log of CLInfo executed from an xterm under twm *Quote:*   

> pinky ~ # cat CLInfo.log
> 
> Number of platforms:                             1
> 
>   Plaform Profile:                               FULL_PROFILE
> ...

 FX: Yippee! Success! I also ran the Eigen example too. I would like to know how I can talk to the graphics card with OpenCL if it's possible without my progs being run from within the X environment.

Best regards, Paul.

----------

## wilf

For anyone else trying to install the latest ATI drivers before the relevant ebuilds have been released, I have a couple more 'tidy ups' after completing my installation.

You may think they are ill-advised/inappropriate so any one better informed can correct me.

As long as I have an XSession running on console, I can ssh into the box and run the OpenCL examples such as CLInfo and see the GPU. Success.

After my first reboot, OpenCL was unavailable and I couldn't modprobe the fglrx driver.

I have two relevant kernels installed:-

2.6.33.3

2.6.34-rc6

and I have built the fglrx kernel modules for both.

I created the following directories:-

/lib64/modules/<kernel_version>/kernel/drivers/gpu/drm/fglrx/

and placed the appropriate version kernel module in it's respective target directory and then ran

depmod

After this I was able to modprobe the fglrx driver and it was installed. I was able to startx and OpenCL was available.

I am not sure why OpenCL wouldn't run and just see the CPU's before I loaded fglrx, but hey-ho.

The other item which foxed me for a short while was that GPU OpenCL stopped working after a short while.

It turns out that my XSession was going into screensaver and as X is how OpenCL talks to fglrx, GPU OpenCL stopped working.

So I ran:-

xset s off

xset -dpms

Which did the trick, GPU OpenCL remains available ad infinitum.

xset q

will dump out interesting params about your XSession.

I hope this helps anyone else trying the same thing, good luck.

Best regards, Paul.

----------

## kite14

Hi Paul,

thanks for sharing your findings in this thread.

I bookmarked this page, just in case I feel like trying OpenCL some day...   :Smile: 

Best regards,

Roberto

----------

## brainsalad

FYI, on a fresh Gentoo installation, ATI stream SDK v2.2 installation went smoothly, and it works with my RV770 based HD4870 512MiB  :Very Happy: 

```

[07:05 PM][wix@dubicile:/usr/local/ati-stream-sdk/samples/opencl/bin/x86_64]> ./CLInfo 

Number of platforms:                             1

  Platform Profile:                              FULL_PROFILE

  Platform Version:                              OpenCL 1.1 ATI-Stream-v2.2 (302)

  Platform Name:                                         ATI Stream

  Platform Vendor:                               Advanced Micro Devices, Inc.

  Platform Extensions:                   cl_khr_icd cl_amd_event_callback

  Platform Name:                                         ATI Stream

Number of devices:                               2

  Device Type:                                   CL_DEVICE_TYPE_CPU

  Device ID:                                     4098

  Max compute units:                             4

  Max work items dimensions:                     3

    Max work items[0]:                           1024

    Max work items[1]:                           1024

    Max work items[2]:                           1024

  Max work group size:                           1024

  Preferred vector width char:                   16

  Preferred vector width short:                  8

  Preferred vector width int:                    4

  Preferred vector width long:                   2

  Preferred vector width float:                  4

  Preferred vector width double:                 0

  Max clock frequency:                           2999Mhz

  Address bits:                                  64

  Max memory allocation:                         1073741824

  Image support:                                 No

  Max size of kernel argument:                   4096

  Alignment (bits) of base address:              1024

  Minimum alignment (bytes) for any datatype:    128

  Single precision floating point capability

    Denorms:                                     Yes

    Quiet NaNs:                                  Yes

    Round to nearest even:                       Yes

    Round to zero:                               Yes

    Round to +ve and infinity:                   Yes

    IEEE754-2008 fused multiply-add:             No

  Cache type:                                    Read/Write

  Cache line size:                               64

  Cache size:                                    32768

  Global memory size:                            3221225472

  Constant buffer size:                          65536

  Max number of constant args:                   8

  Local memory type:                             Global

  Local memory size:                             32768

  Profiling timer resolution:                    1

  Device endianess:                              Little

  Available:                                     Yes

  Compiler available:                            Yes

  Execution capabilities:                                

    Execute OpenCL kernels:                      Yes

    Execute native function:                     Yes

  Queue properties:                              

    Out-of-Order:                                No

    Profiling :                                  Yes

  Platform ID:                                   0x7ff8e03d6b20

  Name:                                          Intel(R) Core(TM)2 Extreme CPU X9650  @ 3.00GHz

  Vendor:                                        GenuineIntel

  Driver version:                                2.0

  Profile:                                       FULL_PROFILE

  Version:                                       OpenCL 1.1 ATI-Stream-v2.2 (302)

  Extensions:                                    cl_amd_fp64 cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_byte_addressable_store cl_khr_gl_sharing cl_ext_device_fission cl_amd_device_attribute_query cl_amd_printf 

  Device Type:                                   CL_DEVICE_TYPE_GPU

  Device ID:                                     4098

  Max compute units:                             10

  Max work items dimensions:                     3

    Max work items[0]:                           256

    Max work items[1]:                           256

    Max work items[2]:                           256

  Max work group size:                           256

  Preferred vector width char:                   16

  Preferred vector width short:                  8

  Preferred vector width int:                    4

  Preferred vector width long:                   2

  Preferred vector width float:                  4

  Preferred vector width double:                 0

  Max clock frequency:                           750Mhz

  Address bits:                                  32

  Max memory allocation:                         134217728

  Image support:                                 No

  Max size of kernel argument:                   1024

  Alignment (bits) of base address:              32768

  Minimum alignment (bytes) for any datatype:    128

  Single precision floating point capability

    Denorms:                                     No

    Quiet NaNs:                                  Yes

    Round to nearest even:                       Yes

    Round to zero:                               Yes

    Round to +ve and infinity:                   Yes

    IEEE754-2008 fused multiply-add:             Yes

  Cache type:                                    None

  Cache line size:                               0

  Cache size:                                    0

  Global memory size:                            268435456

  Constant buffer size:                          65536

  Max number of constant args:                   8

  Local memory type:                             Global

  Local memory size:                             16384

  Profiling timer resolution:                    1

  Device endianess:                              Little

  Available:                                     Yes

  Compiler available:                            Yes

  Execution capabilities:                                

    Execute OpenCL kernels:                      Yes

    Execute native function:                     No

  Queue properties:                              

    Out-of-Order:                                No

    Profiling :                                  Yes

  Platform ID:                                   0x7ff8e03d6b20

  Name:                                          ATI RV770

  Vendor:                                        Advanced Micro Devices, Inc.

  Driver version:                                CAL 1.4.736

  Profile:                                       FULL_PROFILE

  Version:                                       OpenCL 1.0 ATI-Stream-v2.2 (302)

  Extensions:                                    cl_khr_icd cl_amd_fp64 cl_khr_gl_sharing cl_amd_device_attribute_query 

Passed!
```

----------

## logical_guy

Hi I'm in the process of installing ati-stream-sdk-bin from the pentoo overlay.

While trying to emerge it, it pulls in ati-drivers, but as my driver chipset is r580, xf86-video-ati is the recommended package over ati-drivers.

I have xf86-video-ati installed, but it still wants to install ati-drivers.

I'm wondering what I can do about this.  Thanks.

----------

## energyman76b

 *logical_guy wrote:*   

> Hi I'm in the process of installing ati-stream-sdk-bin from the pentoo overlay.
> 
> While trying to emerge it, it pulls in ati-drivers, but as my driver chipset is r580, xf86-video-ati is the recommended package over ati-drivers.
> 
> I have xf86-video-ati installed, but it still wants to install ati-drivers.
> ...

 

nothing, you need the binary amd drivers for opencl.

Besides, with such an old card I wonder if opencl is even possible.

----------

