Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8208105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:13:46+00:00 2026-06-07T09:13:46+00:00

I’m new with OpenCL and have some problems with the array additions I use

  • 0

I’m new with OpenCL and have some problems with the array additions
I use the code provided in the link below

http://code.google.com/p/opencl-book-samples/source/browse/#svn%2Ftrunk%2Fsrc%2FChapter_2%2FHelloWorld%253Fstate%253Dclosed

and I added some parts to measure the performance of the GPU

clFinish(commandQueue);
        // Queue the kernel up for execution across the array
        cl_ulong start, end; cl_event  k_events;

        errNum = clEnqueueNDRangeKernel(commandQueue, kernel, 1, NULL,
                                        globalWorkSize, localWorkSize,
                                        0, NULL, &k_events);
         clGetEventProfilingInfo(k_events, CL_PROFILING_COMMAND_START,  
                            sizeof(cl_ulong), &start, NULL); 
         clWaitForEvents(1 , &k_events);

    clGetEventProfilingInfo(k_events, CL_PROFILING_COMMAND_END, 
                            sizeof(cl_ulong), &end, NULL); 
    clGetEventProfilingInfo(k_events, CL_PROFILING_COMMAND_START,  
                            sizeof(cl_ulong), &start, NULL); 

    float GPUTime = (end - start);

And this to measure the CPU time

LARGE_INTEGER CPUstart, finish, freq;
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&CPUstart);

for (int i=0;i<ARRAY_SIZE;i++){

    result[i]=a[i]+b[i];
}

QueryPerformanceCounter(&finish);
double timeCPU=(finish.QuadPart - CPUstart.QuadPart) /((double)freq.QuadPart)/1000000000.0) ;

The first problem I encountered is the array size ; it can’t go beyond 10000 ; if I do this ; it just crash . How to fix it ?

The second problem is the performance ; the GPU/CPU ratio range is too wide ; from 13% to 210%(ish) . Why does this happen and can you suggest a fix ?

Edit : I figured out the 2nd ; the lag was caused by the power saving mode ; it set the core/mem to much lower than default . Just use a program to lock it ; and the performance are rocking stable at ~150-300 % (GPU/CPU)

Good case

GPU time :632667 nanosecs.
CPU time : 990023 nanosecs.
GPU/CPU ratio : 156.484 percent.

And bad one :

GPU time :6.83267e+006 nanosecs.
CPU time : 1.00756e+006 nanosecs.
GPU/CPU ratio : 14.7462 percent.

Any ideas will be appreciated . Thank you 😀

PS : The CPU is core i3-370M ; GPU : HD5470 . I use VS2008 on windows 7

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:13:47+00:00Added an answer on June 7, 2026 at 9:13 am

    One possible (and most probable) reason that your program crashes with bigger array sizes is due to the following code in main.cpp (lines 274-276 in the original code):

    float result[ARRAY_SIZE];
    float a[ARRAY_SIZE];
    float b[ARRAY_SIZE];
    

    These are automatic arrays and space for them is allocated on the stack of the main function. The total space required is 3*ARRAY_SIZE*sizeof(float) which equals 12*ARRAY_SIZE. The default stack size on Windows is 1 MiB which means ARRAY_SIZE could be up to 87380. This is the upper limit given the default stack size and since the stack is also used for other things too, the real value would be somewhat lower.

    You can increase the stack size on the Linker -> System page of your VS project properties. Or better allocate those arrays on the heap using malloc() or new[].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I have two tables with like below codes: Table: Accounts id | username |
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.