FindOpenCL.cmake - For Windows with Intel's SDK

322 views
Skip to first unread message

C B

unread,
May 22, 2021, 11:15:14 PM5/22/21
to amgcl
Hello Denis and All,

Perhaps anyone has figured out this already:
And it creates this env var:
INTELOCLSDKROOT=C:\Program Files (x86)\IntelSWTools\system_studio_2020\OpenCL\sdk\

Using  INTELOCLSDKROOT  I customized FindOpenCL.cmake (attached file) and placed it in dir  amgcl-master\cmake,
but still cmake is not processing it .....

If anyone has figured out how to get this done with Intel's SDK or other current SDK, please let me know.

Cheers,

FindOpenCL.cmake

Denis Demidov

unread,
May 23, 2021, 1:51:34 AM5/23/21
to amgcl
FindOpenCL.cmake copy in amgcl is only used with ancient versions of CMake:

https://github.com/ddemidov/amgcl/blob/61d219699005743338a41768c41bca0a8678d24e/CMakeLists.txt#L18-L21

After that, FindOpenCL is part of cmake distribution. I don't have access to a windows machine, but you should be able to manually set cmake variables (these should be in "advanced" section) OpenCL_INCLUDE_DIR (the path which has CL/opencl.h) and OpenCL_LIBRARY (the path to OpenCL.dll).

C B

unread,
May 23, 2021, 2:35:15 PM5/23/21
to Denis Demidov, amgcl
Denis,
Thank you so much for these pointers.
I included the two variables as shown below:
image.png
and rebuild all of AMGCL, and I do not see any differences, in the examples generated amgcl-master\build\examples\Release,
now I have a more fundamental question, are there any OpenCL examples ?
I tried searching in all *.c* and *.h* files for cl.h cl_device..... etc and I could not find any instances, 
I would need your help to understand how to determine when OpenCL is being used :).

On a related aspect, I see that my CUDA driver also has OpenCL 
image.png
does this mean that we can use the CUDA SDK to build OpenCL codes that run on AMD cards ?

And I see that oneAPI also has an OpenCL version:
image.png
I may try the 3 of them once I know how to test with OpenCL :)

Lastly I always have this problem when building all of AMGCL, I have not needed the 8 exes that fail, so I never paid attention, but perhaps is easy for you to spot the issue (same for all 8 failures on my setup):
poisson3Db.obj : error LNK2019: unresolved external symbol "class amgcl::profiler<struct amgcl::perf_counter::clock,2> amgcl::prof" (?prof@amgcl@@3V?$profiler@Uclock@perf_counter@amgcl@@$01@1@A) referenced in function "void __cdecl amgcl::backend::axpby<double,class amgcl::backend::numa_vector<double>,double,class std::vector<double,class std::allocator<double> > >(double,class amgcl::backend::numa_vector<double> const &,double,class std::vector<double,class std::allocator<double> > &)" (??$axpby@NV?$numa_vector@N@backend@amgcl@@NV?$vector@NV?$allocator@N@std@@@std@@@backend@amgcl@@YAXNAEBV?$numa_vector@N@01@NAEAV?$vector@NV?$allocator@N@std@@@std@@@Z)

Thanks again for you help !
Regards,


--
You received this message because you are subscribed to the Google Groups "amgcl" group.
To unsubscribe from this group and stop receiving emails from it, send an email to amgcl+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/amgcl/99d3a108-2307-49eb-80e9-627c14b775c5n%40googlegroups.com.

Denis Demidov

unread,
May 23, 2021, 2:53:31 PM5/23/21
to amgcl
On Sunday, May 23, 2021 at 9:35:15 PM UTC+3 cebau...@gmail.com wrote:
Denis,
Thank you so much for these pointers.
I included the two variables as shown below:
image.png

OpenCL_LIBRARY should be the name of the library (a dll file), not the folder containing the library, I think.

 
and rebuild all of AMGCL, and I do not see any differences, in the examples generated amgcl-master\build\examples\Release,
now I have a more fundamental question, are there any OpenCL examples ?

You need to use VexCL backend in order to use OpenCL. It should be enough to clone and configure the VexCL library somewhere
for AMGCL cmake to pick it up:

Here are some examples:

CUDA backend
./solver_cuda -n 128
NVIDIA GeForce GTX 1050 Ti

Solver
======
Type:             BiCGStab
Unknowns:         2097152
Memory footprint: 112.00 M

Preconditioner
==============
Number of levels:    4
Operator complexity: 1.62
Grid complexity:     1.13
Memory footprint:    567.74 M

level     unknowns       nonzeros      memory
---------------------------------------------
    0      2097152       14581760    422.42 M (61.61%)
    1       263552        7918340    127.63 M (33.46%)
    2        16128        1114704     15.07 M ( 4.71%)
    3          789          53055      2.62 M ( 0.22%)

Iterations: 10
Error:      2.50965e-09

[Profile:          2.096 s] (100.00%)
[ self:            0.240 s] ( 11.44%)
[  assembling:     0.152 s] (  7.23%)
[  setup:          1.146 s] ( 54.66%)
[  solve:          0.559 s] ( 26.66%)

VexCL backend with CUDA
./solver_vexcl_cuda -n 128
1. NVIDIA GeForce GTX 1050 Ti

...

[Profile:          1.879 s] (100.00%)
[ self:            0.095 s] (  5.05%)
[  assembling:     0.154 s] (  8.21%)
[  setup:          1.088 s] ( 57.90%)
[  solve:          0.542 s] ( 28.84%)

 VexCL backend with OpenCL
./solver_vexcl_cl -n 128
1. NVIDIA GeForce GTX 1050 Ti (NVIDIA CUDA)

...

[Profile:          2.165 s] (100.00%)
[ self:            0.097 s] (  4.49%)
[  assembling:     0.158 s] (  7.30%)
[  setup:          1.349 s] ( 62.34%)
[  solve:          0.560 s] ( 25.87%)



I tried searching in all *.c* and *.h* files for cl.h cl_device..... etc and I could not find any instances, 
I would need your help to understand how to determine when OpenCL is being used :).

On a related aspect, I see that my CUDA driver also has OpenCL 
image.png
does this mean that we can use the CUDA SDK to build OpenCL codes that run on AMD cards ?

Yes, the OpenCL kernels are compiled at runtime, and the OpenCL library is dynamically linked, so it is possible to compile a program on one platform and run it on another.
 

And I see that oneAPI also has an OpenCL version:
image.png
I may try the 3 of them once I know how to test with OpenCL :)

Lastly I always have this problem when building all of AMGCL, I have not needed the 8 exes that fail, so I never paid attention, but perhaps is easy for you to spot the issue (same for all 8 failures on my setup):
poisson3Db.obj : error LNK2019: unresolved external symbol "class amgcl::profiler<struct amgcl::perf_counter::clock,2> amgcl::prof" (?prof@amgcl@@3V?$profiler@Uclock@perf_counter@amgcl@@$01@1@A) referenced in function "void __cdecl amgcl::backend::axpby<double,class amgcl::backend::numa_vector<double>,double,class std::vector<double,class std::allocator<double> > >(double,class amgcl::backend::numa_vector<double> const &,double,class std::vector<double,class std::allocator<double> > &)" (??$axpby@NV?$numa_vector@N@backend@amgcl@@NV?$vector@NV?$allocator@N@std@@@std@@@backend@amgcl@@YAXNAEBV?$numa_vector@N@01@NAEAV?$vector@NV?$allocator@N@std@@@std@@@Z)

These look like the examples that do not define a global instance of amgcl::profiler, which is used by AMGCL_TIC/TOC macros when you compile with AMGCL_PROFILING preprocessor definition. You should be able to compile these if you undefine AMGCL_PROFILING.

C B

unread,
May 23, 2021, 5:21:42 PM5/23/21
to Denis Demidov, amgcl
Denis,
Thanks so much for your guidance.

I changed the LIBRARY entry:
image.png
pointing to the .lib file, with static or dynamic we need a .lib for linking, just like with CUDA:
image.png

As you said after removing /DAMGCL_PROFILING all exes linked w/o problems :).

I downloaded VexCL from https://github.com/ddemidov/vexcl and unzipped it creating the dir tree 
image.png

Then when I tried using it with CMAKE, I tried these 4 options:
image.png
image.png
image.png
image.png
And in all cases after "Configure" I get:
image.png
I wonder what may be happening ...why CMAKE is not finding it?
Do I need to set VIENNACL_INCLUDE ?

I read in vexcl-master/DEPENDS.md that VexCL depends on Boost, these are my boost settings:
image.png

Thanks again!
Cheers



Denis Demidov

unread,
May 24, 2021, 12:05:25 AM5/24/21
to amgcl
Carl,

On Monday, May 24, 2021 at 12:21:42 AM UTC+3 cebau...@gmail.com wrote:
Denis,
Thanks so much for your guidance.

I changed the LIBRARY entry:
image.png
pointing to the .lib file, with static or dynamic we need a .lib for linking, just like with CUDA:
image.png

As you said after removing /DAMGCL_PROFILING all exes linked w/o problems :).

I downloaded VexCL from https://github.com/ddemidov/vexcl and unzipped it creating the dir tree 
image.png

Then when I tried using it with CMAKE, I tried these 4 options:
image.png
image.png
image.png
image.png
And in all cases after "Configure" I get:
image.png
I wonder what may be happening ...why CMAKE is not finding it?

You need to configure vexcl first. That is, you need to create the "build" folder inside vexcl and run cmake from there (both "configure" and "generate" stages).
After that, amgcl's cmake should be able to find vexcl automatically.
 
Do I need to set VIENNACL_INCLUDE ?

Only if you decide to use the viennacl backend (http://viennacl.sourceforge.net/)

C B

unread,
May 24, 2021, 3:07:37 AM5/24/21
to Denis Demidov, amgcl
Denis,

Everything is easy when you tell us what to do !!! :)

Cmake works fine with VexCL, however the default configuration is X86:
image.png

And when I try to force x64 with:

image.png

I get this error, even after a fresh unzip from vexcl_master.zip.
If I delete CMakeCache.txt and the CMakeFiles dir, I still get the same error.

BTW, if I continue with X86, everything finishes fine on VexCL, but then AMGCL fails at link time.

I wonder if I am doing something wrong.
Thanks,



Denis Demidov

unread,
May 24, 2021, 7:12:41 AM5/24/21
to amgcl
You have to select the correct generator the first time you invoke the cmake-gui. Something like "Visual Studio v2020 x64" if I remember correctly.
So, I would just delete the build folder and start from scratch.

C B

unread,
May 25, 2021, 12:14:08 AM5/25/21
to Denis Demidov, amgcl
Hi Denis,
Well I ended up editing by hand file CMakeCache.txt based on the CMakeCache.txt from AMGCL/amgcl-master/build.
here below we see that I edited x64 in CMakeCache.txt,
image.png

 but when I press Generate CMAKE makes changes that I can't control,  changes some to Win32, and leaves others unchanged as shown below:

image.png

whereas in AMGCL everything is OK before / after generate:

image.png

At least now 37 out of 39 VexCL tests run fine !!

image.png

Now back in AMGCL, rebuilding only 9 failed:

image.png

And all of them failed for the same reason, they are trying to link with the Win32 CUDA libs !!
image.png

The few Tests done run fine ! :)

image.png

Now running the same example tests that you run:

image.png

And when I try CL it looks like there is a compilation at runtime:

image.png

Then I thought that just with these Defines it would work:

