<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.gmail-transaction-comment
        {mso-style-name:gmail-transaction-comment;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Hi,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">You’re right, CheckDeviceAndCtors should be called from __tgt_target_data_end_mapper as well, just like any other __tgt_* function. The reason it’s currently missing is that it was assumed (as you said) that an orphan “target exit data”
 directive would make no sense, in other words the device would have been initialized by some other __tgt_* function already. However, since the example you provided seems to be a valid OpenMP program, then we should add code to initialize the device even in
 __tgt_target_data_end_mapper.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">George<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> Joel E. Denny <jdenny.ornl@gmail.com> <br>
<b>Sent:</b> Wednesday, 3 March, 2021 23:57<br>
<b>To:</b> openmp-dev@lists.llvm.org<br>
<b>Cc:</b> Rokos, Georgios <georgios.rokos@intel.com>; Narayanaswamy, Ravi <ravi.narayanaswamy@intel.com>; Johannes Doerfert <johannesdoerfert@gmail.com><br>
<b>Subject:</b> lone "omp target exit data" produces runtime error<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">Hi,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">The following program produces an OpenMP runtime error.  LIBOMPTARGET_DEBUG=1 reveals that the problem is that the device is uninitialized.  Is this behavior specified by OpenMP?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">```<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">int main() {<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  int x;<o:p></o:p></p>
</div>
<p class="MsoNormal">  #pragma omp target exit data map(from:x)<br>
  return 0;<o:p></o:p></p>
<div>
<p class="MsoNormal">}<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">```<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I'm not sure how it's useful to have an "omp target exit data" before any other offloading code.  I've only run into this when writing toy test programs, and my solution has been to add an empty target region before it.  Also, in the call
 today I mentioned I'd like to encapsulate more code into <span class="gmail-transaction-comment">
CheckDeviceAndCtors.  It looks like __tgt_target_data_end_mapper could benefit from that encapsulation except it doesn't currently call CheckDeviceAndCtors.  If it did call it, the above program would succeed.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span class="gmail-transaction-comment">Thanks.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span class="gmail-transaction-comment">Joel</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</body>
</html>