<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<div class="">Thanks Jonas! </div>
<div class=""><br class="">
</div>
<div class="">That helped a lot and the memory consumption shown by Nvidia-smi is now much closer to what I expected! </div>
<div class=""><br class="">
</div>
<div class="">The blog post is great! Maybe it should be a part of the official clang OpenMP documentation? </div>
<br class="">
<div class="">
<div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;">
Sincerely,</div>
<div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;">
Qiongsi</div>
<div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<br class="">
</div>
<br class="Apple-interchange-newline">
</div>
<div><br class="">
<blockquote type="cite" class="">
<div class="">On Jan 30, 2019, at 2:18 AM, Jonas Hahnfeld <<a href="mailto:hahnjo@hahnjo.de" class="">hahnjo@hahnjo.de</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">Hi,</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">On
 2019-01-29 17:51, Qiongsi Wu via Openmp-dev wrote:</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
Hi everyone!<br class="">
I am following Jonas Hahnfeld’s blog post<br class="">
(<a href="https://www.hahnjo.de/blog/2018/10/08/clang-7.0-openmp-offloading-nvidia.html" class="">https://www.hahnjo.de/blog/2018/10/08/clang-7.0-openmp-offloading-nvidia.html</a>)<br class="">
to build clang to test some simple target offloading workloads.<br class="">
The complete code can be found at the end.<br class="">
I tried clang 7.0.1 and llvm trunk (9.0.0). omp_get_num_devices()<br class="">
returned 0 for both compilers although the server I am running this on<br class="">
has Quadro P4000 on it. As an attempt to fix the issue, I added<br class="">
compute compatibility 61 and set it to default. This did not help.<br class="">
Additionally, the binary built by trunk cannot even offload to CPU<br class="">
targets, reporting error<br class="">
"Libomptarget fatal error 1: default offloading policy must switched<br class="">
to mandatory or disabled”<br class="">
May I get some help from the community on what to look into to get<br class="">
this microbenchmark to run on the GPU?<br class="">
Thanks!<br class="">
######################################################################################################<br class="">
#include <stdio.h><br class="">
#include <stdlib.h><br class="">
#include <time.h><br class="">
#include <omp.h><br class="">
#define VALUE_TYPE double<br class="">
#define ARR_SIZE  128 * 1024 * 1024<br class="">
struct timespec timespec_diff(struct timespec t1, struct timespec t2)<br class="">
{<br class="">
   struct timespec diff;<br class="">
   diff.tv_nsec = t1.tv_nsec - t2.tv_nsec;<br class="">
   diff.tv_sec = t1.tv_sec - t2.tv_sec;<br class="">
   if (diff.tv_nsec < 0) {<br class="">
       diff.tv_nsec += 1000000000;<br class="">
       diff.tv_sec -= 1;<br class="">
   }<br class="">
   return diff;<br class="">
}<br class="">
double timespec_to_sec(struct timespec t) {<br class="">
   double sec = (double)t.tv_sec;<br class="">
   double nsec = (double)t.tv_nsec;<br class="">
   return sec + nsec * 1E-9;<br class="">
}<br class="">
void gen_rand_number(VALUE_TYPE *arr, int size) {<br class="">
   for (int i = 0; i < size; i++) {<br class="">
       arr[i] = (VALUE_TYPE)rand();<br class="">
   }<br class="">
}<br class="">
void cpu_add(VALUE_TYPE *out, VALUE_TYPE *in_1, VALUE_TYPE *in_2, int<br class="">
size) {<br class="">
   for (int i = 0; i < size; i++) {<br class="">
       out[i] = in_1[i] + in_2[i];<br class="">
   }<br class="">
}<br class="">
void omp_cpu_add(VALUE_TYPE *out, VALUE_TYPE *in_1, VALUE_TYPE *in_2,<br class="">
int size) {<br class="">
#pragma omp parallel for<br class="">
   for (int i = 0; i < size; i++) {<br class="">
       out[i] = in_1[i] + in_2[i];<br class="">
   }<br class="">
}<br class="">
void omp_gpu_add(VALUE_TYPE *out, VALUE_TYPE *in_1, VALUE_TYPE *in_2,<br class="">
int size) {<br class="">
#pragma omp target map(to:in_1, in_2) map(from:out)<br class="">
</blockquote>
<br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">I
 think the compiler will have trouble to correctly map / transfer the arrays here. Can you try specifying array sections?</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">Should
 be as easy as "map(to:in_1[0:size], in_2[0:size]) map(from:out[0:size])"</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">Hope
 this helps and fixes the problem :)</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">Jonas</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
#pragma omp teams<br class="">
#pragma omp distribute parallel for<br class="">
   for (int i = 0; i < size; i++) {<br class="">
       out[i] = in_1[i] + in_2[i];<br class="">
   }<br class="">
}<br class="">
int main() {<br class="">
   VALUE_TYPE *a = malloc(sizeof(VALUE_TYPE) * ARR_SIZE);<br class="">
   VALUE_TYPE *b = malloc(sizeof(VALUE_TYPE) * ARR_SIZE);<br class="">
   VALUE_TYPE *c_1 = malloc(sizeof(VALUE_TYPE) * ARR_SIZE);<br class="">
   VALUE_TYPE *c_2 = malloc(sizeof(VALUE_TYPE) * ARR_SIZE);<br class="">
   VALUE_TYPE *c_3 = malloc(sizeof(VALUE_TYPE) * ARR_SIZE);<br class="">
   struct timespec start, end, diff;<br class="">
   gen_rand_number(a, ARR_SIZE);<br class="">
   gen_rand_number(b, ARR_SIZE);<br class="">
   printf("number of omp devices %d\n", omp_get_num_devices());<br class="">
   printf("number of omp teams %d\n", omp_get_num_teams());<br class="">
   clock_gettime(CLOCK_MONOTONIC, &start);<br class="">
   cpu_add(c_1, a, b, ARR_SIZE);<br class="">
   clock_gettime(CLOCK_MONOTONIC, &end);<br class="">
   printf("CPU took %f seconds. \n",<br class="">
timespec_to_sec(timespec_diff(end, start)));<br class="">
   clock_gettime(CLOCK_MONOTONIC, &start);<br class="">
   omp_cpu_add(c_2, a, b, ARR_SIZE);<br class="">
   clock_gettime(CLOCK_MONOTONIC, &end);<br class="">
   printf("CPU omp took %f seconds. \n",<br class="">
timespec_to_sec(timespec_diff(end, start)));<br class="">
   clock_gettime(CLOCK_MONOTONIC, &start);<br class="">
   for (int i = 0; i < 100; i++) {<br class="">
       omp_gpu_add(c_3, a, b, ARR_SIZE);<br class="">
   }<br class="">
   clock_gettime(CLOCK_MONOTONIC, &end);<br class="">
   printf("GPU omp offload took %f seconds. \n",<br class="">
timespec_to_sec(timespec_diff(end, start)) / 100.0);<br class="">
}<br class="">
######################################################################################################<br class="">
Sincerely,<br class="">
Qiongsi<br class="">
_______________________________________________<br class="">
Openmp-dev mailing list<br class="">
<a href="mailto:Openmp-dev@lists.llvm.org" class="">Openmp-dev@lists.llvm.org</a><br class="">
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/openmp-dev" class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/openmp-dev</a></blockquote>
</div>
</blockquote>
</div>
<br class="">
</body>
</html>