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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:29:16+00:00 2026-05-18T07:29:16+00:00

I have two matrices (A and B), 2-dimensions. And i think i’ll speed up

  • 0

I have two matrices (A and B), 2-dimensions. And i think i’ll speed up a bit if instead of putting it into global memory and access via pointers, i put them into textures 2d and use it. The matrices aren’t that big, and different positions are read by different threads.

So right now my code is using global memory, and the values i get are correct, i am multiplying for every value in the matrix:

A[i][j] * B[ p[i] ] [ p[j] ]

The optimal value for the instance i’m testing is 9552, can’t get a different value.

So i moved into textures, and it seems like some fetches return a wrong value, because i got a 9511 right now.

I was searching about textures on CUDA, and i saw they are indexed by [0..n-1]. But they have some normalized access, and a couple other stuff, like filtering, where the value you want is an interpolation of neighbors.

What’s the default options for a texture? Maybe that’s the problem. Couldn’t find the defaults on the Programming Guide.

here’s the relevant code:

Declaration:

texture<float,2> A_matrix;
texture<float,2> B_matrix;

Allocation:

HANDLE_ERROR( cudaMalloc( (void**)&_A, n * n * sizeof(float) ) );
HANDLE_ERROR( cudaMalloc( (void**)&_B, n * n * sizeof(float) ) );

Memcpy

HANDLE_ERROR( cudaMemcpy( _A, A, n * n * sizeof(float), cudaMemcpyHostToDevice ) );
HANDLE_ERROR( cudaMemcpy( _B, B, n * n * sizeof(float), cudaMemcpyHostToDevice ) );

Binding and Descriptors (created two because i’m silly)

cudaChannelFormatDesc desc = cudaCreateChannelDesc<float>();
    cudaChannelFormatDesc desc2 = cudaCreateChannelDesc<float>();

    HANDLE_ERROR( cudaBindTexture2D( NULL, A_matrix,
                                   _A,
                                   desc, n, n,
                                   sizeof(float) * n ) );
    HANDLE_ERROR( cudaBindTexture2D( NULL, B_matrix,
                                   _B,
                                   desc2, n, n,
                                   sizeof(float) * n ) );

And where i use it

res += tex2D(A_matrix, i, j)  * tex2D(B_matrix, p[i], p[j]);

So how can I use textures correctly? Or are they meant to be like this?

EDIT:

This is the code that uses this memory access, the commented line doesn’t use textures, and WORKS PERFECTLY.

__device__ inline float datastruct::getPermutationValue(int* p)
{
    float res = 0;
    for(int i = 0 ; i < ints[data_n] ; i++)
        for(int j = 0 ; j < ints[data_n] ; j++)
            res += tex2D(A_matrix, i, j)  * tex2D(B_matrix, p[i], p[j]);
            //res += qap_A[i * ints[data_n] + j]  * qap_B[p[i] * ints[data_n] + p[j]];
    return res;
}
  • 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-05-18T07:29:17+00:00Added an answer on May 18, 2026 at 7:29 am

    Sorry 2D textures in CUDA can be a pain. I have a simple code thats only about 150 lines. I posted it on the nvidia forums. I believe you may need one of the sdk libraries to compile. I haven’t had too much luck with textures for more complicated operations. I hope this helps you, it should compile for you.

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

Sidebar

Related Questions

No related questions found

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.