@@ -0,0 +1,2022 @@
+/*%0A * To change this license header, choose License Headers in Project Properties.%0A * To change this template file, choose Tools %7C Templates%0A * and open the template in the editor.%0A */%0Apackage gvirtusfe;%0A%0Aimport java.io.IOException;%0Aimport javax.xml.bind.DatatypeConverter;%0A%0A/**%0A *%0A * @author cferraro%0A */%0Apublic class CudaDr_memory %7B%0A%0A    public CudaDr_memory() %7B%0A    %7D%0A%0A    String cuMemAlloc(Frontend fe, Result res, long size) throws IOException%7B%0A%0A        Buffer b = new Buffer();%0A        byte%5B%5D bits = this.longToByteArray(size);%0A           for (int i =0; i%3C bits.length;i++)%7B%0A               b.AddByte(bits%5Bi%5D & 0xFF);%0A        %7D%0A        String pointer = %22%22;%0A        fe.Execute(%22cuMemAlloc%22,b,res);%0A        pointer = getHex(res,8);%0A        return pointer;%0A    %7D%0A     %0A    %0A        private String getHex (Result res,int size) throws IOException%7B%0A%0A        byte%5B%5D array=new byte%5Bsize%5D;%0A        for (int i=0; i%3Csize;i++)%7B%0A            byte bit=res.getInput_stream().readByte();%0A            array%5Bi%5D=bit;%0A        %7D%0A        String hex = DatatypeConverter.printHexBinary(array);%0A        System.out.println(hex);%0A        return hex;%0A    %7D%0A    %0A        %0A    void cuMemcpyHtoD(Frontend fe, Result res, String dst, float%5B%5D src, int count) throws IOException %7B%0A        %0A        Buffer b = new Buffer();%0A         byte%5B%5D bits = this.longToByteArray(count);%0A           for (int i =0; i%3C bits.length;i++)%7B%0A               b.AddByte(bits%5Bi%5D & 0xFF);%0A        %7D%0A        b.Add(dst);%0A           for (int i =0; i%3C bits.length;i++)%7B%0A               b.AddByte(bits%5Bi%5D & 0xFF);%0A        %7D%0A        b.Add(src);%0A        fe.Execute(%22cuMemcpyHtoD%22, b, res);%0A    %0A    %7D    %0A        %0A        %0A     public byte%5B%5D longToByteArray(long value) %7B%0A        return new byte%5B%5D %7B%0A            (byte) value,%0A            (byte) (value %3E%3E 8),%0A            (byte) (value %3E%3E 16),%0A            (byte) (value %3E%3E 24),%0A            (byte) (value %3E%3E 32),%0A            (byte) (value %3E%3E 40),%0A            (byte) (value %3E%3E 48),%0A            (byte) (value %3E%3E 56)%0A%0A        %7D;%0A    %7D%0A%0A %0A%7D%0A

Add CUDA memory manage functions