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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:26:34+00:00 2026-06-12T22:26:34+00:00

I have some CUDA code I made in C and it seems to be

  • 0

I have some CUDA code I made in C and it seems to be working fine (it’s plain old C and not C++). I’m running a Hadoop cluster and wanted to consolidate my code so ideally I’m looking to run it within Java (long story short: system is too complex).

Currently the C program parses a log file, takes a few thousand lines, processes each line in parallel on the GPU, saves specific errors/transactions into a linked list, and writes them to the drive.

What is the best approach to do this? Is JCUDA a perfect mapping to C CUDA or is it totally different? Or does it make sense to call C code from Java and share results (would the linked list be accessible)?

  • 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-12T22:26:36+00:00Added an answer on June 12, 2026 at 10:26 pm

    IMO? JavaCPP. For example, here is a port to Java of the example displayed on the main page of Thrust’s Web site:

    import com.googlecode.javacpp.*;
    import com.googlecode.javacpp.annotation.*;
    
    @Platform(include={"<thrust/host_vector.h>", "<thrust/device_vector.h>", "<thrust/generate.h>", "<thrust/sort.h>",
                       "<thrust/copy.h>", "<thrust/reduce.h>", "<thrust/functional.h>", "<algorithm>", "<cstdlib>"})
    @Namespace("thrust")
    public class ThrustTest {
        static { Loader.load(); }
    
        public static class IntGenerator extends FunctionPointer {
            static { Loader.load(); }
            protected IntGenerator() { allocate(); }
            private native void allocate();
            public native int call();
        }
    
        @Name("plus<int>")
        public static class IntPlus extends Pointer {
            static { Loader.load(); }
            public IntPlus() { allocate(); }
            private native void allocate();
            public native @Name("operator()") int call(int x, int y);
        }
    
        @Name("host_vector<int>")
        public static class IntHostVector extends Pointer {
            static { Loader.load(); }
            public IntHostVector() { allocate(0); }
            public IntHostVector(long n) { allocate(n); }
            public IntHostVector(IntDeviceVector v) { allocate(v); }
            private native void allocate(long n);
            private native void allocate(@ByRef IntDeviceVector v);
    
            public IntPointer begin() { return data(); }
            public IntPointer end() { return data().position((int)size()); }
    
            public native IntPointer data();
            public native long size();
            public native void resize(long n);
        }
    
        @Name("device_ptr<int>")
        public static class IntDevicePointer extends Pointer {
            static { Loader.load(); }
            public IntDevicePointer() { allocate(null); }
            public IntDevicePointer(IntPointer ptr) { allocate(ptr); }
            private native void allocate(IntPointer ptr);
    
            public native IntPointer get();
        }
    
        @Name("device_vector<int>")
        public static class IntDeviceVector extends Pointer {
            static { Loader.load(); }
            public IntDeviceVector() { allocate(0); }
            public IntDeviceVector(long n) { allocate(n); }
            public IntDeviceVector(IntHostVector v) { allocate(v); }
            private native void allocate(long n);
            private native void allocate(@ByRef IntHostVector v);
    
            public IntDevicePointer begin() { return data(); }
            public IntDevicePointer end() { return new IntDevicePointer(data().get().position((int)size())); }
    
            public native @ByVal IntDevicePointer data();
            public native long size();
            public native void resize(long n);
        }
    
        public static native @MemberGetter @Namespace IntGenerator rand();
        public static native void copy(@ByVal IntDevicePointer first, @ByVal IntDevicePointer last, IntPointer result);
        public static native void generate(IntPointer first, IntPointer last, IntGenerator gen);
        public static native void sort(@ByVal IntDevicePointer first, @ByVal IntDevicePointer last);
        public static native int reduce(@ByVal IntDevicePointer first, @ByVal IntDevicePointer last, int init, @ByVal IntPlus binary_op);
    
        public static void main(String[] args) {
            // generate 32M random numbers serially
            IntHostVector h_vec = new IntHostVector(32 << 20);
            generate(h_vec.begin(), h_vec.end(), rand());
    
            // transfer data to the device
            IntDeviceVector d_vec = new IntDeviceVector(h_vec);
    
            // sort data on the device (846M keys per second on GeForce GTX 480)
            sort(d_vec.begin(), d_vec.end());
    
            // transfer data back to host
            copy(d_vec.begin(), d_vec.end(), h_vec.begin());
    
            // compute sum on device
            int x = reduce(d_vec.begin(), d_vec.end(), 0, new IntPlus());
        }
    }
    

    Your code in C should be easier to map though.

    We can get this compiled and running on Linux x86_64 with these commands, or on other supported platforms by modifying the -properties option appropriately:

    $ javac -cp javacpp.jar ThrustTest.java
    $ java -jar javacpp.jar ThrustTest -properties linux-x86_64-cuda
    $ java  -cp javacpp.jar ThrustTest
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran some CUDA code that updated an array of floats. I have a
I have some code on two systems running kernel 2.4.20 and kernel 2.4.38 .
I have a re-useable function in some CUDA code that needs to be called
I have some code that I want to make into a cuda kernel. Behold:
I have done this for other apps but for some reason its not working
I have made a Simple CUDA dll the code which I am displaying below.
I have some code that will change the background color of a specific label
I have written a CUDA code to solve an NP-Complete problem, but the performance
I am having a weird problem .. I have written a CUDA code which
I am working on CUDA and I have a problem related to thread synchronization.

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.