Permalink
Browse files

Add OpenCL device query example from CUDA SDK

This will give a basis for further CUDA/OpenCL-based GPU code.
  • Loading branch information...
1 parent 4d12ce7 commit aa60fffcf86b55fcd0723a02dd5797559ba61400 @Beirdo committed Oct 12, 2011
Showing with 621 additions and 0 deletions.
  1. +3 −0 src/.gitignore
  2. +4 −0 src/ocldevice/.gitignore
  3. +53 −0 src/ocldevice/Makefile
  4. +274 −0 src/ocldevice/common_opencl.mk
  5. +287 −0 src/ocldevice/oclDeviceQuery.cpp
View
@@ -2,3 +2,6 @@
*.o
gputrans
test_decode
+*.ppm
+*.mpg
+tmp
View
@@ -0,0 +1,4 @@
+!Makefile
+oclDeviceQuery
+oclDeviceQuery.txt
+SdkMasterLog.csv
View
@@ -0,0 +1,53 @@
+################################################################################
+#
+# Copyright 1993-2009 NVIDIA Corporation. All rights reserved.
+#
+# NOTICE TO USER:
+#
+# This source code is subject to NVIDIA ownership rights under U.S. and
+# international Copyright laws.
+#
+# NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE
+# CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR
+# IMPLIED WARRANTY OF ANY KIND. NVIDIA DISCLAIMS ALL WARRANTIES WITH
+# REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
+# IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
+# OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
+# OR PERFORMANCE OF THIS SOURCE CODE.
+#
+# U.S. Government End Users. This source code is a "commercial item" as
+# that term is defined at 48 C.F.R. 2.101 (OCT 1995), consisting of
+# "commercial computer software" and "commercial computer software
+# documentation" as such terms are used in 48 C.F.R. 12.212 (SEPT 1995)
+# and is provided to the U.S. Government only as a commercial end item.
+# Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through
+# 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the
+# source code with only those rights set forth herein.
+#
+################################################################################
+#
+# Build script for project
+#
+################################################################################
+
+# Add source files here
+EXECUTABLE := oclDeviceQuery
+# C/C++ source files (compiled with gcc / c++)
+CCFILES := oclDeviceQuery.cpp
+
+CUDASDK = /home/gjhurlbu/NVIDIA_GPU_Computing_SDK
+ROOTDIR = ${CUDASDK}
+
+################################################################################
+# Rules and targets
+
+# NOTE: Assuming P4 based install until OpenCL becomes public
+# Adjust P4_Root, default is ${HOME}/perforce/
+# P4_ROOT=${HOME}/myperforce/
+
+include common_opencl.mk
+
+
@@ -0,0 +1,274 @@
+################################################################################
+#
+# Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
+#
+# NOTICE TO USER:
+#
+# This source code is subject to NVIDIA ownership rights under U.S. and
+# international Copyright laws.
+#
+# NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE
+# CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR
+# IMPLIED WARRANTY OF ANY KIND. NVIDIA DISCLAIMS ALL WARRANTIES WITH
+# REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
+# IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
+# OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
+# OR PERFORMANCE OF THIS SOURCE CODE.
+#
+# U.S. Government End Users. This source code is a "commercial item" as
+# that term is defined at 48 C.F.R. 2.101 (OCT 1995), consisting of
+# "commercial computer software" and "commercial computer software
+# documentation" as such terms are used in 48 C.F.R. 12.212 (SEPT 1995)
+# and is provided to the U.S. Government only as a commercial end item.
+# Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through
+# 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the
+# source code with only those rights set forth herein.
+#
+################################################################################
+#
+# Common build script for OpenCL samples
+#
+################################################################################
+
+.SUFFIXES : .cl
+
+P4_ROOT ?= ${HOME}/perforce/
+
+# detect OS
+OSUPPER = $(shell uname -s 2>/dev/null | tr [:lower:] [:upper:])
+OSLOWER = $(shell uname -s 2>/dev/null | tr [:upper:] [:lower:])
+# 'linux' is output for Linux system, 'darwin' for OS X
+DARWIN = $(strip $(findstring DARWIN, $(OSUPPER)))
+ifneq ($(DARWIN),)
+ SNOWLEOPARD = $(strip $(findstring 10.6, $(shell egrep "<string>10\.6" /System/Library/CoreServices/SystemVersion.plist)))
+endif
+
+
+# detect if 32 bit or 64 bit system
+HP_64 = $(shell uname -m | grep 64)
+OSARCH= $(shell uname -m)
+
+# Basic directory setup for SDK
+# (override directories only if they are not already defined)
+SRCDIR ?=
+ROOTDIR ?= ../../../
+ROOTOBJDIR ?= obj
+LIBDIR := $(ROOTDIR)/shared/lib/
+SHAREDDIR := $(ROOTDIR)/shared/
+OCLROOTDIR := $(ROOTDIR)/OpenCL/
+OCLCOMMONDIR ?= $(OCLROOTDIR)/common/
+OCLBINDIR ?= $(OCLROOTDIR)/bin/
+BINDIR ?= $(OCLBINDIR)/$(OSLOWER)
+OCLLIBDIR := $(OCLCOMMONDIR)/lib
+INCDIR ?= .
+
+# Compilers
+CXX := g++
+CC := gcc
+LINK := g++ -fPIC
+
+# Includes
+INCLUDES += -I$(INCDIR) -I$(OCLCOMMONDIR)/inc -I$(SHAREDDIR)/inc
+
+ifeq "$(strip $(HP_64))" ""
+ MACHINE := 32
+ USRLIBDIR := -L/usr/lib/
+else
+ MACHINE := 64
+ USRLIBDIR := -L/usr/lib64/
+endif
+
+
+# Warning flags
+CXXWARN_FLAGS := \
+ -W -Wall \
+ -Wimplicit \
+ -Wswitch \
+ -Wformat \
+ -Wchar-subscripts \
+ -Wparentheses \
+ -Wmultichar \
+ -Wtrigraphs \
+ -Wpointer-arith \
+ -Wcast-align \
+ -Wreturn-type \
+ -Wno-unused-function \
+ $(SPACE)
+
+CWARN_FLAGS := $(CXXWARN_FLAGS) \
+ -Wstrict-prototypes \
+ -Wmissing-prototypes \
+ -Wmissing-declarations \
+ -Wnested-externs \
+ -Wmain \
+
+
+# architecture flag for nvcc and gcc compilers build
+LIB_ARCH := $(OSARCH)
+
+# Determining the necessary Cross-Compilation Flags
+# 32-bit OS, but we target 64-bit cross compilation
+ifeq ($(x86_64),1)
+ LIB_ARCH = x86_64
+
+ ifneq ($(DARWIN),)
+ CXX_ARCH_FLAGS += -arch x86_64
+ else
+ CXX_ARCH_FLAGS += -m64
+ endif
+else
+# 64-bit OS, and we target 32-bit cross compilation
+ ifeq ($(i386),1)
+ LIB_ARCH = i386
+ ifneq ($(DARWIN),)
+ CXX_ARCH_FLAGS += -arch i386
+ else
+ CXX_ARCH_FLAGS += -m32
+ endif
+ else
+ ifeq "$(strip $(HP_64))" ""
+ LIB_ARCH = i386
+ ifneq ($(DARWIN),)
+ CXX_ARCH_FLAGS += -arch i386
+ else
+ CXX_ARCH_FLAGS += -m32
+ endif
+ else
+ LIB_ARCH = x86_64
+ ifneq ($(DARWIN),)
+ CXX_ARCH_FLAGS += -arch x86_64
+ else
+ CXX_ARCH_FLAGS += -m64
+ endif
+ endif
+ endif
+endif
+
+# Compiler-specific flags
+CXXFLAGS := $(CXXWARN_FLAGS) $(CXX_ARCH_FLAGS)
+CFLAGS := $(CWARN_FLAGS) $(CXX_ARCH_FLAGS)
+LINK += $(CXX_ARCH_FLAGS)
+
+# Common flags
+COMMONFLAGS += $(INCLUDES) -DUNIX
+
+# Add Mac Flags
+ifneq ($(DARWIN),)
+ COMMONFLAGS += -DMAC
+endif
+
+# Debug/release configuration
+ifeq ($(dbg),1)
+ COMMONFLAGS += -g
+ BINSUBDIR := debug
+ LIBSUFFIX := D
+else
+ COMMONFLAGS += -O3
+ BINSUBDIR := release
+ LIBSUFFIX :=
+ CXXFLAGS += -fno-strict-aliasing
+ CFLAGS += -fno-strict-aliasing
+endif
+
+
+# OpenGL is used or not (if it is used, then it is necessary to include GLEW)
+ifeq ($(USEGLLIB),1)
+
+ ifneq ($(DARWIN),)
+ OPENGLLIB := -L/System/Library/Frameworks/OpenGL.framework/Libraries -lGL -lGLU $(SHAREDDIR)/lib/$(OSLOWER)/libGLEW.a
+ else
+ OPENGLLIB := -lGL -lGLU -lX11 -lXmu
+ ifeq "$(strip $(HP_64))" ""
+ OPENGLLIB += -lGLEW -L/usr/X11R6/lib
+ else
+ OPENGLLIB += -lGLEW_x86_64 -L/usr/X11R6/lib64
+ endif
+ endif
+
+ CUBIN_ARCH_FLAG := -m64
+endif
+
+ifeq ($(USEGLUT),1)
+ ifneq ($(DARWIN),)
+ OPENGLLIB += -framework GLUT
+ INCLUDES += -I/System/Library/Frameworks/OpenGL.framework/Headers
+ else
+ OPENGLLIB += -lglut
+ endif
+endif
+
+# Libs
+ifneq ($(DARWIN),)
+ LIB := -L${OCLLIBDIR} -L$(LIBDIR) -L$(SHAREDDIR)/lib/$(OSLOWER)
+ LIB += -framework OpenCL -framework OpenGL ${OPENGLLIB} -framework AppKit ${ATF} ${LIB}
+else
+ LIB := ${USRLIBDIR} -L${OCLLIBDIR} -L$(LIBDIR) -L$(SHAREDDIR)/lib/$(OSLOWER)
+ LIB += -lOpenCL ${OPENGLLIB} ${LIB}
+endif
+
+
+# Lib/exe configuration
+ifneq ($(STATIC_LIB),)
+ TARGETDIR := $(OCLLIBDIR)
+ TARGET := $(subst .a,_$(LIB_ARCH)$(LIBSUFFIX).a,$(OCLLIBDIR)/$(STATIC_LIB))
+ LINKLINE = ar qv $(TARGET) $(OBJS)
+else
+ LIB += -loclUtil_$(LIB_ARCH)$(LIBSUFFIX) -lshrutil_$(LIB_ARCH)$(LIBSUFFIX)
+ TARGETDIR := $(BINDIR)/$(BINSUBDIR)
+ TARGET := $(EXECUTABLE)
+ LINKLINE = $(LINK) -o $(TARGET) $(OBJS) $(LIB)
+endif
+
+# check if verbose
+ifeq ($(verbose), 1)
+ VERBOSE :=
+else
+ VERBOSE := @
+endif
+
+# Add common flags
+CXXFLAGS += $(COMMONFLAGS)
+CFLAGS += $(COMMONFLAGS)
+
+
+################################################################################
+# Set up object files
+################################################################################
+OBJDIR := $(ROOTOBJDIR)/$(BINSUBDIR)
+OBJS += $(patsubst %.cpp,$(OBJDIR)/%.cpp.o,$(notdir $(CCFILES)))
+OBJS += $(patsubst %.c,$(OBJDIR)/%.c.o,$(notdir $(CFILES)))
+
+################################################################################
+# Rules
+################################################################################
+$(OBJDIR)/%.c.o : $(SRCDIR)%.c $(C_DEPS)
+ $(VERBOSE)$(CC) $(CFLAGS) -o $@ -c $<
+
+$(OBJDIR)/%.cpp.o : $(SRCDIR)%.cpp $(C_DEPS)
+ $(VERBOSE)$(CXX) $(CXXFLAGS) -o $@ -c $<
+
+$(TARGET): makedirectories $(OBJS) Makefile
+ $(VERBOSE)$(LINKLINE)
+
+makedirectories:
+ $(VERBOSE)mkdir -p $(LIBDIR)
+ $(VERBOSE)mkdir -p $(OBJDIR)
+ $(VERBOSE)mkdir -p $(TARGETDIR)
+
+
+tidy :
+ $(VERBOSE)find . | egrep "#" | xargs rm -f
+ $(VERBOSE)find . | egrep "\~" | xargs rm -f
+
+clean : tidy
+ $(VERBOSE)rm -f $(OBJS)
+ $(VERBOSE)rm -f $(TARGET)
+
+clobber : clean
+ $(VERBOSE)rm -rf $(ROOTOBJDIR)
+ $(VERBOSE)find $(TARGETDIR) | egrep "ptx" | xargs rm -f
+ $(VERBOSE)find $(TARGETDIR) | egrep "txt" | xargs rm -f
+ $(VERBOSE)rm -f $(TARGETDIR)/samples.list
Oops, something went wrong.

0 comments on commit aa60fff

Please sign in to comment.