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

  • Home
  • SEARCH
  • 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 8215161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:41:34+00:00 2026-06-07T11:41:34+00:00

I’m developing this test application in C++ and OpenCL but I just CAN’T figure

  • 0

I’m developing this test application in C++ and OpenCL but I just CAN’T figure out why I am getting this very weird problem which further results in segmentation fault.

Some of the code:

output = new cl_float[TestCount*TrainCount]; // output array
output_buf = new cl::Buffer(*context, CL_MEM_WRITE_ONLY, sizeof(cl_float)*TestCount*TrainCount, NULL);
// .... some more stuff
queue->enqueueReadBuffer(*output_buf, CL_TRUE, 0, TestCount*TrainCount, output);

Here, output and output_buf are pointers to their respective data.

The seg-fault occurs when I try to access any element of the output array after everything has been processed. Upon further debugging, I found that the maximum number of elements it is storing is 562 whereas it should be 2250 (TestCount=150, TrainCount=15). Moreover, the surprising thing is that I can access any element from GDB but not 562 upwards.

I have no doubt that there is no error in the code and I’m absolutely sure that all the 2250 outputs are being processed by the GPU. This was testing by atomically incrementing the first element of the output array in each thread and then outputting it via GDB.

Seems like I have ruled out a lot of possibilities but for the heck of it I still can’t figure out what’s causing this problem. There is a minuscule chance that the heap is getting filled but I top’ed and found that my application only uses like 37M of memory.

Any help would be appreciated!

UPDATE: James is right. It was because of not reading enough bytes from the memory. The backtrace of the seg-fault is as follows-

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x000000000000000c
0x0000000100002402 in main (argc=4, argv=0x7fff5fbffb88)
    at TestApplication.cpp:202
202     cout << OpenCL_KNN::output[0] << " " << OpenCL_KNN::output[1] << " " << OpenCL_KNN::output[2] << " " << OpenCL_KNN::output[3];

The 4 indices being accessed are definitely defined. Nothing before this lines gives me any error. The output array isn’t altered/created anywhere other than what I mentioned previously.

Update 2: The error is resolved. It was only occurring in Mac OS X. It had something to do what the way I was accessing the output. Once I created a function in OpenCL_KNN namespace returning me the output, it worked perfectly.

  • 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-07T11:41:36+00:00Added an answer on June 7, 2026 at 11:41 am

    I’m not familiar with the C++ wrapper for CL, but I’m guessing that TestCount*TrainCount is a factor of sizeof(cl_float) too few bytes to be reading back from the GPU. Your code should be:

    queue->enqueueReadBuffer(*output_buf, CL_TRUE, 0, sizeof(cl_float)*TestCount*TrainCount, output);
    

    That doesn’t explain your segfault, however. Perhaps you are making the same error elsewhere?

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
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 want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

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.