Created
May 7, 2012 12:41
-
-
Save ugovaretto/2627550 to your computer and use it in GitHub Desktop.
CUDA pointer info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 2.8) | |
project(cudaptrinfo) | |
include(FindCUDA) | |
include_directories(${CUDA_INCLUDE_DIRS}) | |
set( SRCS cudaptrinfo.cpp ) | |
add_executable( cudaptrinfo ${SRCS} ) | |
target_link_libraries( cudaptrinfo ${CUDA_LIBRARIES} ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cuda_runtime.h> | |
#include <iostream> | |
void print_ptr_attr( const cudaPointerAttributes& pa ) { | |
std::cout << "Pointer attributes:\n"; | |
std::string mt = pa.memoryType == cudaMemoryTypeHost ? "cudaMemoryTypeHost" | |
: "cudaMemoryTypeDevice"; | |
std::cout << " memoryType: " << mt << std::endl; | |
std::cout << " device: " << std::hex << pa.device << std::endl; | |
std::cout << " devicePointer: " << std::hex << pa.devicePointer << std::endl; | |
std::cout << " hostPointer: " << pa.hostPointer << std::endl; | |
} | |
int main( int argc, char** argv ) { | |
char* dev = 0; | |
char* host = 0; | |
cudaMalloc( &dev, 0x10000 ); | |
host = new char[ 0x10000 ]; | |
std::cout << std::endl; | |
std::cout << "Device pointer info" << std::endl | |
<< "-------------------" << std::endl; | |
cudaPointerAttributes attr; | |
cudaPointerGetAttributes( &attr, dev ); | |
print_ptr_attr( attr ); | |
std::cout << std::endl; | |
std::cout << "Host pointer info" << std::endl | |
<< "-----------------" << std::endl; | |
cudaPointerAttributes attr2; | |
cudaPointerGetAttributes( &attr2, host ); | |
print_ptr_attr( attr2 ); | |
cudaFree( dev ); | |
delete [] host; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment