src-d / kmcuda

Large scale K-means and K-nn implementation on NVIDIA GPU / CUDA
Other
807 stars 146 forks source link

Illegal instruction (core dumped) #52

Open hyh900220 opened 6 years ago

hyh900220 commented 6 years ago

Hi, @vmarkovtsev I meet the same problem: "Segmentation fault (core dumped)" When running test.py I use ubuntu 16.04, python 3.5.2 and CUDA 8.0. I tried to use pip install libKMCUDA, the log it shows

The directory '/home/deeptexas-1/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/deeptexas-1/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting libKMCUDA
  Downloading https://files.pythonhosted.org/packages/b9/ae/db37581df07f7e225fac11e62cb8231437949780f41e8542979bed7aaba3/libKMCUDA-6.2.1-cp35-cp35m-manylinux1_x86_64.whl (643kB)
    100% |████████████████████████████████| 645kB 61kB/s 
Requirement already satisfied: numpy in ./.local/lib/python3.5/site-packages (from libKMCUDA) (1.15.0)
Installing collected packages: libKMCUDA
Successfully installed libKMCUDA-6.2.1

but when I try to run this sample

import numpy
from matplotlib import pyplot
from libKMCUDA import kmeans_cuda

numpy.random.seed(0)
arr = numpy.empty((10000, 2), dtype=numpy.float32)
arr[:2500] = numpy.random.rand(2500, 2) + [0, 2]
arr[2500:5000] = numpy.random.rand(2500, 2) - [0, 2]
arr[5000:7500] = numpy.random.rand(2500, 2) + [2, 0]
arr[7500:] = numpy.random.rand(2500, 2) - [2, 0]
centroids, assignments = kmeans_cuda(arr, 4, verbosity=1, seed=3)
print(centroids)
pyplot.scatter(arr[:, 0], arr[:, 1], c=assignments)
pyplot.scatter(centroids[:, 0], centroids[:, 1], c="white", s=150)

it shows error

arguments: 1 0x7ffe7faab5e4 0.010 0.10 0 10000 2 4 3 0 0 2 0x32b4ff0 0x32f3ef0 0x33585e0 (nil)
Illegal instruction (core dumped)

so I try to build from source , the command is

cmake -DCMAKE_BUILD_TYPE=Release -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-8.0 .
make

and the build logs is kmcuda_build_log.txt

my CPU is E5-1650, motherboard is intel C602 chipset, 32G ddr3 ram.

Thanks!

vmarkovtsev commented 6 years ago

I suggest making a debug build -DCMAKE_BUILD_TYPE=Debug and launching again. If it says smth about the GPU arch mismatch, see the README.

hyh900220 commented 6 years ago

I modify the CMakeLists.txt, line 38 , "-march=native" to "-march=sandybridge", see below:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=sandybridge -Wall -Werror -DCUDA_ARCH=${CUDA_ARCH} -std=c++11 ${OpenMP_CXX_FLAGS}")

it still cannot normally run the test.py , but it can run the sample below and it can normally work.

import numpy
from matplotlib import pyplot
from libKMCUDA import kmeans_cuda

numpy.random.seed(0)
arr = numpy.empty((10000, 2), dtype=numpy.float32)
arr[:2500] = numpy.random.rand(2500, 2) + [0, 2]
arr[2500:5000] = numpy.random.rand(2500, 2) - [0, 2]
arr[5000:7500] = numpy.random.rand(2500, 2) + [2, 0]
arr[7500:] = numpy.random.rand(2500, 2) - [2, 0]
centroids, assignments = kmeans_cuda(arr, 4, verbosity=1, seed=3)
print(centroids)
pyplot.scatter(arr[:, 0], arr[:, 1], c=assignments)
pyplot.scatter(centroids[:, 0], centroids[:, 1], c="white", s=150)

Notice, my CPU is E5-1650, which CPU arch is Sandy Bridge EP, so change '-march=native' to '-march=sandybridge' can work, other CPU may not work. You need to notice your CPU arch.