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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:58:31+00:00 2026-06-11T22:58:31+00:00

I have the following code in Java: float in[][] = new float[2][2]; float B[]

  • 0

I have the following code in Java:

float in[][] = new float[2][2];

float B[] = new float[2]; 
float A[] = new float[2]; 
float res[] = new float[A[0].length];

for(float r : res){
    r = 0;
}

for (int i = 0; i < A[0].length; i++) {
    for (int j = 0; j < B[0].length; j++) {
        res[i] += A[j] * in[j][i];
}

I simplified it at most, so you should not search for a real logic in there :).

I struggle for some hours converting this in CUDA because of the += statement in the loop.

I started with something like this :

extern "C"
__global__ void filter(float* in, float* A, float* B, float* res, int in_size){

    unsigned int x = blockIdx.x*blockDim.x + threadIdx.x;
    unsigned int y = blockIdx.y*blockDim.y + threadIdx.y;

    res[x] = A[y] * in[x + y * in_width];

}

but quickly realized it couldn’t work because of all the threads trying to set the same variable.

I read the example of the dot product in this presentation,
but I don’t really see how to adapt that with my need of two dimensions for in.

I don’t ask for a complete solution, but any direction would definitely be appreciated.

Thx,

  • 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-11T22:58:32+00:00Added an answer on June 11, 2026 at 10:58 pm

    Too much CUDA killed my head.

    I found a partial solution by unrolling one of the loops inside my kernel.
    Here it what it looks like right now :

    extern "C"
    __global__ void filter(float* in, float* A, float* res, const int in_width, const int sizeB){
        unsigned int x = blockIdx.x*blockDim.x + threadIdx.x;
        int i = 0;
    
        for(i = 0; i < sizeB; i++){
            res[x] += A[i] * in[i + x * in_width];
        }
    
    }
    

    I am sure I can find better, but I think I’ll stick with this for today 🙂

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

Sidebar

Related Questions

If I have the following Java code: int[][] readAPuzzle() { Scanner input = new
I have the following Java code: final Future future = exeService.submit( new Runnable() {
I have the following code adding an ActionListener to a JTextField: chatInput.addMouseListener(new java.awt.event.MouseAdapter() {
I have the following simple code : int speed1 = (int)(6.2f * 10); float
I have following Java code: import java.io.*; class Global{ public static int a =
I have following code in web aplication java.​awt.Desktop.getDesktop().print(new File(path)); It is working with any
I have the following code in Java; BigDecimal price; // assigned elsewhere if (price.compareTo(new
I have the following java code: import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement;
I have following Code package cyclist.project; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException;
Say suppose I have the following Java code. public class Example { public static

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.