Skip to content

Commit

Permalink
Misc. cleanups and documentation
Browse files Browse the repository at this point in the history
Except for the atomic decrement of cl_context_count instead of non-
atomic.
  • Loading branch information
pjaaskel committed Oct 18, 2019
1 parent 6ddb674 commit 790df88
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 30 deletions.
33 changes: 28 additions & 5 deletions lib/CL/clGetEventInfo.c
@@ -1,11 +1,34 @@
/* OpenCL runtime library: clGetEventInfo()
Copyright (c) 2011-2019 pocl developers
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#include "pocl_util.h"

CL_API_ENTRY cl_int CL_API_CALL
POname(clGetEventInfo)(cl_event event ,
cl_event_info param_name ,
size_t param_value_size ,
void * param_value ,
size_t * param_value_size_ret )
POname(clGetEventInfo)(cl_event event,
cl_event_info param_name,
size_t param_value_size,
void * param_value,
size_t * param_value_size_ret)
CL_API_SUFFIX__VERSION_1_0
{
POCL_RETURN_ERROR_COND((event == NULL), CL_INVALID_EVENT);
Expand Down
9 changes: 6 additions & 3 deletions lib/CL/clReleaseContext.c
@@ -1,17 +1,18 @@
/* OpenCL runtime library: clReleaseContext()
Copyright (c) 2011 Universidad Rey Juan Carlos
2011-2019 pocl developers
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -22,6 +23,7 @@
*/

#include "pocl_cl.h"
#include "pocl_util.h"
#include "devices/devices.h"

#include <unistd.h>
Expand Down Expand Up @@ -65,6 +67,7 @@ POname(clReleaseContext)(cl_context context) CL_API_SUFFIX__VERSION_1_0

/* see below on why we don't call uninit_devices here anymore */
--cl_context_count;
POCL_ATOMIC_DEC (cl_context_count);
}

POCL_UNLOCK (pocl_context_handling_lock);
Expand Down
2 changes: 1 addition & 1 deletion lib/CL/devices/hsa/pocl-hsa.c
Expand Up @@ -1581,7 +1581,7 @@ pocl_hsa_submit (_cl_command_node *node, cl_command_queue cq)
pocl_hsa_device_data_t *d = device->data;
unsigned added_to_readylist = 0;

PTHREAD_CHECK(pthread_mutex_lock(&d->list_mutex));
PTHREAD_CHECK (pthread_mutex_lock(&d->list_mutex));

node->ready = 1;
if (pocl_command_is_ready (node->event))
Expand Down
8 changes: 4 additions & 4 deletions lib/CL/pocl_mem_management.c
@@ -1,17 +1,17 @@
/* pocl_cl.h - local runtime library declarations.
/* pocl_mem_management.c - manage allocation of runtime objects
Copyright (c) 2014 Ville Korhonen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down
8 changes: 4 additions & 4 deletions lib/CL/pocl_mem_management.h
@@ -1,17 +1,17 @@
/* pocl_cl.h - local runtime library declarations.
/* pocl_mem_management.c - manage allocation of runtime objects
Copyright (c) 2014 Ville Korhonen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down
6 changes: 3 additions & 3 deletions lib/CL/pocl_runtime_config.h
@@ -1,17 +1,17 @@
/* pocl_runtime_config.h: functions to query pocl runtime configuration settings
Copyright (c) 2013 Pekka Jääskeläinen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down
10 changes: 3 additions & 7 deletions lib/CL/pocl_util.c
Expand Up @@ -395,7 +395,7 @@ cl_int pocl_create_event (cl_event *event, cl_command_queue command_queue,
POname(clRetainCommandQueue) (command_queue);

(*event)->command_type = command_type;
(*event)->id = ATOMIC_INC (event_id_counter);
(*event)->id = POCL_ATOMIC_INC (event_id_counter);
(*event)->num_buffers = num_buffers;

POCL_MSG_PRINT_EVENTS ("created event with id %d\n", (*event)->id);
Expand All @@ -406,12 +406,8 @@ cl_int pocl_create_event (cl_event *event, cl_command_queue command_queue,
memcpy ((*event)->mem_objs, buffers, num_buffers * sizeof(cl_mem));
}
(*event)->status = CL_QUEUED;

/* user events do not have cq */
if (!command_queue)
return CL_SUCCESS;

}

return CL_SUCCESS;
}

Expand Down Expand Up @@ -484,7 +480,7 @@ cl_int pocl_create_command (_cl_command_node **cmd,

(*cmd)->type = command_type;

/* Even if user does not provide event pointer, create event anyway */
/* If user does not provide an event pointer, create an implicit one. */
event = &((*cmd)->event);
err = pocl_create_event (event, command_queue, 0, num_buffers, buffers,
command_queue->context);
Expand Down
9 changes: 7 additions & 2 deletions lib/CL/pocl_util.h
Expand Up @@ -46,9 +46,14 @@ extern "C" {
#endif

#if defined(__GNUC__) || defined(__clang__)
#define ATOMIC_INC(x) __sync_add_and_fetch(&x, 1)

/* These return the new value. */
/* See: https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Builtins.html */
#define POCL_ATOMIC_INC(x) __sync_add_and_fetch (&x, 1)
#define POCL_ATOMIC_DEC(x) __sync_sub_and_fetch (&x, 1)

#else
#error Need atomic_inc() builtin for this compiler
#error Need basic atomics builtin support in the compiler.
#endif

uint32_t byteswap_uint32_t (uint32_t word, char should_swap);
Expand Down
2 changes: 1 addition & 1 deletion lib/llvmopencl/WorkitemHandler.cc
Expand Up @@ -54,7 +54,7 @@ using namespace llvm;
/* These are used to communicate the work-group function specialization
properites of the currently compiled kernel command.
TODO: Something cleaner than a global value. */
TODO: Something cleaner than global values. */

bool WGDynamicLocalSize = false;
size_t WGLocalSizeX = 1;
Expand Down

0 comments on commit 790df88

Please sign in to comment.