-masalah dengan lightdm login (loop login)
-masalah dengan driver istall ("Instalasi Driver gagal: tampaknya, bahwa server X sedang berjalan ...")
Untuk berhasil menginstal NVidia CUDA Toolkit di Ubuntu 16.04 64bit, saya baru saja harus melakukan:
- buat liveImage dari Ubuntu dengan flashdisk (pena 8GB sudah cukup) - percobaan semacam itu akan menghemat banyak keberanian , sebelum instalasi yang gagal di sistem Linux host Anda !!!
- masuk pada sesi langsung pada pendrive ("Coba Ubuntu, sebelum menginstal")
tambahkan pengguna sudo di sesi langsung:
sudo adduser admin (#pass: admin1)
sudo usermod -aG sudo admin
keluar dari sesi langsung, masuk sebagai #admin
- unduh CUDA Toolkit dari situs resmi NVidia (~ 1.5GB)
ubah hak istimewa untuk file pemasang yang diunduh (JANGAN INSTAL DI LANGKAH INI!):
sudo chmod + x cuda_X.X.run
beralih ke tampilan konsol:
Ctr + Alt + F1 (untuk mengaktifkan tampilan terminal) Ctr + Alt + F7 (untuk beralih dari tampilan terminal ke server grafis)
pada tampilan konsol (Ctr + Alt + F1) masuk:
login: admin pass: admin1
hentikan layanan berjalan grafis:
layanan sudo berhenti lightdm
periksa apakah server grafis mati - setelah beralih Ctr + Alt + F7 monitor harus kosong hitam, aktifkan kembali tampilan konsol Ctr + Alt + F1
instal CUDA Toolkit, dengan konfigurasi seperti itu:
sudo ./cuda_X.X.run (tekan 'q' untuk lewati lisensi baca) jangan instal pustaka OpenGL jangan perbarui konfigurasi sistem X pilihan lain buat yes dan path sebagai default
nyalakan server grafis:
sudo service lightdm start
masuk sebagai pengguna (jika Anda secara otomatis masuk sebagai #ubuntu saat sesi keluar langsung):
login: admin pass: admin1
periksa kompilator nvcc apa pun yang berfungsi dengan jumlah vektor paralel sederhana yang disediakan di Blok GPU:
simpan vecSum.cu dan book.h di file baru, kompilasi dan jalankan di terminal: /usr/local/cuda-8.0/bin/nvcc vecSum.cu && clear && ./a.out
periksa hasil cetak konsol - harus sama dengan: 0,000000 + 0,000000 = 0,000000
-1.100000 + 0.630000 = -0.000000
-2.200000 + 2.520000 = 0.319985
-3.300000 + 5.670000 = 2.119756
-4.400000 + 10.080000 = 5.679756
-5.500000 + 15.750000 = 10.250000
-6.600000 + 22.680000 = 16.017500
-7.700000 + 30.870001 = 23.170002
-8.800000 + 40.320000 = 31.519997
-9.900000 + 51.029999 = 41.129967
jika semuanya berjalan dengan baik pada sesi live flashdisk, lakukan hal yang sama pada sistem host linux Anda
PS Harap dicatat bahwa ini bukan tutorial yang ideal, tetapi berfungsi dengan baik untuk saya!
======= vecSum.cu =====
#include "book.h"
#define N 50000
///usr/local/cuda-8.0/bin/nvcc vecSum.cu && clear && ./a.out
//"HOST" = CPU
//"Device" = GPU
__global__ void add( float *a, float *b, float *c )
{
int tid = blockIdx.x;
if ( tid < N )
c[ tid ] = a[ tid ] + b[ tid ];
}
int main ( void )
{
float a[ N ], b[ N ], c[ N ];
float *dev_a, *dev_b, *dev_c;
//GPU memory allocation
HANDLE_ERROR( cudaMalloc( ( void** )&dev_a, N * sizeof( float ) ) );
HANDLE_ERROR( cudaMalloc( ( void** )&dev_b, N * sizeof( float ) ) );
HANDLE_ERROR( cudaMalloc( ( void** )&dev_c, N * sizeof( float ) ) );
//sample input vectors CPU generation
for ( int i = 0; i < N; i++ )
{
a[ i ] = -i * 1.1;
b[ i ] = i * i * 0.63;
}
//copy/load from CPU to GPU data vectors a[], b[] HostToDevice
HANDLE_ERROR( cudaMemcpy( dev_a, a, N * sizeof( float ), cudaMemcpyHostToDevice ) );
HANDLE_ERROR( cudaMemcpy( dev_b, b, N * sizeof( float ), cudaMemcpyHostToDevice ) );
//calculate sum of vectors on GPU
add<<<N,1>>> ( dev_a, dev_b, dev_c );
//copy/load result vector from GPU to CPU c[] DeviceToHost
HANDLE_ERROR( cudaMemcpy( c, dev_c, N * sizeof( float ), cudaMemcpyDeviceToHost ) );
//printout results
for ( int i = 0; i < 10; i++ ) printf( "%f + %f = %f\n", a[ i ], b[ i ], c[ i ] );
//free memory and constructed objects on GPU
cudaFree( dev_a );
cudaFree( dev_b );
cudaFree( dev_c );
return 0;
}
========= book.h ======
/*
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
*
* NVIDIA Corporation and its licensors retain all intellectual property and
* proprietary rights in and to this software and related documentation.
* Any use, reproduction, disclosure, or distribution of this software
* and related documentation without an express license agreement from
* NVIDIA Corporation is strictly prohibited.
*
* Please refer to the applicable NVIDIA end user license agreement (EULA)
* associated with this source code for terms and conditions that govern
* your use of this NVIDIA software.
*
*/
#ifndef __BOOK_H__
#define __BOOK_H__
#include <stdio.h>
static void HandleError( cudaError_t err,
const char *file,
int line ) {
if (err != cudaSuccess) {
printf( "%s in %s at line %d\n", cudaGetErrorString( err ),
file, line );
exit( EXIT_FAILURE );
}
}
#define HANDLE_ERROR( err ) (HandleError( err, __FILE__, __LINE__ ))
#define HANDLE_NULL( a ) {if (a == NULL) { \
printf( "Host memory failed in %s at line %d\n", \
__FILE__, __LINE__ ); \
exit( EXIT_FAILURE );}}
template< typename T >
void swap( T& a, T& b ) {
T t = a;
a = b;
b = t;
}
void* big_random_block( int size ) {
unsigned char *data = (unsigned char*)malloc( size );
HANDLE_NULL( data );
for (int i=0; i<size; i++)
data[i] = rand();
return data;
}
int* big_random_block_int( int size ) {
int *data = (int*)malloc( size * sizeof(int) );
HANDLE_NULL( data );
for (int i=0; i<size; i++)
data[i] = rand();
return data;
}
// a place for common kernels - starts here
__device__ unsigned char value( float n1, float n2, int hue ) {
if (hue > 360) hue -= 360;
else if (hue < 0) hue += 360;
if (hue < 60)
return (unsigned char)(255 * (n1 + (n2-n1)*hue/60));
if (hue < 180)
return (unsigned char)(255 * n2);
if (hue < 240)
return (unsigned char)(255 * (n1 + (n2-n1)*(240-hue)/60));
return (unsigned char)(255 * n1);
}
__global__ void float_to_color( unsigned char *optr,
const float *outSrc ) {
// map from threadIdx/BlockIdx to pixel position
int x = threadIdx.x + blockIdx.x * blockDim.x;
int y = threadIdx.y + blockIdx.y * blockDim.y;
int offset = x + y * blockDim.x * gridDim.x;
float l = outSrc[offset];
float s = 1;
int h = (180 + (int)(360.0f * outSrc[offset])) % 360;
float m1, m2;
if (l <= 0.5f)
m2 = l * (1 + s);
else
m2 = l + s - l * s;
m1 = 2 * l - m2;
optr[offset*4 + 0] = value( m1, m2, h+120 );
optr[offset*4 + 1] = value( m1, m2, h );
optr[offset*4 + 2] = value( m1, m2, h -120 );
optr[offset*4 + 3] = 255;
}
__global__ void float_to_color( uchar4 *optr,
const float *outSrc ) {
// map from threadIdx/BlockIdx to pixel position
int x = threadIdx.x + blockIdx.x * blockDim.x;
int y = threadIdx.y + blockIdx.y * blockDim.y;
int offset = x + y * blockDim.x * gridDim.x;
float l = outSrc[offset];
float s = 1;
int h = (180 + (int)(360.0f * outSrc[offset])) % 360;
float m1, m2;
if (l <= 0.5f)
m2 = l * (1 + s);
else
m2 = l + s - l * s;
m1 = 2 * l - m2;
optr[offset].x = value( m1, m2, h+120 );
optr[offset].y = value( m1, m2, h );
optr[offset].z = value( m1, m2, h -120 );
optr[offset].w = 255;
}
#if _WIN32
//Windows threads.
#include <windows.h>
typedef HANDLE CUTThread;
typedef unsigned (WINAPI *CUT_THREADROUTINE)(void *);
#define CUT_THREADPROC unsigned WINAPI
#define CUT_THREADEND return 0
#else
//POSIX threads.
#include <pthread.h>
typedef pthread_t CUTThread;
typedef void *(*CUT_THREADROUTINE)(void *);
#define CUT_THREADPROC void
#define CUT_THREADEND
#endif
//Create thread.
CUTThread start_thread( CUT_THREADROUTINE, void *data );
//Wait for thread to finish.
void end_thread( CUTThread thread );
//Destroy thread.
void destroy_thread( CUTThread thread );
//Wait for multiple threads.
void wait_for_threads( const CUTThread *threads, int num );
#if _WIN32
//Create thread
CUTThread start_thread(CUT_THREADROUTINE func, void *data){
return CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)func, data, 0, NULL);
}
//Wait for thread to finish
void end_thread(CUTThread thread){
WaitForSingleObject(thread, INFINITE);
CloseHandle(thread);
}
//Destroy thread
void destroy_thread( CUTThread thread ){
TerminateThread(thread, 0);
CloseHandle(thread);
}
//Wait for multiple threads
void wait_for_threads(const CUTThread * threads, int num){
WaitForMultipleObjects(num, threads, true, INFINITE);
for(int i = 0; i < num; i++)
CloseHandle(threads[i]);
}
#else
//Create thread
CUTThread start_thread(CUT_THREADROUTINE func, void * data){
pthread_t thread;
pthread_create(&thread, NULL, func, data);
return thread;
}
//Wait for thread to finish
void end_thread(CUTThread thread){
pthread_join(thread, NULL);
}
//Destroy thread
void destroy_thread( CUTThread thread ){
pthread_cancel(thread);
}
//Wait for multiple threads
void wait_for_threads(const CUTThread * threads, int num){
for(int i = 0; i < num; i++)
end_thread( threads[i] );
}
#endif
#endif // __BOOK_H__
optirun
). Driver lain menelurkan saya ke loop login atau hitamunity-greeter
! Saya tidak bisa cukup berterima kasih