summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDenis Steckelmacher <steckdenis@yahoo.fr>2011-07-27 19:57:16 +0200
committerDenis Steckelmacher <steckdenis@yahoo.fr>2011-07-27 19:57:16 +0200
commit9846ba66a2652fcac682daf961f7c059ea2df2e6 (patch)
tree2bed66f776e23918e5f7feab440d5757d8bf7a9e /src
parent28144b892f01f16cf5ee0581e58860674b53112a (diff)
Implement clCreateImage2D
Diffstat (limited to 'src')
-rw-r--r--src/api/api_memory.cpp25
-rw-r--r--src/core/cpu/buffer.cpp3
-rw-r--r--src/core/memobject.cpp64
-rw-r--r--src/core/memobject.h2
4 files changed, 82 insertions, 12 deletions
diff --git a/src/api/api_memory.cpp b/src/api/api_memory.cpp
index 5d1297c..602b9b1 100644
--- a/src/api/api_memory.cpp
+++ b/src/api/api_memory.cpp
@@ -101,7 +101,30 @@ clCreateImage2D(cl_context context,
void * host_ptr,
cl_int * errcode_ret)
{
- return 0;
+ cl_int dummy_errcode;
+
+ if (!errcode_ret)
+ errcode_ret = &dummy_errcode;
+
+ if (!context)
+ {
+ *errcode_ret = CL_INVALID_CONTEXT;
+ return 0;
+ }
+
+ *errcode_ret = CL_SUCCESS;
+
+ Coal::Image2D *image = new Coal::Image2D(context, image_width, image_height,
+ image_row_pitch, image_format,
+ host_ptr, flags, errcode_ret);
+
+ if (*errcode_ret != CL_SUCCESS || (*errcode_ret = image->init()) != CL_SUCCESS)
+ {
+ delete image;
+ return 0;
+ }
+
+ return (cl_mem)image;
}
cl_mem
diff --git a/src/core/cpu/buffer.cpp b/src/core/cpu/buffer.cpp
index 1d633ed..a2a2d97 100644
--- a/src/core/cpu/buffer.cpp
+++ b/src/core/cpu/buffer.cpp
@@ -30,6 +30,9 @@ CPUBuffer::CPUBuffer(CPUDevice *device, MemObject *buffer, cl_int *rs)
// We use the host ptr, we are already allocated
p_data = buffer->host_ptr();
}
+
+ // NOTE: This function can also reject Image buffers by setting a value
+ // != CL_SUCCESS in rs.
}
CPUBuffer::~CPUBuffer()
diff --git a/src/core/memobject.cpp b/src/core/memobject.cpp
index 01df144..1213282 100644
--- a/src/core/memobject.cpp
+++ b/src/core/memobject.cpp
@@ -78,7 +78,7 @@ cl_int MemObject::init()
DeviceInterface **devices = 0;
cl_int rs;
- rs = context()->info(CL_CONTEXT_NUM_DEVICES, sizeof(uint), &p_num_devices, 0);
+ rs = context()->info(CL_CONTEXT_NUM_DEVICES, sizeof(unsigned int), &p_num_devices, 0);
if (rs != CL_SUCCESS)
return rs;
@@ -130,19 +130,29 @@ cl_int MemObject::init()
}
// Create a DeviceBuffer for each device
+ unsigned int failed_devices = 0;
+
for (int i=0; i<p_num_devices; ++i)
{
DeviceInterface *device = devices[i];
+ rs = CL_SUCCESS;
p_devicebuffers[i] = device->createDeviceBuffer(this, &rs);
if (rs != CL_SUCCESS)
{
- std::free((void *)devices);
- return rs;
+ p_devicebuffers[i] = 0;
+ failed_devices++;
}
}
+ if (failed_devices == p_num_devices)
+ {
+ // Each device found a reason to reject the buffer, so it's invalid
+ std::free((void *)devices);
+ return rs;
+ }
+
std::free((void *)devices);
devices = 0;
@@ -437,17 +447,51 @@ Image2D::Image2D(Context *ctx, size_t width, size_t height, size_t row_pitch,
const cl_image_format *format, void *host_ptr,
cl_mem_flags flags, cl_int *errcode_ret)
: MemObject(ctx, flags, host_ptr, errcode_ret),
- p_width(width), p_height(height), p_row_pitch(row_pitch), p_format(*format)
+ p_width(width), p_height(height), p_row_pitch(row_pitch)
{
- // NOTE for images : pitches must be NULL if host_ptr is NULL
+ if (!width || !height)
+ {
+ *errcode_ret = CL_INVALID_IMAGE_SIZE;
+ return;
+ }
+
+ if (!format)
+ {
+ *errcode_ret = CL_INVALID_IMAGE_FORMAT_DESCRIPTOR;
+ return;
+ }
+
+ p_format = *format;
+
+ // Row pitch
+ p_row_pitch = width * pixel_size(p_format);
+
+ if (row_pitch)
+ {
+ if (!host_ptr)
+ {
+ // row_pitch must be 0 if host_ptr is null
+ *errcode_ret = CL_INVALID_IMAGE_SIZE;
+ return;
+ }
+ if (row_pitch < p_row_pitch)
+ {
+ *errcode_ret = CL_INVALID_IMAGE_SIZE;
+ return;
+ }
+ if (row_pitch % pixel_size(p_format) != 0)
+ {
+ *errcode_ret = CL_INVALID_IMAGE_SIZE;
+ return;
+ }
+
+ p_row_pitch = row_pitch;
+ }
}
size_t Image2D::size() const
{
- if (row_pitch())
- return height() * row_pitch();
- else
- return height() * width() * pixel_size(format());
+ return height() * row_pitch();
}
MemObject::Type Image2D::type() const
@@ -470,7 +514,7 @@ size_t Image2D::row_pitch() const
return p_row_pitch;
}
-cl_image_format Image2D::format() const
+const cl_image_format &Image2D::format() const
{
return p_format;
}
diff --git a/src/core/memobject.h b/src/core/memobject.h
index 44787f9..7a91879 100644
--- a/src/core/memobject.h
+++ b/src/core/memobject.h
@@ -107,7 +107,7 @@ class Image2D : public MemObject
size_t width() const;
size_t height() const;
size_t row_pitch() const;
- cl_image_format format() const;
+ const cl_image_format &format() const;
cl_int imageInfo(cl_image_info param_name,
size_t param_value_size,