126236Swpaul/*
226236Swpaul    Copyright (c) 2014 Intel Corporation.  All Rights Reserved.
326236Swpaul
426236Swpaul    Redistribution and use in source and binary forms, with or without
526236Swpaul    modification, are permitted provided that the following conditions
626236Swpaul    are met:
726236Swpaul
826236Swpaul      * Redistributions of source code must retain the above copyright
926236Swpaul        notice, this list of conditions and the following disclaimer.
1026236Swpaul      * Redistributions in binary form must reproduce the above copyright
1126236Swpaul        notice, this list of conditions and the following disclaimer in the
1226236Swpaul        documentation and/or other materials provided with the distribution.
1326236Swpaul      * Neither the name of Intel Corporation nor the names of its
1426236Swpaul        contributors may be used to endorse or promote products derived
1526236Swpaul        from this software without specific prior written permission.
1626236Swpaul
1726236Swpaul    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1826236Swpaul    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1926236Swpaul    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2026236Swpaul    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2126236Swpaul    HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2226236Swpaul    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2326236Swpaul    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2426236Swpaul    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2526236Swpaul    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2626236Swpaul    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2726236Swpaul    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2826236Swpaul*/
2926236Swpaul
3026236Swpaul
3126236Swpaul/*! \file
3226236Swpaul    \brief The interface between compiler-generated host code and runtime library
33114601Sobrien*/
34114601Sobrien
3530378Scharnier#ifndef COMPILER_IF_HOST_H_INCLUDED
3626236Swpaul#define COMPILER_IF_HOST_H_INCLUDED
3726236Swpaul
38228679Sdim#include "offload_host.h"
3926236Swpaul
40129658Sstefanf#define OFFLOAD_TARGET_ACQUIRE          OFFLOAD_PREFIX(target_acquire)
4126236Swpaul#define OFFLOAD_TARGET_ACQUIRE1         OFFLOAD_PREFIX(target_acquire1)
4226236Swpaul#define OFFLOAD_OFFLOAD                 OFFLOAD_PREFIX(offload)
4326236Swpaul#define OFFLOAD_OFFLOAD1                OFFLOAD_PREFIX(offload1)
4426236Swpaul#define OFFLOAD_OFFLOAD2                OFFLOAD_PREFIX(offload2)
4526236Swpaul#define OFFLOAD_CALL_COUNT              OFFLOAD_PREFIX(offload_call_count)
4626236Swpaul
4726236Swpaul
4826236Swpaul/*! \fn OFFLOAD_TARGET_ACQUIRE
4926236Swpaul    \brief Attempt to acquire the target.
5026236Swpaul    \param target_type   The type of target.
5190298Sdes    \param target_number The device number.
5290298Sdes    \param is_optional   Whether CPU fall-back is allowed.
5326236Swpaul    \param status        Address of variable to hold offload status.
5426236Swpaul    \param file          Filename in which this offload occurred.
5526236Swpaul    \param line          Line number in the file where this offload occurred.
5690297Sdes*/
5726236Swpaulextern "C" OFFLOAD OFFLOAD_TARGET_ACQUIRE(
5879452Sbrian    TARGET_TYPE      target_type,
5926236Swpaul    int              target_number,
6026236Swpaul    int              is_optional,
6126236Swpaul    _Offload_status* status,
6226236Swpaul    const char*      file,
6326236Swpaul    uint64_t         line
6426236Swpaul);
6526236Swpaul
6626236Swpaul/*! \fn OFFLOAD_TARGET_ACQUIRE1
6726236Swpaul    \brief Acquire the target for offload (OpenMP).
6826236Swpaul    \param device_number Device number or null if not specified.
6926236Swpaul    \param file          Filename in which this offload occurred
7026236Swpaul    \param line          Line number in the file where this offload occurred.
7126236Swpaul*/
7226236Swpaulextern "C" OFFLOAD OFFLOAD_TARGET_ACQUIRE1(
7326236Swpaul    const int*      device_number,
7426236Swpaul    const char*     file,
7590298Sdes    uint64_t        line
7690298Sdes);
7790298Sdes
7826236Swpaul/*! \fn OFFLOAD_OFFLOAD1
7926236Swpaul    \brief Run function on target using interface for old data persistence.
8026236Swpaul    \param o Offload descriptor created by OFFLOAD_TARGET_ACQUIRE.
8126236Swpaul    \param name Name of offload entry point.
8226236Swpaul    \param is_empty If no code to execute (e.g. offload_transfer)
8326236Swpaul    \param num_vars Number of variable descriptors.
8426236Swpaul    \param vars Pointer to VarDesc array.
8526236Swpaul    \param vars2 Pointer to VarDesc2 array.
8626236Swpaul    \param num_waits Number of "wait" values.
8726236Swpaul    \param waits Pointer to array of wait values.
8826236Swpaul    \param signal Pointer to signal value or NULL.
8926236Swpaul*/
9026236Swpaulextern "C" int OFFLOAD_OFFLOAD1(
9126236Swpaul    OFFLOAD o,
9226236Swpaul    const char *name,
9326236Swpaul    int is_empty,
9426236Swpaul    int num_vars,
9526236Swpaul    VarDesc *vars,
9626236Swpaul    VarDesc2 *vars2,
9726236Swpaul    int num_waits,
9826236Swpaul    const void** waits,
9926236Swpaul    const void** signal
10090297Sdes);
10126236Swpaul
10226236Swpaul/*! \fn OFFLOAD_OFFLOAD2
10326236Swpaul    \brief Run function on target using interface for new data persistence.
10426236Swpaul    \param o Offload descriptor created by OFFLOAD_TARGET_ACQUIRE.
10526236Swpaul    \param name Name of offload entry point.
10626236Swpaul    \param is_empty If no code to execute (e.g. offload_transfer)
10726236Swpaul    \param num_vars Number of variable descriptors.
10826236Swpaul    \param vars Pointer to VarDesc array.
10926236Swpaul    \param vars2 Pointer to VarDesc2 array.
11026236Swpaul    \param num_waits Number of "wait" values.
11126236Swpaul    \param waits Pointer to array of wait values.
11226236Swpaul    \param signal Pointer to signal value or NULL.
11326236Swpaul    \param entry_id A signature for the function doing the offload.
11426236Swpaul    \param stack_addr The stack frame address of the function doing offload.
11526236Swpaul*/
11626236Swpaulextern "C" int OFFLOAD_OFFLOAD2(
11726236Swpaul    OFFLOAD o,
11826236Swpaul    const char *name,
11926236Swpaul    int is_empty,
12026236Swpaul    int num_vars,
12126236Swpaul    VarDesc *vars,
12226236Swpaul    VarDesc2 *vars2,
12326236Swpaul    int num_waits,
12426236Swpaul    const void** waits,
12526236Swpaul    const void** signal,
12626236Swpaul    int entry_id,
12726236Swpaul    const void *stack_addr
12826236Swpaul);
12926236Swpaul
13026236Swpaul// Run function on target (obsolete).
13126236Swpaul// @param o    OFFLOAD object
13226236Swpaul// @param name function name
13326236Swpaulextern "C" int OFFLOAD_OFFLOAD(
134228680Sdim    OFFLOAD o,
13526236Swpaul    const char *name,
13626236Swpaul    int is_empty,
13726236Swpaul    int num_vars,
13826236Swpaul    VarDesc *vars,
13926236Swpaul    VarDesc2 *vars2,
14026236Swpaul    int num_waits,
14126236Swpaul    const void** waits,
14226236Swpaul    const void* signal,
14326236Swpaul    int entry_id = 0,
14426236Swpaul    const void *stack_addr = NULL
14526236Swpaul);
14626236Swpaul
14726236Swpaul// Global counter on host.
148// This variable is used if P2OPT_offload_do_data_persistence == 2.
149// The variable used to identify offload constructs contained in one procedure.
150// Call to OFFLOAD_CALL_COUNT() is inserted at HOST on entry of the routine.
151extern "C" int  OFFLOAD_CALL_COUNT();
152
153#endif // COMPILER_IF_HOST_H_INCLUDED
154