首页 > 解决方案 > OpenCL 程序在使用 MinGW 编译时无法识别驱动程序,但在使用 Visual Studio 构建时正常运行

问题描述

我一直在研究一个 OpenCL 程序,该程序可以试用 Mersenne 数。当我使用 Microsoft Visual Studio 编译它时,它按预期工作。但是,尽管它也可以使用 MinGW(64 位)编译而没有错误,但该程序似乎无法与 OpenCL 驱动程序一起使用。

在初始化例程之后,程序应该打印有关所选设备的信息。但是,程序在启动后立即终止并且不打印任何错误。我在几台计算机上尝试了同样的事情,但它只在一台计算机上工作。任何人都知道可能导致此问题的原因是什么?

这是完整的存储库供参考:https ://github.com/Bdot42/mfakto

这是带有我修改的makefile:

# set x86_64 (64-bit) as default
BITS := x86_64
BITFLAG := -m64

# check whether to build 32-bit version
ifdef bitness
  ifeq ($(bitness), 32)
    BITS := x86
    BITFLAG := -m32
  endif
endif

# Check if static linking is requested
ifdef static
  ifeq ($(static), yes)
    STATIC := -static
  endif
endif

# some commands won't work on Windows
ifeq ($(OS), Windows_NT)
  CP = copy
  RM = del /f
else
  CP = cp
  RM = rm -f
endif

# where is the OpenCL SDK installed?
AMD_APP_DIR = c:\ocl
AMD_APP_INCLUDE = -I$(AMD_APP_DIR)\include
AMD_APP_LIB = -L$(AMD_APP_DIR)\lib\$(BITS)

# Change needed for compilation with amdgpu-pro
# AMD_APP_DIR = /opt/amdgpu-pro/opencl

# optimize or debug
#OPTIMIZE_FLAG = -O3
#OPTIMIZE_FLAG = -O3 -funroll-loops  -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las
OPTIMIZE_FLAG = -O3 -funroll-loops  -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto
#OPTIMIZE_FLAG = -g

# Compiler settings for .c files (CPU)
CC = gcc
CPP = $(CC)
CFLAGS = $(BITFLAG) -Wall $(OPTIMIZE_FLAG) $(AMD_APP_INCLUDE) -DBUILD_OPENCL
CPP_FLAGS =
#CFLAGS_EXTRA_SIEVE = -funroll-all-loops
#CFLAGS_EXTRA_SIEVE = -funroll-all-loops -funsafe-loop-optimizations -fira-region=all -fsched-spec-load -fsched-stalled-insns=10 -fsched-stalled-insns-dep=10 -floop-parallelize-all -fvariable-expansion-in-unroller -fno-align-labels
CFLAGS_EXTRA_SIEVE = -funroll-all-loops -funsafe-loop-optimizations -fira-region=all -fsched-spec-load -fsched-stalled-insns=10 -fsched-stalled-insns-dep=10 -fno-align-labels


# Linker
LD = g++
LDFLAGS = $(BITFLAG) $(STATIC) $(OPTIMIZE_FLAG) $(AMD_APP_LIB) -lOpenCL

##############################################################################

CSRC  = sieve.c timer.c parse.c read_config.c mfaktc.c checkpoint.c \
    signal_handler.c filelocking.c output.c

# CLSRC = barrett15.cl  barrett.cl  common.cl  gpusieve.cl  mfakto_Kernels.cl  montgomery.cl  mul24.cl

COBJS  = $(CSRC:.c=.o) mfakto.o gpusieve.o perftest.o menu.o kbhit.o

##############################################################################

all: ../mfakto ../barrett15.cl  ../barrett.cl  ../common.cl  ../gpusieve.cl  ../mfakto_Kernels.cl  ../montgomery.cl  ../mul24.cl ../datatypes.h ../tf_debug.h ../mfakto.ini

../mfakto : $(COBJS)
    $(LD) $^ $(LDFLAGS) -o $@

clean :
    $(RM) *.o *~

sieve.o : sieve.c
    $(CC) $(CFLAGS) $(CFLAGS_EXTRA_SIEVE) -c $< -o $@

%.o : %.c
    $(CC) $(CFLAGS) -c $< -o $@

%.o : %.cpp
    $(CPP) $(CFLAGS) $(CPP_FLAGS) -c $< -o $@

../%.cl : %.cl
    $(CP) $< ..

../%.h : %.h
    $(CP) $< ..

../%.ini : %.ini
    $(CP) $< ..

##############################################################################

# dependencies generated by cpp -MM (manually replaced AMD_APP_DIR)
#

checkpoint.o: checkpoint.c params.h timer.h

filelocking.o: filelocking.c

mfaktc.o: mfaktc.c $(AMD_APP_DIR)/include/CL/cl.h \
 $(AMD_APP_DIR)/include/CL/cl_platform.h params.h my_types.h compatibility.h \
 sieve.h read_config.h parse.h timer.h checkpoint.h signal_handler.h \
 filelocking.h perftest.h mfakto.h gpusieve.h output.h selftest-data.h

output.o: output.c params.h my_types.h $(AMD_APP_DIR)/include/CL/cl.h \
 $(AMD_APP_DIR)/include/CL/cl_platform.h output.h filelocking.h \
 compatibility.h

parse.o: parse.c compatibility.h filelocking.h parse.h

read_config.o: read_config.c params.h my_types.h \
 $(AMD_APP_DIR)/include/CL/cl.h $(AMD_APP_DIR)/include/CL/cl_platform.h

sieve.o: sieve.c params.h compatibility.h

signal_handler.o: signal_handler.c params.h my_types.h \
 $(AMD_APP_DIR)/include/CL/cl.h $(AMD_APP_DIR)/include/CL/cl_platform.h \
 compatibility.h

timer.o: timer.c timer.h compatibility.h

gpusieve.o: gpusieve.cpp $(AMD_APP_DIR)/include/CL/cl.h \
 $(AMD_APP_DIR)/include/CL/cl_platform.h my_types.h params.h compatibility.h

mfakto.o: mfakto.cpp $(AMD_APP_DIR)/include/CL/cl.h \
 $(AMD_APP_DIR)/include/CL/cl_platform.h params.h my_types.h compatibility.h \
 read_config.h parse.h sieve.h timer.h checkpoint.h filelocking.h \
 perftest.h mfakto.h output.h gpusieve.h signal_handler.h

perftest.o: perftest.cpp $(AMD_APP_DIR)/include/CL/cl.h \
 $(AMD_APP_DIR)/include/CL/cl_platform.h params.h my_types.h compatibility.h \
 read_config.h parse.h sieve.h timer.h checkpoint.h filelocking.h \
 signal_handler.h mfakto.h

menu.o: menu.h compatibility.h my_types.h

kbhit.o: kbhit.h

标签: compilationopenclmingw-w64

解决方案


推荐阅读