OSDN Git Service

CUDA
[eos/hostdependX86LINUX64.git] / util / X86LINUX64 / cuda-6.5 / include / fatBinaryCtl.h
1
2 /*
3  *  Copyright 2010 NVIDIA Corporation.  All rights reserved.
4  *
5  *  NOTICE TO USER: The source code, and related code and software
6  *  ("Code"), is copyrighted under U.S. and international laws.
7  *
8  *  NVIDIA Corporation owns the copyright and any patents issued or
9  *  pending for the Code.
10  *
11  *  NVIDIA CORPORATION MAKES NO REPRESENTATION ABOUT THE SUITABILITY
12  *  OF THIS CODE FOR ANY PURPOSE.  IT IS PROVIDED "AS-IS" WITHOUT EXPRESS
13  *  OR IMPLIED WARRANTY OF ANY KIND.  NVIDIA CORPORATION DISCLAIMS ALL
14  *  WARRANTIES WITH REGARD TO THE CODE, INCLUDING NON-INFRINGEMENT, AND
15  *  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  *  PURPOSE.  IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
17  *  DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
18  *  WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATED TO THE USE OR
19  *  PERFORMANCE OF THE CODE, INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT,
20  *  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
21  *  NEGLIGENCE OR OTHER TORTIOUS ACTION, AND WHETHER OR NOT THE
22  *  POSSIBILITY OF SUCH DAMAGES WERE KNOWN OR MADE KNOWN TO NVIDIA
23  *  CORPORATION.
24  *
25  */
26
27 #ifndef fatbinaryctl_INCLUDED
28 #define fatbinaryctl_INCLUDED
29
30 #ifndef __CUDA_INTERNAL_COMPILATION__
31 #include <stddef.h> /* for size_t */
32 #endif
33 #include "fatbinary.h"
34
35 /* 
36  * These are routines for controlling the fat binary.
37  * A void* object is used, with ioctl-style calls to set and get info from it.
38  */
39
40 typedef enum {
41   FBCTL_ERROR_NONE = 0,
42   FBCTL_ERROR_NULL,           /* null pointer */
43   FBCTL_ERROR_UNRECOGNIZED,   /* unrecognized kind */
44   FBCTL_ERROR_NO_CANDIDATE,   /* no candidate found */
45   FBCTL_ERROR_COMPILE_FAILED, /* no candidate found */
46   FBCTL_ERROR_INTERNAL        /* unexpected internal error */
47 } fatBinaryCtlError_t;
48 extern char* fatBinaryCtl_Errmsg (fatBinaryCtlError_t e);
49
50 extern fatBinaryCtlError_t fatBinaryCtl_Create (void* *data);
51
52 extern void fatBinaryCtl_Delete (void* data);
53
54 /* use this control-call to set and get values */
55 extern fatBinaryCtlError_t fatBinaryCtl (void* data, int request, ...);
56
57 /* defined requests */
58 #define FBCTL_SET_BINARY        1  /* void* (e.g. fatbin, elf or ptx object) */
59 #define FBCTL_SET_TARGETSM      2  /* int (use values from nvelf.h) */
60 #define FBCTL_SET_FLAGS         3  /* longlong */
61 #define FBCTL_SET_CMDOPTIONS    4  /* char* */
62 #define FBCTL_SET_POLICY        5  /* fatBinary_CompilationPolicy */
63 /* get calls return value in arg, thus are all by reference */
64 #define FBCTL_GET_CANDIDATE     10 /* void** binary, 
65                                     * fatBinaryCodeKind* kind, 
66                                     * size_t* size */
67 #define FBCTL_GET_IDENTIFIER    11 /* char* * */
68 #define FBCTL_HAS_DEBUG         12 /* Bool * */
69
70 typedef enum {
71   fatBinary_PreferBestCode,  /* default */
72   fatBinary_AvoidPTX,        /* use sass if possible for compile-time savings */
73   fatBinary_ForcePTX,        /* use ptx (mainly for testing) */
74   fatBinary_JITIfNotMatch    /* use ptx if arch doesn't match */
75 } fatBinary_CompilationPolicy;
76
77 /* 
78  * Using the input values, pick the best candidate;
79  * use subsequent Ctl requests to get info about that candidate.
80  */
81 extern fatBinaryCtlError_t fatBinaryCtl_PickCandidate (void* data);
82
83 /* 
84  * Using the previously chosen candidate, compile the code to elf,
85  * returning elf image and size.
86  * Note that because elf is allocated inside fatBinaryCtl, 
87  * it will be freed when _Delete routine is called.
88  */
89 extern fatBinaryCtlError_t fatBinaryCtl_Compile (void* data, 
90                                                  void* *elf, size_t *esize);
91
92 /*
93  * These defines are for the fatbin.c runtime wrapper
94  */
95 #define FATBINC_MAGIC   0x466243B1
96 #define FATBINC_VERSION 1
97 #define FATBINC_LINK_VERSION 2
98
99 typedef struct {
100   int magic;
101   int version;
102   const unsigned long long* data;
103   void *filename_or_fatbins;  /* version 1: offline filename,
104                                * version 2: array of prelinked fatbins */
105 } __fatBinC_Wrapper_t;
106
107 /*
108  * The section that contains the fatbin control structure
109  */
110 #ifdef STD_OS_Darwin
111 /* mach-o sections limited to 15 chars, and want __ prefix else strip complains, * so use a different name */
112 #define FATBIN_CONTROL_SECTION_NAME     "__fatbin"
113 #define FATBIN_DATA_SECTION_NAME        "__nv_fatbin"
114 /* only need segment name for mach-o */
115 #define FATBIN_SEGMENT_NAME             "__NV_CUDA"
116 #else
117 #define FATBIN_CONTROL_SECTION_NAME     ".nvFatBinSegment"
118 /*
119  * The section that contains the fatbin data itself
120  * (put in separate section so easy to find)
121  */
122 #define FATBIN_DATA_SECTION_NAME        ".nv_fatbin"
123 #endif
124 /* section for pre-linked relocatable fatbin data */
125 #define FATBIN_PRELINK_DATA_SECTION_NAME "__nv_relfatbin"
126
127 #endif /* fatbinaryctl_INCLUDED */