Skip to content

Commit

Permalink
Cpp version of Exercise 1 added
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdeakin committed Aug 22, 2013
1 parent 32dbf20 commit 277abed
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Exercises/Exercise05/C/vadd
Exercises/Exercise08/C/pi
Exercises/Exercise06/C/mult

Exercises/Exercise01/Cpp/DeviceInfo

Solutions/Exercise04/C/vadd_chain
Solutions/Exercise05/C/vadd_abc
Solutions/Exercise08/C/pi_ocl
Expand Down
95 changes: 95 additions & 0 deletions Exercises/Exercise01/Cpp/DeviceInfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Display Device Information
*
* Script to print out some information about the OpenCL devices
* and platforms available on your system
*
* History: C++ version written by Tom Deakin, 2012
* Updated by Tom Deakin, August 2013
*/

#define __CL_ENABLE_EXCEPTIONS

#include "cl.hpp"
#include <iostream>
#include <vector>

int main(void)
{

try
{
// Discover number of platforms
std::vector<cl::Platform> platforms;
cl::Platform::get(&platforms);
std::cout << "\nNumber of OpenCL plaforms: " << platforms.size() << std::endl;

// Investigate each platform
std::cout << "\n-------------------------" << std::endl;
for (cl::Platform& plat : platforms)
{
std::string s;
plat.getInfo(CL_PLATFORM_NAME, &s);
std::cout << "Platform: " << s << std::endl;

plat.getInfo(CL_PLATFORM_VENDOR, &s);
std::cout << "\tVendor: " << s << std::endl;

plat.getInfo(CL_PLATFORM_VERSION, &s);
std::cout << "\tVersion: " << s << std::endl;

// Discover number of devices
std::vector<cl::Device> devices;
plat.getDevices(CL_DEVICE_TYPE_ALL, &devices);
std::cout << "\n\tNumber of devices: " << devices.size() << std::endl;

// Investigate each device
for (cl::Device& dev : devices)
{
std::cout << "\t-------------------------" << std::endl;

dev.getInfo(CL_DEVICE_NAME, &s);
std::cout << "\t\tName: " << s << std::endl;

int i;
dev.getInfo(CL_DEVICE_MAX_COMPUTE_UNITS, &i);
std::cout << "\t\tMax. Compute Units: " << i << std::endl;

size_t size;
dev.getInfo(CL_DEVICE_LOCAL_MEM_SIZE, &size);
std::cout << "\t\tLocal Memory Size: " << size/1024 << " KB" << std::endl;

dev.getInfo(CL_DEVICE_GLOBAL_MEM_SIZE, &size);
std::cout << "\t\tGlobal Memory Size: " << size/(1024*1024) << " MB" << std::endl;

dev.getInfo(CL_DEVICE_MAX_MEM_ALLOC_SIZE, &size);
std::cout << "\t\tMax Alloc Size: " << size/(1024*1024) << " MB" << std::endl;

dev.getInfo(CL_DEVICE_MAX_WORK_GROUP_SIZE, &size);
std::cout << "\t\tMax Work-group Size: " << size << std::endl;

std::vector<size_t> d;
dev.getInfo(CL_DEVICE_MAX_WORK_ITEM_SIZES, &d);
std::cout << "\t\tMax Work-item Dims: (";
for (size_t& st : d)
std::cout << st << " ";
std::cout << "\x08)" << std::endl;

std::cout << "\t-------------------------" << std::endl;

}

std::cout << "\n-------------------------\n";
}

}
catch (cl::Error err)
{
std::cout << "OpenCL Error: " << err.what() << " returned " << err.err() << std::endl;
std::cout << "Check cl.h for error codes." << std::endl;
exit(-1);
}

return 0;

}
25 changes: 25 additions & 0 deletions Exercises/Exercise01/Cpp/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

CC=g++

CPP_COMMON = ../../Cpp_common

CCFLAGS=-std=c++11 -std=gnu++11

INC = -I $(CPP_COMMON)

LIBS = -lOpenCL

# Check our platform and make sure we define the APPLE variable
# and set up the right compiler flags and libraries
PLATFORM = $(shell uname -s)
ifeq ($(PLATFORM), Darwin)
CCFLAGS += -DAPPLE
LIBS = -framework OpenCL
endif

DeviceInfo: DeviceInfo.cpp
$(CC) $^ $(INC) $(CCFLAGS) $(LIBS) -o $@


clean:
rm -f DeviceInfo

0 comments on commit 277abed

Please sign in to comment.