Introduction
As a relatively new OpenCL user I was looking online for a
guide to setting up OpenCL in visual studio. I have about 9 years development
experience, so I thought this wouldn’t be much of an issue but I did have a
little trouble due to a few details of the setup not being common knowledge. In
this article I’m going to provide step by step instructions on setting up
OpenCL for both nVidia and ATI graphics cards in Visual Studio 2010. I assume
that you have an OpenCL capable graphics card, if you are unsure please check
your manufacturers website or leave a comment and I’ll check for you. In this
tutorial I will be using an nVidia card but I will provide text instructions
for AMD cards.
1.
Installing OpenCL
For nVidia graphics cards you need to install the CUDA
toolkit and development drivers. As of the time of writing the current CUDA
toolkit version was 5.0, this version includes the development drivers in the
toolkit. It can be downloaded here:
For ATI graphics cards you will need to install the AMD APP
SDK (formerly the AMD Stream SDK). This can be downloaded from:
2.
Setting up the Project
First thing
to do is set up an empty VS project by choosing
- ‘New Project->Visual C++->Win32 Console Application'
- Enter a name for the project and choose OK
- In the application creation wizard choose ‘Next’
- Under ‘Additional options’ check the ‘Empty project’ box and click ‘Finish’
3.
Including OpenCL in the Project
The first step in including OpenCL is to create a C++ file,
this enables the configuration options we will need.
- Right click on the ‘Source Files’ folder in the solution explorer and select ‘Add-> New Item’
- Select C++ File and give the file a name
- Click the ‘Add’ button in the bottom right hand corner of the dialog box
- Now we are ready to point the project to the include directories for OpenCL
- Right click on the project name in the solution explorer and select ‘Properties’
- From the ‘Configuration’ drop down box choose ‘All Configurations’
- Navigate to ‘Configuration Properties-> C/C++ -> General’
- In the ‘Additional Include Directories’ field add the following information depending on your graphics card
- nVidia -“$(CUDA_INC_PATH)”
- AMD -“$(AMDAPPSDKROOT)\include”
4.
Linking OpenCL
Now we are going to tell the project where to find the
actual library file which contains OpenCL. This is where the actual
implementation of OpenCL is contained.
Without
closing the dialog box used above:
- Choose ‘Linker-> General’
- In the ‘Additional Dependencies’ field enter the following, again this is based on your card vendor
- nVidia - “$(CUDA_LIB_PATH)”
- AMD - “$(AMDAPPSDKROOT)\lib\x86” (for 64 bit users you may need to change the x86 to x86_64, I have no machine to test this on)
- Still in the ‘Linker’ submenu, select ‘Input’
- In the ‘Additional Dependencies’ field click on the arrow that appears at the end of the field and choose Edit…
- In the dialog that appears enter “OpenCL.lib” (without the quotes obviously J)
- Click OK in the dialog box
- Click OK in the Properties dialog to bring you back to the main IDE
5.
A Note for 64-Bit users
If you are using a 64-bit machine then you will need to add
an x64 target to your project to be able to build it.
- Again open the properties page of your project by right clicking on it and selecting ‘Properties’
- Select ‘Configuration Manager…’ from the top right hand corner of the dialog (if it is greyed out expand ‘Configuration Properties’ on the left hand side to enable it)
- Under ‘Active solution platforms’ select New...
- Under ‘Type or select the new platform’ select x64 and click OK
- Click Close
- Click OK to get back to the main IDE
Your project should now be set up for OpenCL!! Wasn’t that a
breeze ;)
6.
Testing your project
Below is the simplest OpenCL application to test that the
install and configuration have worked. Copy this code into the C++ class that you created at the start of the tutorial:
Click the run button. If you get a console window that opens
and then closes again, then congratulations!!! You have just taken the first
step on your OpenCL/world domination journey. Happy coding guys! If I have made
any errors please leave me a comment and I will correct it ASAP.
I followed your tutorial and got this error:
ReplyDeleteError 1 error C1083: Cannot open include file: 'CL/cl.h': No such file or directory c:\Users\Filip\documents\visual studio 2010\Projects\openCL1\openCL1\opencl.cpp 1 1 openCL1
2 IntelliSense: cannot open source file "CL/cl.h" c:\users\filip\documents\visual studio 2010\projects\opencl1\opencl1\opencl.cpp 1 1 openCL1
Do you know why the file is not recognized?
This means that visual studio isn't finding the cl header files, try looking at the Including OpenCL in the project section again and make sure you followed all the steps correctly. Are you using an nVidia or ATI graphics card and are you sure installed the toolkit corectly?
DeleteHey, just thought I'd let you know:
Delete#include
references your search paths that are configured and
#include "file.h"
references a path relative to your project.
So apparently the comment system strips out the greater-than and less-than signs. Wrap file.h in a greater and less than sign (so it looks like an html tag)
DeleteIf you installed the SDK and haven't restarted your computer that's why you're having this problem.
DeleteSimply restart, so that Environment Variables can take effect.
Kode-Stuff: Setting Up Opencl In Visual Studio >>>>> Download Now
Delete>>>>> Download Full
Kode-Stuff: Setting Up Opencl In Visual Studio >>>>> Download LINK
>>>>> Download Now
Kode-Stuff: Setting Up Opencl In Visual Studio >>>>> Download Full
>>>>> Download LINK Pb
hi i have installed VS 2010 and CUDA tool kit 4.2
ReplyDelete,i did all the steps ;but when i try to crate anew project in VC++ and choose Opencl this message appears "parameter toolFile cannot be null" ; what is going wrong !!!!!!!
Thanks for making this tutorial. I followed another one but it didn't have the x64 part, so I would get errors when trying to compile.
ReplyDeleteHello I just wanted to correct you with the x64 part.
ReplyDeleteIt has to be “$(AMDAPPSDKROOT)\lib\x86_64" iinstead of “$(AMDAPPSDKROOT)\lib\x64"
(atleast in the current version of AMD APP SDK v2.8)
Thanks for the correction, I appreciate it!
DeleteHi
ReplyDeleteI did all the steps above but this error appers to me
q1.obj : error LNK2019: unresolved external symbol _clGetPlatformIDs@12 referenced in function _main
1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\ImportProjects\vcs\q1\Debug\q1.exe : fatal error LNK1120: 1 unresolved externals
can any one help me
Google is your friend here:
DeleteI had the same problem. I thought I had to link with the 64bit library, but the way I set up my Visual Studio compiler, it was the 32 bit library that was the one to use, and then all went well.
Explanation is here:
http://devgurus.amd.com/thread/133986
Thanks, this worked for me for AMD x64!
ReplyDeleteI am getting following error "INK : fatal error LNK1104: cannot open file 'kernel32.lib'" What should I do in this case?
ReplyDeleteC:\Windows\System32\ntdll.dll'. Cannot find or open the PDB file.
ReplyDeletei am getting this error
For me in VS 2012 there was no CUDA_LIB_PATH or CUDA_INC_PATH macroses, was only CUDA_PATH, so I used $(CUDA_PATH)\lib\x64 and $(CUDA_PATH)\include respectively and it worked.
ReplyDeleteThx couldn't get it working without this comment!
Deletehey thanks it was all messed up before i read your comment :) thnks
DeleteThanks, this comment helped for VS 2010.
DeleteThx!
DeleteThank you.
DeleteThanks lobanovadik. Same things happens for visual studio 2015 and cuda 7.5.
DeleteOh my God, it really works! lobanovadik, thank you so much!
Delete(VS 2015 and Nsight Visual Studio Edition 5.1.0)
thank for tutorial!
ReplyDeleteI got a problem when I run code sample
"Unhandled exception at 0x0000000000000000 in OpenCL_Helloworld.exe: 0xC0000005: Access violation executing location 0x0000000000000000."
Hello I am a newby. After following the instructions, I got the following error, please help me.
ReplyDelete1>------ Build started: Project: JayTest, Configuration: Debug Win32 ------
1>D:\OpenCLtestJay\JayTest\JayTest\JayTest.vcxproj : error MSB4014: The build stopped unexpectedly because of an internal failure.
1>D:\OpenCLtestJay\JayTest\JayTest\JayTest.vcxproj : error MSB4014: Microsoft.Build.Exceptions.BuildAbortedException: Build was canceled. MSBuild.exe could not be launched as a child node as it could not be found at the location "C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe". If necessary, specify the correct location in the BuildParameters, or with the MSBUILD_EXE_PATH environment variable.
1>D:\OpenCLtestJay\JayTest\JayTest\JayTest.vcxproj : error MSB4014: at Microsoft.Build.BackEnd.NodeManager.AttemptCreateNode(INodeProvider nodeProvider, NodeConfiguration nodeConfiguration)
1>D:\OpenCLtestJay\JayTest\JayTest\JayTest.vcxproj : error MSB4014: at Microsoft.Build.BackEnd.NodeManager.CreateNode(NodeConfiguration configuration, NodeAffinity nodeAffinity)
1>D:\OpenCLtestJay\JayTest\JayTest\JayTest.vcxproj : error MSB4014: at Microsoft.Build.Execution.BuildManager.PerformSchedulingActions(IEnumerable`1 responses)
1>D:\OpenCLtestJay\JayTest\JayTest\JayTest.vcxproj : error MSB4014: at Microsoft.Build.Execution.BuildManager.HandleNewRequest(Int32 node, BuildRequestBlocker blocker)
1>D:\OpenCLtestJay\JayTest\JayTest\JayTest.vcxproj : error MSB4014: at Microsoft.Build.Execution.BuildManager.IssueRequestToScheduler(BuildSubmission submission, Boolean allowMainThreadBuild, BuildRequestBlocker blocker)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Thanks so far! But, didn't get the "Linker" option in properties for cpp file. Instead put the additional details into project. Had the following two errors.
ReplyDeleteError 1 error LNK2019: unresolved external symbol _clGetPlatformIDs@12 referenced in function _main C:\Users\sony\documents\visual studio 2012\Projects\Parallel01\Parallel01\oicl.obj Parallel01
Error 2 error LNK1120: 1 unresolved externals C:\Users\sony\documents\visual studio 2012\Projects\Parallel01\x64\Parallel01.exe Parallel01
In VS2010, even with the mentioned x64 setting, its still being compiled for 32 bit. So in the linker, instead of $(CUDA_PATH)\lib\x64 still use $(CUDA_PATH)\lib\Win32.
ReplyDeleteFirst, great tutorial! I appreciated the detail and screen-shots. I followed all the directions accept I started with an Opencl sample from AMD.
ReplyDeleteThe reason I'm writing is when I try to build the project I keep getting error message. C1083: Cannot open include file "CLUtil.hpp": No such file or directory
I've searched the net and found no articles on how to resolve this issue. Are u familiar with this error message? If so, what can I do to complete the project to set-up and Opencl device to run guiminer?
Here's the System info and what alternatives I already tried. GPU: AMD Athlon(tm) 64 X2 Duel Core Processor, AMD SDK 2.9, and MS Visual Studio 2012.
1st, I tried building the project from scratch using your tutorial. At the end I was getting error message missing "CLcl/h".
I resolved this this by changing the C/C++ Additional Include Directories to take the opencl files from the include folder at C:/program file(x86)/AMD SDK/2.9/include.
Then Linker-> General Additional Library Directories to $(AMDAPPSDKROOT)\lib\x86_64
Last I added Open.lib to the Input and added x64 under the Configuration Manager > Active Solutions Platform.
Once I build the project I get error message C1083: Cannot open include file "CLUtil.hpp": No such file or directory.
How do I fix this problem?
error LNK 1104: cannot open file 'corporation\NVIDIA.obj' i am getting this error :(
ReplyDeletehey thanks it was all messed up before i read your comment :) thnks
ReplyDeleteChris, I'm interested in your MS thesis: "An OpenCL implementation of multi-precision arithmetic" .. where can get a PDF copy? Thanks very much!
ReplyDeleteCan anyone post RSA opencl code asap...or convert the below RSA code to opencl code..pls pls pls...help me out..
ReplyDelete#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include
#include
#include
__device__ long long int mod(int base,int exponent,int den)
{
unsigned int a=(base%den)*(base%den);
unsigned long long int ret=1;
float size=(float)exponent/2;
if(exponent==0)
{
return base%den;
}
else
{
while(1)
{
if(size>0.5)
{
ret=(ret*a)%den;
size=size-1.0;
}
else if(size==0.5)
{
ret=(ret*(base%den))%den;
break;
}
else
{
break;
}
}
return ret;
}
}
__global__ void rsa(int * num,int *key,int *den,unsigned int * result)
{
int i=threadIdx.x;
int temp;
if(i<3)
{
temp=mod(num[i],*key,*den);
atomicExch(&result[i],temp);
}
}
int main()
{
int num[3]={16,5,4};
int key=5;
int den=35;
int devcount;
cudaGetDeviceCount(&devcount);
printf("%d CUDA devices found",devcount);
if(devcount>0)
{
cudaSetDevice(1);
printf("\nEnter the 8 digit word:");
for(int i=0;i<3;i++)
{
printf("\n.");
scanf("%d",&num[i]);
}
printf("\nEnter key parameter 1:");
scanf("%d",&key);
printf("\nEnter key parameter 2:");
scanf("%d",&den);
int *dev_num,*dev_key,*dev_den;
unsigned int *dev_res;
unsigned int res[3]={1,1,1};
dim3 grid(1,1,1);
dim3 block(3,3,1);
cudaMalloc( (void **)&dev_num, 3*sizeof(int));
cudaMalloc( (void **)&dev_key,sizeof(int));
cudaMalloc( (void **)&dev_den, sizeof(int));
cudaMalloc( (void **)&dev_res, 3*sizeof(unsigned int));
cudaMemcpy(dev_num,num,3*sizeof(int),cudaMemcpyHostToDevice);
cudaMemcpy(dev_key,&key,sizeof(int),cudaMemcpyHostToDevice);
cudaMemcpy(dev_den,&den,sizeof(int),cudaMemcpyHostToDevice);
cudaMemcpy(dev_res,res,3*sizeof(unsigned int),cudaMemcpyHostToDevice);
rsa<<>>(dev_num,dev_key,dev_den,dev_res);
cudaMemcpy(res,dev_res,3*sizeof(unsigned int),cudaMemcpyDeviceToHost);
cudaFree(dev_num);
cudaFree(dev_key);
cudaFree(dev_den);
cudaFree(dev_res);
for(int i=0;i<3;i++)
{
printf("\n%d",res[i]);
}
}
getch();
return 0;
}
plz explain how this code works?
DeleteI found this really helpful - thank you.
ReplyDeleteHad to create a blank .cl file under OpenCL files directory for this to work, but otherwise it was straightforward. Also, I use the Intel SDK which automatically fills in the values under the project Properties. Thanks! :)
ReplyDeleteHello, I am new to OpenCL. I installed Intel SDK and used Visual Studio 2012 for OpenCL. Would you please give some configuration instructions regarding how to set up Visual Studio for OpenCL ? Thank you so much for your help!
ReplyDeleteThank you! It worked with "$(CUDA_PATH)\lib\x64" and "$(CUDA_PATH)\include"...
ReplyDeleteThis comment has been removed by the author.
DeleteThis comment has been removed by the author.
Deletewow thanks so much
ReplyDeleteI followed your instriction but i got this error
ReplyDelete1>------ Début de la génération : Projet : opencl14, Configuration : Debug Win32 ------
1>LINK : fatal error LNK1123: échec lors de la conversion en fichier COFF : fichier non valide ou endommagé
========== Génération : 0 a réussi, 1 a échoué, 0 mis à jour, 0 a été ignoré
please can any one help me !
Thank you for this walkthrough, saved me a lot of annoyance setting this all up.
ReplyDeleteHello, please could you give me a link to a project, or just source code.
ReplyDeleteI would like to try to run opencl on nvidia in vs2012
I could not find link for the file there.
thanks, I appreciate this article
Below is the simplest OpenCL application to test that the install and configuration have worked
ReplyDeletewhere is it ?
Thank you for the tutorial.
ReplyDeletedid u properly install and link the program with visual ?
DeleteYes, I did
DeleteIt's working fine
sir i m facing this error when i debugging....how to resolve?
ReplyDeletefatal error LNK1181: cannot open input file 'OpenCL.lib'
Sir this error occured also
ReplyDeletethe system can not find file specified
j ai eu le même probèlme comment je peux le résoudre?
DeleteThanks... Great tutorial :)
ReplyDeleteThanks... Great tutorial :)
ReplyDeleteHello it was a great tutorial !
ReplyDeletewould you please upload a program "hello world" for openCL ?
Hello,
ReplyDeleteI am not able to find the openCL code to test the implementation please can anyone help me with this.
Thanks!
Jaime
Thank you for sharing!
ReplyDeleteI coudn't find the c++ code "OpenCL application to test that the install and configuration have worked correctly" as mentioned above
ReplyDeletefatal error LNK1181: cannot open input file 'OpenCL.lib
ReplyDeletej'ai eu ce problème svp comment je peux le résoudre?
Консоли от компании Microsoft не сразу завоевали всемирную популярность и доверие игроков. Первая консоль под названием Xbox, вышедшая в далеком 2001 году, существенно уступала PlayStation 2 по количеству проданных приставок. Однако все поменялось с выходом Xbox 360 - консоли седьмого поколения, которая стала по-настоящему "народной" для обитателей Рф и стран СНГ - Игры для Xbox 360 прошивка LT 3.0 торрент. Веб-сайт Ru-Xbox.Ru является популярным ресурсом в числе поклонников приставки, так как он предлагает игры для Xbox 360, которые поддерживают все имеющиеся версии прошивок - совершенно бесплатно! Зачем играть на оригинальном железе, в случае если имеется эмуляторы? Для Xbox 360 игры выходили долгое время и находятся как посредственными проектами, так и хитами, многие из которых даже сейчас остаются уникальными для это консоли. Некие гости, желающие сыграть в игры для Xbox 360, смогут задать вопрос: для чего необходимы игры для прошитых Xbox 360 freeboot или разными версиями LT, в случае если есть эмулятор? Рабочий эмулятор Xbox 360 хоть и существует, однако он просит производительного ПК, для покупки которого потребуется вложить существенную сумму. К тому же, разные артефакты в виде исчезающих текстур, недостатка некоторых графических эффектов и освещения - смогут изрядно попортить впечатления об игре и отбить желание для ее дальнейшего прохождения. Что предлагает этот интернет-сайт? Наш интернет-сайт на сто процентов посвящен играм для приставки Xbox 360. У нас можно совершенно бесплатно и без регистрации загрузить игры на Xbox 360 через торрент для следующих версий прошивок консоли: - FreeBoot; - LT 3.0; - LT 2.0; - LT 1.9. Каждая прошивка имеет свои особенности обхода встроенной защиты. Поэтому, для запуска той или прочей игры потребуется скачать специальную ее версию, которая стопроцентно приспособлена под одну из 4 вышеперечисленных прошивок. На нашем веб-сайте можно без труда подобрать желаемый проект под подходящую прошивку, так как возле каждой игры присутствует название версии (FreeBoot, LT 3.0/2.0/1.9), под которую она приспособлена. Гостям данного ресурса доступна особая категория игр для 360-го, предназначенных для Kinect - специального дополнения, которое считывает все движения одного или нескольких игроков, и позволяет управлять с их помощью компьютерными персонажами. Большой выбор ПО Кроме возможности скачать игры на Xbox 360 Freeboot или LT различных версий, здесь можно получить программное обеспечение для консоли от Майкрософт: - различные версии Dashboard, которые позволяют кастомизировать интерфейс консоли под свои нужды, сделав его более удобным и современным; - браузеры; - просмотрщики файлов; - сохранения для игр; - темы для консоли; - программы, для конвертации образов и записи их на диск. Кроме перечисленного выше игры на Xbox 360 Freeboot можно запускать не с дисковых, а с USB и прочих носителей, используя программу x360key, которую вы можете достать на нашем портале. Посетителям доступно множество нужных статей, а кроме этого форум, где можно пообщаться с единомышленниками или попросить совета у более опытных хозяев консоли.
ReplyDeleteKode-Stuff: Setting Up Opencl In Visual Studio >>>>> Download Now
ReplyDelete>>>>> Download Full
Kode-Stuff: Setting Up Opencl In Visual Studio >>>>> Download LINK
>>>>> Download Now
Kode-Stuff: Setting Up Opencl In Visual Studio >>>>> Download Full
>>>>> Download LINK lT
Большинство пользователей Инстаграма желали бы увеличить количество подписчиков, просмотров, комментариев и лайков. Самым быстрым способом может стать накрутка за деньги, конкретно такие услуги предлагают на интернет-сайте Krutiminst.ru - накрутка лайков инстаграм бесплатно
ReplyDeleteпрошивка lt
ReplyDeleteБонусы и поощрений в БК 1хбет значительно повышает привлекательность компании в глазах пользователей. Очень выгодные предложения доступны как новеньким, так и игрокам, уже имеющим опыт работы на платформе. Среди внушительного ассортимента бонусной программы очень очень просто потеряться. Каждый промокод 1хбет обеспечит право на определенные преференции - промокод для 1хбет.
ReplyDeleteБК MelBet пользуется большой популярностью на отечественном рынке: -Деятельность организации лицензирована; - Пользователям предоставлен впечатляющий список ставок - в формате live и предматчевых; - Здесь нет задержек с выплатами. Линия ставок невероятно привлекательна. Для того, чтобы получить выгодный бонус на совершение ставок, необходимо всего только использовать промокод MelBet RS777. Получить промокод можно на ставку или на депозит. Каждое предложение имеет свои особенности отыгрыша - Мелбет промокод бонус.
ReplyDeleteВ 2023 году промокод 1хбет предоставляющий максимальный бонус - 1XFREE777. Бонусные средства начисляются автоматически на отдельный счет и их сразу же вы можете использовать для игры - 1xbet промокод.
ReplyDeleteCool and I have a neat proposal: Where To Buy Houses That Need Renovation split level kitchen remodel
ReplyDelete