View Single Post
Old 2019-10-26, 15:22   #1
EdH
 
EdH's Avatar
 
"Ed Hall"
Dec 2009
Adirondack Mtns

31×109 Posts
Default How I Compile the GPU branch of GMP-ECM in a Colaboratory Session

(Note: I expect to keep the first post of each of these "How I..." threads up-to-date with the latest version. Please read the rest of each thread to see what may have led to the current set of instructions.)

I will take the liberty of expecting readers to already be somewhat familiar with Google's Colaboratory sessions. There are several threads already on Colab and these should be reviewed by interested readers:

Google Colaboratory Notebook?
GPU72 Notebook Integration...
Notebook Instance Reverse SSH and HTTP Tunnels.
Colab question

I do not, as of yet, have a github account, so I have not created an upload of this to github. Others may feel free to do so, if desired. The following is a manner to compile and install GMP and the GPU branch of GMP-ECM into a Colab session, so that ECM can be run making use of a GPU.

For those unfamiliar with the GPU branch of GMP-ECM, only stage 1 is handled by the GPU. All of stage 2 is still only processed by the CPU. Additionally, the stages are not run in parallel. Stage 1 runs on the GPU and then stage 2 runs on the CPU.

More information on the GPU branch of GMP-ECM can be found in the README.gpu document within the ecm main folder.

To use Colab, you need a Gmail account and will be required to log into that account to run a session.

On to the specifics:

Open a Google Colaboratory session.
Sign in with your Google/Gmail account info.
Choose New Python3 notebook:
Code:
Menu->File->New Python3 notebook (or within popup)
Change Runtime to add GPU:
Code:
Menu->Runtime->Change runtime type->Hardware accelerator->GPU->SAVE
Click Connect to start a session.
Edit title from Untitled... to whatever you like.
Paste the following into the Codeblock:
Code:
!chmod 777 /tmp
!apt update
!apt install g++ m4 make subversion libtool autoconf
!mkdir Math
%cd Math
!wget "https://ftp.gnu.org/gnu/gmp/gmp-6.2.0.tar.bz2"
!tar -xf gmp-6.2.0.tar.bz2
!mv gmp-6.2.0 gmp
%cd gmp
!./configure
!make
############################################
# These 4 lines are recommended, but can be commented out or removed! #
############################################
!make check
!echo "Check results, then click in the"
!echo "TextBox below and press Enter to continue. . ."
!read continue in
############################################
!make install
%cd ..
!svn co svn://scm.gforge.inria.fr/svn/ecm/trunk ecm
%cd ecm
!libtoolize
!autoreconf -i
!./configure --enable-gpu --with-cuda-bin=/usr/local/cuda-10.0/bin --with-cuda=/usr/local/cuda-10.0/targets/x86_64-linux --with-cuda-lib=/usr/local/cuda-10.0/targets/x86_64-linux/lib --with-gmp=/usr/local/
!make
############################################
# These 4 lines are recommended, but can be commented out or removed! #
############################################
!make check
!echo "Check results, then click in the"
!echo "TextBox below and press Enter to continue. . ."
!read continue in
############################################
!make install
!echo "############################################"
!echo "############################################"
!echo "(2^835+1)/33" | ecm -gpu 1e4
Note: There are some checks and pauses written into the code that are recommended, but not strictly necessary. Feel free to comment out or remove those lines in the above code.

Click on the Run cell icon or use CTRL-Enter.
Either watch all the scrolling text or take a break. This will run for a few minutes. If you chose to leave the checks and pauses you can review the results of the GMP and ECM check runs before continuing. To continue at these breaks, you have to click in the text entry box below the message and hit Enter as instructed.

When everything is finished, if all went well, you should have a message similar to the following:
Code:
. . .
GMP-ECM 7.0.5-dev [configured with GMP 6.1.2, --enable-asm-redc, --enable-gpu, --enable-assert] [ECM]
 Input number is (2^835+1)/33 (250 digits)
Using B1=10000, B2=1873422, sigma=3:1745495596-3:1745496427 (832 curves)
GPU: Block: 32x32x1 Grid: 26x1x1 (832 parallel curves)
Computing 832 Step 1 took 90ms of CPU time / 4044ms of GPU time
Computing 832 Step 2 on CPU took 28406ms
At this point you can remove the code from the original code block or open a new code block to continue.

Next, in an empty code block, try the following:
Code:
!echo 115367564564210182766242534110944507919869313713243756429 | ecm -gpu 1e4
You should see a long series of successes:
Code:
GMP-ECM 7.0.5-dev [configured with GMP 6.1.2, --enable-asm-redc, --enable-gpu, --enable-assert] [ECM]
Input number is 115367564564210182766242534110944507919869313713243756429 (57 digits)
Using B1=10000, B2=1873422, sigma=3:2239793235-3:2239794066 (832 curves)
GPU: Block: 32x32x1 Grid: 26x1x1 (832 parallel curves)
GPU: factor 3387679 found in Step 1 with curve 0 (-sigma 3:2239793235)
. . .
GPU: factor 3387679 found in Step 1 with curve 830 (-sigma 3:2239794065)
Computing 832 Step 1 took 62ms of CPU time / 4012ms of GPU time
********** Factor found in step 1: 3387679
Found prime factor of 7 digits: 3387679
Prime cofactor 34055046113935288073705488067477617542827792631251 has 50 digits
If all ran as expected, you can proceed with more ECM runs using the same format. Again, for more info on running GMP-ECM with GPU support, see the README.gpu document in the main ecm folder.

Last fiddled with by EdH on 2020-06-02 at 11:02
EdH is offline   Reply With Quote