[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39303] branches/cycles/intern/cycles: Cycles: more opencl tweaks, status is:
Brecht Van Lommel
brechtvanlommel at pandora.be
Thu Aug 11 14:36:09 CEST 2011
Revision: 39303
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39303
Author: blendix
Date: 2011-08-11 12:36:08 +0000 (Thu, 11 Aug 2011)
Log Message:
-----------
Cycles: more opencl tweaks, status is:
* kernel has shading nodes / textures disabled, amd/nvidia opencl
compilers choke on these, need to figure out how to avoid this
* works in cycles_test, not available as option in blender yet
* kernel compiles and runs with opencl 1.1 from intel/amd/nvidia
Modified Paths:
--------------
branches/cycles/intern/cycles/app/cycles_test.cpp
branches/cycles/intern/cycles/device/device_opencl.cpp
branches/cycles/intern/cycles/kernel/CMakeLists.txt
branches/cycles/intern/cycles/kernel/kernel_compat_opencl.h
branches/cycles/intern/cycles/kernel/kernel_types.h
Modified: branches/cycles/intern/cycles/app/cycles_test.cpp
===================================================================
--- branches/cycles/intern/cycles/app/cycles_test.cpp 2011-08-11 11:56:02 UTC (rev 39302)
+++ branches/cycles/intern/cycles/app/cycles_test.cpp 2011-08-11 12:36:08 UTC (rev 39303)
@@ -284,7 +284,7 @@
int main(int argc, const char **argv)
{
- path_init();
+ path_init("../blender/intern/cycles");
options_parse(argc, argv);
Modified: branches/cycles/intern/cycles/device/device_opencl.cpp
===================================================================
--- branches/cycles/intern/cycles/device/device_opencl.cpp 2011-08-11 11:56:02 UTC (rev 39302)
+++ branches/cycles/intern/cycles/device/device_opencl.cpp 2011-08-11 12:36:08 UTC (rev 39303)
@@ -45,7 +45,7 @@
class OpenCLDevice : public Device
{
public:
- cl_context cxGPUContext;
+ cl_context cxContext;
cl_command_queue cqCommandQueue;
cl_platform_id cpPlatform;
cl_device_id cdDevice;
@@ -121,19 +121,28 @@
OpenCLDevice(bool background_)
{
background = background_;
+ vector<cl_platform_id> platform_ids;
+ cl_uint num_platforms;
/* setup device */
- ciErr = clGetPlatformIDs(1, &cpPlatform, NULL);
+ ciErr = clGetPlatformIDs(0, NULL, &num_platforms);
opencl_assert(ciErr);
+ assert(num_platforms != 0);
- ciErr = clGetDeviceIDs(cpPlatform, CL_DEVICE_TYPE_CPU, 1, &cdDevice, NULL);
+ platform_ids.resize(num_platforms);
+ ciErr = clGetPlatformIDs(num_platforms, &platform_ids[0], NULL);
opencl_assert(ciErr);
- cxGPUContext = clCreateContext(0, 1, &cdDevice, NULL, NULL, &ciErr);
+ cpPlatform = platform_ids[0]; /* todo: pick specified platform && device */
+
+ ciErr = clGetDeviceIDs(cpPlatform, CL_DEVICE_TYPE_ALL, 1, &cdDevice, NULL);
opencl_assert(ciErr);
- cqCommandQueue = clCreateCommandQueue(cxGPUContext, cdDevice, 0, &ciErr);
+ cxContext = clCreateContext(0, 1, &cdDevice, NULL, NULL, &ciErr);
opencl_assert(ciErr);
+
+ cqCommandQueue = clCreateCommandQueue(cxContext, cdDevice, 0, &ciErr);
+ opencl_assert(ciErr);
/* compile kernel */
string source = string_printf("#include \"kernel.cl\" // %lf\n", time_dt());
@@ -141,16 +150,12 @@
string build_options = "";
- //string csource = "../blender/intern/cycles";
- //build_options += "-I " + csource + "/kernel -I " + csource + "/util";
+ string csource = "../blender/intern/cycles";
+ build_options += "-I " + path_get("kernel") + " -I " + path_get("util"); /* todo: escape path */
+ build_options += " -Werror -cl-fast-relaxed-math -cl-strict-aliasing";
- build_options += " -I " + path_get("kernel"); /* todo: escape path */
+ cpProgram = clCreateProgramWithSource(cxContext, 1, (const char **)&source, &source_len, &ciErr);
- build_options += " -Werror";
- build_options += " -DCCL_NAMESPACE_BEGIN= -DCCL_NAMESPACE_END=";
-
- cpProgram = clCreateProgramWithSource(cxGPUContext, 1, (const char **)&source, &source_len, &ciErr);
-
opencl_assert(ciErr);
ciErr = clBuildProgram(cpProgram, 0, NULL, build_options.c_str(), NULL, NULL);
@@ -178,7 +183,7 @@
ckFilmConvertKernel = clCreateKernel(cpProgram, "kernel_ocl_tonemap", &ciErr);
opencl_assert(ciErr);
- null_mem = (device_ptr)clCreateBuffer(cxGPUContext, CL_MEM_READ_ONLY, 1, NULL, &ciErr);
+ null_mem = (device_ptr)clCreateBuffer(cxContext, CL_MEM_READ_ONLY, 1, NULL, &ciErr);
}
~OpenCLDevice()
@@ -196,7 +201,7 @@
clReleaseKernel(ckFilmConvertKernel);
clReleaseProgram(cpProgram);
clReleaseCommandQueue(cqCommandQueue);
- clReleaseContext(cxGPUContext);
+ clReleaseContext(cxContext);
}
string description()
@@ -213,11 +218,11 @@
size_t size = mem.memory_size();
if(type == MEM_READ_ONLY)
- mem.device_pointer = (device_ptr)clCreateBuffer(cxGPUContext, CL_MEM_READ_ONLY, size, NULL, &ciErr);
+ mem.device_pointer = (device_ptr)clCreateBuffer(cxContext, CL_MEM_READ_ONLY, size, NULL, &ciErr);
else if(type == MEM_WRITE_ONLY)
- mem.device_pointer = (device_ptr)clCreateBuffer(cxGPUContext, CL_MEM_WRITE_ONLY, size, NULL, &ciErr);
+ mem.device_pointer = (device_ptr)clCreateBuffer(cxContext, CL_MEM_WRITE_ONLY, size, NULL, &ciErr);
else
- mem.device_pointer = (device_ptr)clCreateBuffer(cxGPUContext, CL_MEM_READ_WRITE, size, NULL, &ciErr);
+ mem.device_pointer = (device_ptr)clCreateBuffer(cxContext, CL_MEM_READ_WRITE, size, NULL, &ciErr);
opencl_assert(ciErr);
}
@@ -321,7 +326,7 @@
opencl_assert(ciErr);
- size_t local_size[2] = {1, 1};
+ size_t local_size[2] = {8, 8};
size_t global_size[2] = {global_size_round_up(local_size[0], d_w), global_size_round_up(local_size[1], d_h)};
/* run kernel */
@@ -389,7 +394,7 @@
opencl_assert(ciErr);
- size_t local_size[2] = {1, 1};
+ size_t local_size[2] = {8, 8};
size_t global_size[2] = {global_size_round_up(local_size[0], d_w), global_size_round_up(local_size[1], d_h)};
/* run kernel */
Modified: branches/cycles/intern/cycles/kernel/CMakeLists.txt
===================================================================
--- branches/cycles/intern/cycles/kernel/CMakeLists.txt 2011-08-11 11:56:02 UTC (rev 39302)
+++ branches/cycles/intern/cycles/kernel/CMakeLists.txt 2011-08-11 12:36:08 UTC (rev 39303)
@@ -72,6 +72,12 @@
svm/volume.h
)
+SET(util_headers
+ ../util/util_color.h
+ ../util/util_math.h
+ ../util/util_transform.h
+ ../util/util_types.h)
+
# CUDA module
IF("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
@@ -118,11 +124,13 @@
# OPENCL kernel
IF(WITH_CYCLES_OPENCL)
- SET(util_headers
- ../util/util_color.h
- ../util/util_math.h
- ../util/util_transform.h
- ../util/util_types.h)
+ #SET(kernel_preprocessed ${CMAKE_CURRENT_BINARY_DIR}/kernel_preprocessed.cl)
+ #ADD_CUSTOM_COMMAND(
+ # OUTPUT ${kernel_preprocessed}
+ # COMMAND gcc -x c++ -E ${CMAKE_CURRENT_SOURCE_DIR}/kernel.cl -I ${CMAKE_CURRENT_SOURCE_DIR}/../util/ -DCCL_NAMESPACE_BEGIN= -DCCL_NAMESPACE_END= -DWITH_OPENCL -o ${kernel_preprocessed}
+ # DEPENDS ${kernel_sources} ${util_headers})
+ #ADD_CUSTOM_TARGET(cycles_kernel_preprocess ALL DEPENDS ${kernel_preprocessed})
+ #INSTALL(FILES ${kernel_preprocessed} DESTINATION ${CYCLES_INSTALL_PATH}/cycles/kernel)
INSTALL(FILES kernel.cl ${headers} DESTINATION ${CYCLES_INSTALL_PATH}/cycles/kernel)
INSTALL(FILES ${svm_headers} DESTINATION ${CYCLES_INSTALL_PATH}/cycles/kernel/svm)
Modified: branches/cycles/intern/cycles/kernel/kernel_compat_opencl.h
===================================================================
--- branches/cycles/intern/cycles/kernel/kernel_compat_opencl.h 2011-08-11 11:56:02 UTC (rev 39302)
+++ branches/cycles/intern/cycles/kernel/kernel_compat_opencl.h 2011-08-11 12:36:08 UTC (rev 39303)
@@ -22,7 +22,10 @@
#define __KERNEL_GPU__
#define __KERNEL_OPENCL__
-CCL_NAMESPACE_BEGIN
+/* no namespaces in opencl */
+#define CCL_NAMESPACE_BEGIN
+#define CCL_NAMESPACE_END
+#define WITH_OPENCL
/* in opencl all functions are device functions, so leave this empty */
#define __device
@@ -104,7 +107,5 @@
#include "util_types.h"
-CCL_NAMESPACE_END
-
#endif /* __KERNEL_COMPAT_OPENCL_H__ */
Modified: branches/cycles/intern/cycles/kernel/kernel_types.h
===================================================================
--- branches/cycles/intern/cycles/kernel/kernel_types.h 2011-08-11 11:56:02 UTC (rev 39302)
+++ branches/cycles/intern/cycles/kernel/kernel_types.h 2011-08-11 12:36:08 UTC (rev 39303)
@@ -34,8 +34,8 @@
#define __BACKGROUND__
#define __EMISSION__
#define __CAUSTICS_TRICKS__
+#ifndef __KERNEL_OPENCL__
#define __SVM__
-#ifndef __KERNEL_OPENCL__
#define __TEXTURES__
#endif
#define __RAY_DIFFERENTIALS__
More information about the Bf-blender-cvs
mailing list