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 9060707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:17:55+00:00 2026-06-16T15:17:55+00:00

I have a large character array in the device global memory that is accessed

  • 0

I have a large character array in the device global memory that is accessed
in a coalescent manner by threads. I’ve read somewhere that I could speed up
memory access by reading 4 or 16 chars in one memory transaction per thread.
I believe I would have to use textures and the char4 or int4 structs. However,
I can’t find any documentation or examples on this. Could anyone here please
provide a simple example or pointers to where I can learn more about this?

In my code I define the char array as

char *database = NULL;
cudaMalloc( (void**) &database, SIZE * sizeof(char) );

What would the definition be if I want to use textures and char4 (or int4)?

Thanks very much.

  • 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-16T15:17:56+00:00Added an answer on June 16, 2026 at 3:17 pm

    I finally figured out the answer to my own question. The definition with char4
    would be

    char4 *database = NULL;
    cudaMalloc( (void**) &database, SIZE * sizeof(char4)/4 );
    

    Don’t need textures for this. The kernel does speedup by a factor of three
    with char4 but reduces to two if I do loop unrolling. For the sake of completeness
    my kernel is

    __global__ void kernel(unsigned int jobs_todo, char* database, float* results ) {
    
      unsigned int id = threadIdx.x + blockIdx.x * blockDim.x;
      float A = 0; int i; char ch;
      if(id < jobs_todo) {
        for(i = 0; i < 1000; i += 1){
         ch = database[jobs_todo*i + id];
         if(ch == 'A') A++;
        }
        results[id] = A;
      }
    }
    

    And with char4 it is

    __global__ void kernel4(unsigned int jobs_todo, char4* database, float* results ) {
    
      unsigned int id = threadIdx.x + blockIdx.x * blockDim.x;
      float A = 0; int i; char4 ch4;
      if(id < jobs_todo) {
        for(i = 0; i < 1000/4; i += 1){
         ch4 = database[jobs_todo*i + id];
         if(ch4.x == 'A') A++;
         if(ch4.y == 'A') A++;
         if(ch4.z == 'A') A++;
         if(ch4.w == 'A') A++;
        }
        results[id] = A;
      }
    }
    

    I also tried int4 but it’s just .0002 seconds faster than the char4 time.

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

Sidebar

Related Questions

I have code that loops through numbers and creates the character array representation of
I have an array of entities that need to be replaced in a large
Here's the deal. I have a large character array and am trying to manipulate
i have large numbers of text files and i am in problem that i
I have large video files (~100GB) that are local on my machine. I have
I have an array that's declared as char buff[8]. That should only be 8
I have a large number of strings that I need to store in a
I have two arrays First array has large number of words, i have 2nd
I have a large database made up of mixed data types (numeric, character, factor,
I have a rather large list of data that contains 5 properties per element.

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.