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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:36:49+00:00 2026-05-19T12:36:49+00:00

I just can’t find examples for JCuda for one of simplest tasks: add two

  • 0

I just can’t find examples for JCuda for one of simplest tasks: add two arrays of values to a third array.

I always only find C/C++ examples, which rely on some CUDA-precompiler, hence unusable for me. Scary things occur there, such as:

VecAdd<<<blocksPerGrid, threadsPerBlock>>>(d_A, d_B, d_C, N)

Well, in JCuda libraries there is nothing similar to VecAdd.

There are a lot of sub-libraries in JCuda, such as JCudpp, JCublas, … I really don’t know where to look and for what.

Please help!

  • 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-19T12:36:49+00:00Added an answer on May 19, 2026 at 12:36 pm

    I managed to assemble a working example:

    Source

    import java.util.*;
    
    import jcuda.*;
    import static jcuda.jcublas.JCublas.*;
    
    public class Main {
    
      private static final int VECTOR_SIZE = 10;
    
      static {
        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
    
          @Override
          public void run() {
            cublasShutdown();
          }
    
        }));
    
        cublasInit();
      }
    
      static void printArrays(float[] a1, float[] a2) {
        System.out.println("\t" + Arrays.toString(a1));
        System.out.println("\t" + Arrays.toString(a2));
        System.out.println();
      }
    
      public static void main(String[] args) {
        float[] a1 = new float[VECTOR_SIZE];
        float[] a2 = new float[VECTOR_SIZE];
    
        for (int i = 0; i < VECTOR_SIZE; ++i) {
          a1[i] = i + 1;
        }
    
        Pointer p1 = new Pointer();
        Pointer p2 = new Pointer();
    
        cublasAlloc(VECTOR_SIZE, Sizeof.FLOAT, p1);
        cublasAlloc(VECTOR_SIZE, Sizeof.FLOAT, p2);
    
        System.out.println("BEFORE:");
        printArrays(a1, a2);
    
        cublasSetVector(VECTOR_SIZE, Sizeof.FLOAT, Pointer.to(a1), 1, p1, 1);
        cublasSetVector(VECTOR_SIZE, Sizeof.FLOAT, Pointer.to(a2), 1, p2, 1);
    
        // THE ACTUAL OPERATION: MULTIPLY AND ADD
        cublasSaxpy(VECTOR_SIZE, 20f, p1, 1, p2, 1);
    
        cublasGetVector(VECTOR_SIZE, Sizeof.FLOAT, p2, 1, Pointer.to(a2), 1);
    
        System.out.println("AFTER:");
        printArrays(a1, a2);
    
        cublasFree(p1);
        cublasFree(p2);
      }
    
    }
    

    Output

    BEFORE:
        [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
        [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
    
    AFTER:
        [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
        [20.0, 40.0, 60.0, 80.0, 100.0, 120.0, 140.0, 160.0, 180.0, 200.0]
    

    Note

    Now I will play around with AMD Aparapi.

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

Sidebar

Related Questions

I just can't figure out or find any solution here, so I chose to
I just can't find the option anywhere. Is there some way in eclipse to
I just can't find a simple answer to this simple question I have from
I just can't work this one out. I have a table with a column
I just can't seem to figure this one out... As far as I know,
Just can't find a way to transform an Hex String to a number (Int,
I just can't get to set sessions in php, and I can't find the
Just can not find how to install root certificate on Windows Phone 7. Does
Just can't wrap my head around the proper syntax for this one. Below is
I just can't seem to find a way on the command line to say

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.