image.png

But it didn't, I got the same error again,
How can I include the Define so that it is used at "runtime" ?
Or perhaps my interpretation is not correct?
Thanks,
Cheers


Denis Demidov

unread,
May 25, 2021, 12:23:42 AM5/25/21
to amgcl
On Tuesday, May 25, 2021 at 7:14:08 AM UTC+3 cebau...@gmail.com wrote:
Hi Denis,
Well I ended up editing by hand file CMakeCache.txt based on the CMakeCache.txt from AMGCL/amgcl-master/build.
here below we see that I edited x64 in CMakeCache.txt,
image.png

 but when I press Generate CMAKE makes changes that I can't control,  changes some to Win32, and leaves others unchanged as shown below:

Again, it would be much easier to reconfigure vexcl from scratch, and just select VSx64 generator in the beginning.
 

image.png

whereas in AMGCL everything is OK before / after generate:

image.png

At least now 37 out of 39 VexCL tests run fine !!

image.png

Now back in AMGCL, rebuilding only 9 failed:

image.png

And all of them failed for the same reason, they are trying to link with the Win32 CUDA libs !!
image.png

The few Tests done run fine ! :)

image.png

Now running the same example tests that you run:

image.png

And when I try CL it looks like there is a compilation at runtime:

image.png

Then I thought that just with these Defines it would work:

image.png

But it didn't, I got the same error again,
How can I include the Define so that it is used at "runtime" ?
Or perhaps my interpretation is not correct?

The error you got means one of your devices (I believe it is the Intel integrated graphics chip) does not support double precision arithmetics.
This is a hardware limitation, so there is nothing you can do with a preprocessor definition.
You can select which device to use with the solver by exporting an environment variable
OCL_DEVICE=Quadro, or OCL_PLATFORM=NVIDIA (see https://vexcl.readthedocs.io/en/latest/initialize.html#device-filters)

C B

unread,
May 25, 2021, 1:52:28 AM5/25/21
to Denis Demidov, amgcl
Denis,
Your 
export OCL_DEVICE=Quadro
fixed my runtime issue :)). Thanks!!
(I need to read the docs, that's hard!)

About x64, this is the only thing that I could find:

image.png
And CMAKE configures w/o errors, and yet it is mixing up Win32 / x64 CUDA's libs, and can't find many, as we see below, so I think this is kind of a CMAKE issue.

image.png

And it is really hard to override what CMAKE does, I even tried to use set() but I could not get what I wanted :)).

Anyway, I am happy because now I can run with CL very many exes that I did not have before.

Thanks!
Cheers


Denis Demidov

unread,
May 25, 2021, 1:58:32 AM5/25/21
to amgcl
On Tuesday, May 25, 2021 at 8:52:28 AM UTC+3 cebau...@gmail.com wrote:
Denis,
Your 
export OCL_DEVICE=Quadro
fixed my runtime issue :)). Thanks!!
(I need to read the docs, that's hard!)

About x64, this is the only thing that I could find:

It is too late to fix at this point. You need to select the correct Generator the first time you configure cmake for vexcl. "Current generator" from your image below is "Visual Studio 15 2017", but it should be something like "Visual Studio 15 2017 x64"

I found this image online, this is the point you should select the correct generator at (the first dropdown list):

Denis Demidov

unread,
May 25, 2021, 1:59:40 AM5/25/21
to amgcl
Looks like the image was not attached correctly, here is the link:

C B

unread,
May 25, 2021, 11:06:32 PM5/25/21
to Denis Demidov, amgcl
Denis,
Like you said, once the build is started, there is no way to change the target Generator.
This is something that bites those like me not familiar with CMAKE kirks.
Now I know, wiping out the build directory is the only way to change the "generator".

And I was able to build both VexCL and AMGCL with zero errors, all targets :).
Thanks again for your help !
Cheers,

Reply all
Reply to author
Forward
0 new messages