搜档网
当前位置:搜档网 › AMD_OpenCL_大学教程中文版

AMD_OpenCL_大学教程中文版

AMD_OpenCL_大学教程中文版
AMD_OpenCL_大学教程中文版

AMD OpenCL大学教程中文版*

迈克老狼@https://www.sodocs.net/doc/b516744942.html,?

January10,2012

目录

1并行计算概述3

1.1并行计算概述 (3)

1.2常用基于硬件和软件的并行 (5)

2OpenCL概述7

2.1OpenCL架构 (7)

2.2OpenCL平台模型 (7)

2.3OpenCL编程的一般步骤 (8)

2.3.1命令队列 (10)

2.3.2OpenCL内存对象 (11)

2.3.3OpenCL程序对象 (12)

2.3.4Kernel对象 (15)

2.3.5Kernel执行 (19)

3GPU架构23

3.1OpenCLspec和多核硬件的对应关系 (23)

3.2一些关于OpenCL的特殊主题 (23)

3.3传统的CPU架构 (24)

3.4现代的GPGPU架构 (25)

3.5AMD GPU硬件架构 (25)

3.6Nvdia GPU Femi架构 (29)

3.6.1GTX480-Compute2.0capability (29)

3.6.2SIMT和SIMD (30)

3.6.3Nvida GPU内存机制 (30)

3.7Cell Broadband Engine (31)

3.8OpenCL编译系统 (32)

3.9Installable Client Driver (32)

4OpenCL buffer使用及两个简单例子33

4.1创建OpenCL设备缓冲(buffer) (33)

4.2图像旋转的例子 (34)

4.3一个矩阵乘法的例子 (37)

5GPU memory结构37

5.1GPU总线寻址介绍 (37)

5.2合并内存访问 (38)

5.3Global memory的bank以及channel访问冲突 (39)

5.4Local memory的bank conflit (39)

*英文原版地址:点击这里。

?欢迎光临OpenGPU专业论坛:https://www.sodocs.net/doc/b516744942.html,

目录6GPU线程及调度41

6.1Workgroup到硬件线程 (41)

6.2AMD wave调度 (42)

6.3NV warp调度 (43)

6.4Occupancy开销 (43)

6.5控制流和分支预测(prediction) (43)

6.6Warp voting (44)

7性能优化45

7.1线程映射 (45)

7.2Occupancy (47)

7.3向量化 (48)

8性能优化案例NBody49

8.1NBody (49)

8.2NBody算法 (49)

8.3OpenCL优化Nbody (50)

1并行计算概述

1.1并行计算概述

在计算机术语中,并行性描述了把一个复杂问题分解成多个能同时处理的子问题的能力。要实现并行计算,首先我们要有物理上能够实现并行计算的硬件设备,比如多核CPU,每个核能同时实现算术或逻辑运算。

在GPU并行计算中,通常我们实现两类并行计算:

?任务并行:把一个问题分解为能够同时执行的多个任务。

?数据并行:同一个任务内,它的各个部分同时执行。

下面我们通过一个农场主雇佣工人摘苹果的例子来描述不同种类的并行计算。

?摘苹果的工人就是硬件上的并行处理单元(process elements)。

?树就是要执行的任务。

?苹果就是要处理的数据。

串行的任务处理就如下图所示,一个工人背着梯子摘完所有树上的苹果(一个处理单元处理完所有任务的数据)。

数据并行就好比农场主雇佣了好多工人来摘完一个树上的苹果(多个处理单元并行完成一个任务中的数据),这样就能很快摘完一颗树上的苹果。

农场主也可以为每棵树分配一个人,这就好比任务并行。在每个任务内,由于只有一个工人,所以是执行串行的,但任务之间是并行的。

对一个复杂问题,影响并行计算的因素很多。通常,我们都是通过分解问题的方式来实施并算法行。这又包括两方面内容:

?任务分解:通常是把算法分解成很多的小任务,就像前面的例子中,把果园按苹果树进行划分,这时我们并不关注数据,也就是说不关注每个树上到底有多少个苹果。

?数据分解:就是把很多数据,分成不同的、离散的小块,这些数据块能够被并行执行,就好比前面例子中的苹果。

通常我们按照算法之间的依赖关系来分解任务,这样就形成了一个任务关系图。一个任务只有没有依赖任务的时候,才能够被执行。

这有点类似于我们数据结构中的有向无环图,两个没有连通路径的任务之间可以并行执行。下面再给一个烤面包的例子,如果所示,预热烤箱和购买面粉糖两个任务之间可以并行执行。

对大多数科学计算和工程应用来说,数据分解一般都是基于输出数据,例如:

?在一副图像中,对一个滑动窗口(例如:3*3像素)内的像素实施滤波操作,可以得到一个输出像素的卷积。

?第一个输入矩阵的第i行乘以第二个输入矩阵的第j列,得到的向量和即为输出矩阵第i行,第j列的元素。

这种方法对于输入和输出数据是一对一,或者多对一的对应关系比较有效。

也有的数据分解算法是基于输入数据的,这时,输入数据和输出数据一般是一对多的关系,比如求图像的直方图,我们要把每个像素放到对应的槽中(bins,对于灰度图,bin数量通常是256)。一个搜索函数,输入可能是多个数据,输出却只有一个值。对于这类应用,我们一般用每个线程计算输出的一部分,然后通过同步以及原子操作得到最终的值,OpenCL 中求最小值的kernel函数就是典型代表1。

通常来说,怎样分解问题和具体算法有关,而且还要考虑自己使用的硬件和软件,比如AMD GPU平台和Nvdia GPU 平台的优化就有很多不同。

1.2常用基于硬件和软件的并行

在上个实际90年代,并行计算主要研究如何在cpu上实施指自动的指令级并行。

?同时发射多条指令(之间没有依赖关系),并行执行这些指令。

?在本教程中,我么不讲述自动的硬件级并行,感兴趣的话,可以看看计算机体系结构的教程。

高层的并行,比如线程级别的并行,一般很难自动化,需要程序员告诉计算机,该做什么,不该做什么。这时,程序员还要考虑硬件的具体指标,通常特定硬件都是适应于某一类并行编程,比如多核cpu就适合基于任务的并行编程,而GPU 更适应于数据并行编程。

Hardware type Examples Parallelism

Multi-core superscalar processors Phenom II CPU Task

Vector or SIMD processors SSE units(x86CPUs)Data

Multi-core SIMD processors Radeon5870GPU Data

现代的GPU有很多独立的运算核(processor)组成,在AMD GPU上就是stream core,这些core能够执行SIMD 操作(单指令,多数据),所以特别适合数据并行操作。通常GPU上执行一个任务,都是把任务中的数据分配到各个独立的core中执行。

在GPU上,我们一般通过循环展开,Loop strip mining技术,来把串行代码改成并行执行的。比如在CPU上,如果我们实现一个向量加法,代码通常如下:

for(i=0;i

{

C[i]=A[i]+B;

}

在GPU上,我们可以设置n个线程,每个线程执行一个加法,这样大大提高了向量加法的并行性。

1可以看下ATI Stream Computing OpenCL programming guide第二章中求最小值的kernel例子

__kernel void VectorAdd(__global const float*a,__global const float*b,__global float*c,int n)

{

int i=get_global_id(0);

c=a+b;

}

上面这个图展示了向量加法的SPMD(单指令多线程)实现,从图中可以看出如何实施Loop strip mining操作的。

GPU的程序一般称作Kernel程序,它是一种SPMD的编程模型(the Single Program Multiple Data)。SPMD执行同一段代码的多个实例,每个实例对数据的不同部分进行操作。

在数据并行应用中,用loop strip mining来实现SPMD是最常用的方法:

?在分布式系统中,我们用Message Passing Interface(MPI)来实现SPMD。

?在共享内存并行系统中,我们用POSIX线程来实现SPMD。

?在GPU中,我们就是用Kernel来显现SPMD。

在现代CPU上,创建回一个线程的开销还是很大的,如果要在CPU上实现SPMD,每个线程处理的数据块就要尽量大点,做更多的事情,以便减少平均线程开销。但在GPU上,都是轻量级的线程,创建、调度线程的开销比较小,所以我们可以做到把循环完全展开,一个线程处理一个数据。

GPU上并行编程的硬件一般称作SIMD。通常,发射一条指令后,它要在多个ALU单元中执行(ALU的数量即使simd的宽度),这种设计减少了控制流单元以级ALU相关的其他硬件数量。SIMD的硬件如下图所示:

在向量加法中,宽度为4的SIMD单元,可以把整个循环分为四个部分同时执行。在工人摘苹果的例子中,工人的双手类似于SIMD的宽度为2。另外,我们要知道,现在的GPU硬件上都是基于SIMD设计,GPU硬件隐式的把SPMD 线程映射到SIMD core上。对开发有人员来说,我们并不需要硬件是否正确,我们只需要关注它的性能。

CPU一般都支持并行级的原子操作,这些操作保证不同的线程读写数据,相互之间不会干扰。有些GPU支持系统范围的并行操作,但会有很大开销,比如Global memory的同步。

2OpenCL概述

2.1OpenCL架构

OpenCL可以实现混合设备的并行计算,这些设备包括CPU,GPU,以及其它处理器,比如Cell处理器,DSP等。使用OpenCL编程,可以实现可移植的并行加速代码。2。

通常OpenCL架构包括四个部分:

?平台模型(Platform Model)

?执行模型(Execution Model)

?内存模型(Memory Model)

?编程模型(Programming Model)

2.2OpenCL平台模型

不同厂商的OpenCL实施定义了不同的OpenCL平台,通过OpenCL平台,主机能够和OpenCL设备之间进行交互操作。现在主要的OpenCL平台有AMD、Nvdia,intel等。OpenCL使用了一种Installable Client Driver模型,这样不同厂商的平台就能够在系统中共存。在我的计算机上就安装有AMD和Intel两个OpenCL Platform3。

2但由于各个OpenCL device不同的硬件性能,可能对于程序的优化还要考虑具体的硬件特性

3现在的OpenCL driver模型不允许不同厂商的GPU同时运行

OpenCL平台通常包括一个主机(Host)和多个OpenCL设备(device),每个OpenCL设备包括一个或多个CU(compute units),每个CU包括又一个或多个PE(process element)。每个PE都有自己的程序计数器(PC)。主机就是OpenCL运行库宿主设备,在AMD和Nvida的OpenCL平台中,主机一般都指x86CPU。对AMD平台来说,所有的CPU是一个设备,CPU的每一个core就是一个CU,而每个GPU都是独立的设备。

2.3OpenCL编程的一般步骤

下面我们通过一个实例来了解OpenCL编程的步骤,假设我们用的是AMD OpenCL平台(因为本人的GPU是HD5730),安装了AMD Stream SDK2.4,并在VS2008中设置好了include,lib目录等。

首先我们建立一个控制台程序,最初的代码如下:

#include"stdafx.h"

#include

#include

#include

#pragma comment(lib,"OpenCL.lib")

int main(int argc,char*argv[])

{

return0;

}

第一步,我们要选择一个OpenCL平台,所用的函数就是:

cl_int clGetPlatformIDs(cl_unit num_entries,

cl_platform_id*platforms,

cl_uint*num_platforms);

通常,这个函数要调用2次,第一次得到系统中可使用的平台数目,然后为(Platform)平台对象分配空间,第二次调用就是查询所有的平台,选择自己需要的OpenCL平台。代码比较长,具体可以看下AMD Stream SDK2.4中的TemplateC例子,里面描述如何构建一个robust的最小OpenCL程序。为了简化代码,使程序看起来不那么繁琐,我直接调用该函数,选取系统中的第一个OpenCL平台,我的系统中安装AMD和Intel两家的平台,第一个平台是AMD的。另外,我也没有增加错误检测之类的代码,但是我增加了一个status的变量,通常如果函数执行正确,返回的值是0。

#include"stdafx.h"

#include

#include

#include

#pragma comment(lib,"OpenCL.lib")

int main(int argc,char*argv[])

{

cl_uint status;

cl_platform_id platform;

status=clGetPlatformIDs(1,&platform,NULL);

return0;

}

第二步是得到OpenCL设备:

clGetDeviceIDs(cl_platform_id platform,

cl_device_type device_type,

cl_unit num_entries,

cl_device_id*devices,

cl_unit*num_devices);

这个函数通常也是调用2次,第一次查询设备数量,第二次检索得到我们想要的设备。为了简化代码,我们直接指定GPU设备。

#include"stdafx.h"

#include

#include

#include

#pragma comment(lib,"OpenCL.lib")

int main(int argc,char*argv[])

{

cl_uint status;

cl_platform_id platform;

status=clGetPlatformIDs(1,&platform,NULL);

cl_device_id device;

clGetDeviceIDs(platform,CL_DEVICE_TYPE_GPU,

1,

&device,

NULL);

return0;

}

下面我们来看下OpenCL中Context的概念。通常,Context是指管理OpenCL对象和资源的上下文环境。为了管理OpenCL程序,下面的一些对象都要和Context关联起来:

?设备(Devices):执行Kernel程序对象。

?程序对象(Program objects):kernel程序源代码

?Kernels:运行在OpenCL设备上的函数

?内存对象(Memory objects):设备上存放数据

?命令队列(Command queues):设备的交互机制

?内存命令(Memory commands)(用于在主机内存和设备内存之间拷贝数据)

?Kernel执行(Kernel execution)

?同步(Synchronization)

注意:创建一个Context的时候,我们必须把一个或多个设备和它关联起来。对于其它的OpenCL资源,它们创建时候,也要和Context关联起来,一般创建这些资源的OpenCL函数的输入参数中,都会有context。

cl_context clCreateContest(const cl_context_properties*properties,

cl_uint num_devices,

const cl_device_id*devices,

void(CL_CALLBACK*pfn_notify)(const char*errinfo,

const void*private_info,

size_t cb,

void*user_data),

void*user_data,

cl_int*errcode_ret);

这个函数中指定了和context关联的一个或多个设备对象,properties参数指定了使用的平台,如果为NULL,厂商选择的缺省值被使用,这个函数也提供了一个回调机制给用户提供错误报告。现在的代码如下:

#include"stdafx.h"

#include

#include

#include

#pragma comment(lib,"OpenCL.lib")

int main(int argc,char*argv[])

{

cl_uint status;

cl_platform_id platform;

status=clGetPlatformIDs(1,&platform,NULL);

cl_device_id device;

clGetDeviceIDs(platform,CL_DEVICE_TYPE_GPU,

1,

&device,

NULL);

cl_context context=clCreateContext(NULL,

1,

&device,

NULL,NULL,NULL);

return0;

}

2.3.1命令队列

接下来,我们要看下命令队列。在OpenCL中,命令队列就是主机的请求,在设备上执行的一种机制。

在Kernel执行前,我们一般要进行一些内存拷贝的工作,比如把主机内存中的数据传输到设备内存中。

另外要注意的几点就是:对于不同的设备,它们都有自己的独立的命令队列;命令队列中的命令(kernel函数)可能是同步的,也可能是异步的,它们的执行顺序可以是有序的,也可以是乱序的。

cl_command_queue clCreateCommandQueue(cl_context context,

cl_device_id device,

cl_command_queue_properties properties,

cl_int*errcode_ret);

命令队列在device和context之间建立了一个连接。

命令队列properties指定一下内容:

?是否乱序执行(在AMD GPU中,好像现在还不支持乱序执行)

?是否启动profiling。Profiling通过事件机制来得到kernel执行时间等有用的信息,但它本身也会有一些开销。

如下图所示,命令队列把设备和context联系起来,尽管它们之间不是物理连接:

添加命令队列后的代码如下:

#include"stdafx.h"

#include

#include

#include

#pragma comment(lib,"OpenCL.lib")

int main(int argc,char*argv[])

{

cl_uint status;

cl_platform_id platform;

status=clGetPlatformIDs(1,&platform,NULL);

cl_device_id device;

clGetDeviceIDs(platform,CL_DEVICE_TYPE_GPU,

1,

&device,

NULL);

cl_context context=clCreateContext(NULL,

1,

&device,

NULL,NULL,NULL);

cl_command_queue queue=clCreateCommandQueue(context,

device,

CL_QUEUE_PROFILING_ENABLE,NULL);

return0;

}

2.3.2OpenCL内存对象

OpenCL内存对象就是一些OpenCL数据,这些数据一般在设备内存中,能够被拷入也能够被拷出。OpenCL内存对象包括buffer对象和image对象。

?Buffer对象:连续的内存块----顺序存储,能够通过指针、行列式等直接访问。

?Image对象:是2维或3维的内存对象,只能通过read_image()或write_image()来读取。image对象可以是可读或可写的,但不能同时既可读又可写。

cl_mem clCreateBuffer(cl_context context,

cl_mem_flags flags,

size_t size,

void*host_ptr,

cl_int*errcode_ret);

该函数会在指定的context上创建一个buffer对象,image对象相对比较复杂,留在后面再讲。flags参数指定buffer 对象的读写属性,host_ptr可以是NULL,如果不为NULL,一般是一个有效的host buffer对象,这时,函数创建OpenCL buffer对象后,会把对应host buffer的内容拷贝到OpenCL buffer中。

在Kernel执行之前,host中原始输入数据必须显式的传到device中,Kernel执行完后,结果也要从device内存中传回到host内存中。我们主要通过函数clEnqueue{Read/Write}Buffer/Image}来实现这两种操作。从host到device,我们用clEnqueueWrite,从device到host,我们用clEnqueueRead。clEnqueueWrite命令包括初始化内存对象以及把host数据传到device内存这两种操作。当然,像前面一段说的那样,也可以把host buffer指针直接用在CreateBuffer函数中来实现隐式的数据写操作。

cl_int clEnqueueWriteBuffer(cl_command_queue command_queue,

cl_mem buffer,

cl_bool blocking_write,

size_t offset,

size_t cb,

const void*ptr,

cl_uint num_events_in_wait_list,

const cl_event*event_wait_list,

cl_event*event);

这个函数初始化OpenCL内存对象,并把相应的数据写到OpenCL内存关联的设备内存中。其中,blocking write参数指定是数拷贝完成后函数才返回还是数据开始拷贝后就立即返回(阻塞模式于非阻塞模式)。Events参数指定这个函数执行之前,必须要完成的Event(比如先要创建OpenCL内存对象的Event)

2.3.3OpenCL程序对象

程序对象就是通过读入Kernel函数源代码或二进制文件,然后在指定的设备上进行编译而产生的OpenCL对象。

cl_program clCreateProgramWithSource(cl_context context,

cl_uint count,

const char**strings,

const size_t*lengths,

cl_int*errcode_ret);

这个函数通过源代码(strings),创建一个程序对象,其中counts指定源代码串的数量,lengths指定源代码串的长度(为NULL结束的串时,可以省略)。当然,我们还必须自己编写一个从文件中读取源代码串的函数。

cl_int clBuildProgram(cl_program program,

cl_uint num_devices,

const cl_device_id*device_list,

const char*options,

void(CL_CALLBACK*pfn_notify)(cl_program program,

void*user_data),

void*user_data);

对context中的每个设备,这个函数编译、连接源代码对象,产生device可以执行的文件,对GPU而言就是设备对应shader汇编。如果device list参数被提供,则只对这些设备进行编译连接。options参数主要提供一些附加的编译选项,比如宏定义、优化开关标志等等。

如果程序编译失败,我们能够根据返回的状态,通过调用clGetProgramBuildInfo来得到错误信息。加上创建内存对象以及程序对象的代码如下:

#include"stdafx.h"

#include

#include

#include

#include

#include

#include

using namespace std;

#define NWITEMS262144

#pragma comment(lib,"OpenCL.lib")

//把文本文件读入一个string中

int convertToString(const char*filename,std::string&s)

{

size_t size;

char*str;

std::fstream f(filename,(std::fstream::in|std::fstream::binary));

if(f.is_open())

{

size_t fileSize;

f.seekg(0,std::fstream::end);

size=fileSize=(size_t)f.tellg();

f.seekg(0,std::fstream::beg);

str=new char[size+1];

if(!str)

{

f.close();

return NULL;

}

f.read(str,fileSize);

f.close();

str[size]='\0';

s=str;

delete[]str;

return0;

}

printf("Error:Failed to open file%s\n",filename);

return1;

}

int main(int argc,char*argv[])

{

//在host内存中创建三个缓冲区

float*buf1=0;

float*buf2=0;

float*buf=0;

buf1=(float*)malloc(NWITEMS*sizeof(float));

buf2=(float*)malloc(NWITEMS*sizeof(float));

buf=(float*)malloc(NWITEMS*sizeof(float));

//初始化buf1和buf2的内容

int i;

srand((unsigned)time(NULL));

for(i=0;i

buf1[i]=rand()%65535;

srand((unsigned)time(NULL)+1000);

for(i=0;i

buf2[i]=rand()%65535;

cl_uint status;

cl_platform_id platform;

//创建平台对象

status=clGetPlatformIDs(1,&platform,NULL);

cl_device_id device;

//创建GPU设备

clGetDeviceIDs(platform,CL_DEVICE_TYPE_GPU,

1,

&device,

NULL);

//创建context

cl_context context=clCreateContext(NULL,

1,

&device,

NULL,NULL,NULL);

//创建命令队列

cl_command_queue queue=clCreateCommandQueue(context,

device,

CL_QUEUE_PROFILING_ENABLE,NULL); //创建三个OpenCL内存对象,并把buf1的内容通过隐式拷贝的方式

//拷贝到clbuf1,buf2的内容通过显示拷贝的方式拷贝到clbuf2

cl_mem clbuf1=clCreateBuffer(context,

CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR,

NWITEMS*sizeof(cl_float),buf1,

NULL);

cl_mem clbuf2=clCreateBuffer(context,

CL_MEM_READ_ONLY,

NWITEMS*sizeof(cl_float),NULL,

NULL);

status=clEnqueueWriteBuffer(queue,clbuf2,1,

0,NWITEMS*sizeof(cl_float),buf2,0,0,0);

cl_mem buffer=clCreateBuffer(context,

CL_MEM_WRITE_ONLY,

NWITEMS*sizeof(cl_float),

NULL,NULL);

const char*filename="add.cl";

std::string sourceStr;

status=convertToString(filename,sourceStr);

const char*source=sourceStr.c_str();

size_t sourceSize[]={strlen(source)};

//创建程序对象

cl_program program=clCreateProgramWithSource(

context,

1,

&source,

sourceSize,

NULL);

//编译程序对象

status=clBuildProgram(program,1,&device,NULL,NULL,NULL);

if(status!=0)

{

printf("clBuild failed:%d\n",status);

char tbuf[0x10000];

clGetProgramBuildInfo(program,device,CL_PROGRAM_BUILD_LOG,0x10000,tbuf,NULL);

printf("\n%s\n",tbuf);

return?1;

}

if(buf)

free(buf);

if(buf1)

free(buf1);

if(buf2)

free(buf2);

//删除OpenCL资源对象

clReleaseMemObject(clbuf1);

clReleaseMemObject(clbuf2);

clReleaseMemObject(buffer);

clReleaseProgram(program);

clReleaseCommandQueue(queue);

clReleaseContext(context);

return0;

}

2.3.4Kernel对象

Kernel就是在程序代码中的一个函数,这个函数能在OpenCL设备上执行。一个Kernel对象就是kernel函数以及其相关的输入参数。

Kernel对象通过程序对象以及指定的函数名字创建。注意:函数必须是程序源代码中存在的函数。

cl_kernel clCreateKernel(cl_program program,

const char*kernel_name,

cl_int*errcode_ret);

运行时编译:在运行时,编译程序和创建kernel对象是有时间开销的,但这样比较灵活,能够适应不同的OpenCL硬件平台。程序动态编译一般只需一次,而Kernel对象在创建后,可以反复调用。

创建Kernel后,运行Kernel之前,我们还要为Kernel对象设置参数。我们可以在Kernel运行后,重新设置参数再次运行。

cl_int clSetKernelArg(cl_kernel kernel,

cl_uint arg_index,

size_t arg_size,

const void*arg_value);

arg_index指定该参数为Kernel函数中的第几个参数(比如第一个参数为0,第二个为1,…)。内存对象和单个的值都可以作为Kernel参数。下面是2个设置Kernel参数的例子:

clSetKernelArg(kernel,0,sizeof(cl_mem),(void*)&d_iImage);

clSetKernelArg(kernel,1,sizeof(int),(void*)&a);

在Kernel运行之前,我们先看看OpenCL中的线程结构:大规模并行程序中,通常每个线程处理一个问题的一部分,比如向量加法,我们会把两个向量中对应的元素加起来,这样,每个线程可以处理一个加法。

下面请看一个16个元素的向量加法:两个输入缓冲A、B,一个输出缓冲C。

在这种情况下,我们可以创建一维的线程结构去匹配这个问题。

每个线程把自己的线程id作为索引,把相应元素加起来。

OpenCL中的线程结构是可缩放的,Kernel的每个运行实例称作WorkItem(也就是线程),WorkItem组织在一起称作WorkGroup,OpenCL中,每个workgroup之间都是相互独立的。通过一个global id(在索引空间,它是唯一的)或者一个workgroup id和一个work group内的local id,就能标定一个workitem。

在kernel函数中,我们能够通过API调用得到global id以及其他信息:

get_global_id(dim);

get_global_size(dim);

这两个函数能得到每个维度上的global id。

get_group_id(dim);

get_num_groups(dim);

get_local_id(dim);

get_local_size(dim);

这几个函数用来计算group id以及在group内的local id。

column=get_global_id(0);

row=get_global_id(1);

get_num_groups(0)*get_local_size(0)==get_global_size(0);

?OpenCL内存模型

OpenCL的内存模型定义了各种各样内存类型,各种内存模型之间有层级关系。各种内存之间的数据传输必须是显式进行的,比如从host memory到device memory,从global memory到local memory等等。

Memory Description

Global Accessible by all work items

Constant Read-only,global

Local Local to a work-group

Private Private to a work-item

WorkGroup被映射到硬件的CU上执行(在AMD5xxx系列显卡上,CU就是simd,一个simd中有16个pe,或者说是stream core),OpenCL并不提供各个workgroup之间的一致性,如果我们需要在各个workgroup之间共享数据或者通信之类的,要自己通过软件实现。

?Kernel函数的写法

每个线程(workitem)都有一个kenerl函数的实例。下面我们看下kernel的写法:

__kernel void vecadd(__global const float*A,__global const float*B,__global float*C)

{

int id=get_global_id(0);

C[id]=A[id]+B[id];

}

每个Kernel函数都必须以__kernel开始,而且必须返回void。每个输入参数都必须声明使用的内存类型。通过一些API,比如get_global_id之类的得到线程id。

内存对象地址空间标识符有以下几种:

__global/*memory allocated from global address space*/

__constant/*a special type of read?only memory*/

__local/*memory shared by a work?group*/

__private/*private per work?item memory*/

__read_only||__write_only/*used for images*/

Kernel函数参数如果是内存对象,那么一定是__global,__local或者constant。

2.3.5Kernel执行

首先要设置线程索引空间的维数以及workgroup大小等。

我们通过函数clEnqueueNDRangeKerne把Kernel放在一个队列里,但不保证它马上执行,OpenCL driver会管理队列,调度Kernel的执行。注意:每个线程执行的代码都是相同的,但是它们执行数据却是不同的。

cl_int clEnqueueNDRangeKernel(cl_command_queue command_queue,

cl_kernel kernel,

cl_uint work_dim,

const size_t*global_work_offset,

const size_t*global_work_size,

const size_t*local_work_size,

cl_uint num_events_in_wait_list,

const cl_event*event_wait_list,

cl_event*event);

该函数把要执行的Kernel函数放在指定的命令队列中,globald大小(线程索引空间)必须指定,local大小(work group)可以指定,也可以为空。如果为空,则系统会自动根据硬件选择合适的大小。event waitlist用来选定一些events,只有这些events执行完后,该kernel才可能被执行,也就是通过事件机制来实现不同kernel函数之间的同步。

当Kernel函数执行完毕后,我们要把数据从device memory中拷贝到host memory中去。

cl_int clEnqueueReadBuffer(cl_command_queue command_queue,

cl_mem buffer,

cl_bool blocking_read,

size_t offset,

size_t cb,

void*ptr,

cl_uint num_events_in_wait_list,

const cl_event*event_wait_list,

cl_event*event);

?释放资源

大多数的OpenCL资源都是指针,不使用的时候需要释放掉。当然,程序关闭的时候这些对象也会被自动释放掉。释放资源的函数是:clRelase{Resource},比如:clReleaseProgram(),clReleaseMemObject()等。

?错误捕捉

如果OpenCL函数执行失败,会返回一个错误码,一般是个负值,返回0则表示执行成功。我们可以根据该错误码知道什么地方出错了,需要修改。错误码在cl.h中定义,下面是几个错误码的例子。

#define CL_DEVICE_NOT_FOUND?1

#define CL_DEVICE_NOT_AVAILABLE?2

#define CL_COMPILER_NOT_AVAILABLE?3

#define CL_MEM_OBJECT_ALLOCATION_FAILURE?4

图1:OpenCL机制示意图

?程序模型

–数据并行:work item和内存对象元素之间是一一映射关系;workgroup可以显示指定,也可以隐式指定。

–任务并行:kernel的执行独立于线程索引空间;用其他方法表示并行,比如把不同的任务放入队列,用设备指定的特殊的向量类型等等。

–同步:workgroup内work item之间的同步;命令队列中不同命令之间的同步。

完整代码如下:

#include"stdafx.h"

#include

#include

#include

#include

#include

#include

using namespace std;

#define NWITEMS262144

大学英语综合教程1课后习题答案

Unit 1 Part Ⅱ Reading Task Vocabulary Ⅰ1. 1)respectable 2)agony 3)put down 4)sequence 5)hold back 6)distribute 7)off and on 8)vivid 9)associate 10)finally 11)turn in 12)tackle 2. 1)has been assigned to the newspaper’s Paris office. 2)was so extraordinary that I didn’t know whether to believe him or not. 3)a clear image of how she would look in twenty years’time. 4)gave the command the soldiers opened fire. 5)buying bikes we’ll keep turning them out. 3. 1)reputation; rigid; to inspire 2)and tedious; What’s more; out of date ideas 3)compose; career; avoid showing; hardly hold back Ⅱviolating Ⅲ;in upon Comprehensive Exercises ⅠCloze back; tedious; scanned; recall; vivid; off and on; turn out/in; career ; surprise; pulled; blowing; dressed; scene; extraordinary; image; turn; excitement ⅡTranslation As it was a formal dinner party, I wore formal dress, as Mother told me to. 2)His girlfriend advised him to get out of /get rid of his bad habits of smoking before it took hold. 3)Anticipating that the demand for electricity will be high during the next few months, they have decided to increase its production. 4)It is said that Bill has been fired for continually violating the company’s safety rules. /Bill is said to have been fired for continually violating the company’s safety rules. 5)It is reported that the government has taken proper measures to avoid the possibility of a severe water shortage. /The local government is reported to have taken proper measures to avoid the possibility of a severe water shortage. 2.Susan lost her legs because of/in a car accident. For a time, she didn’t know how to face up to the fact she would never (be able to) walk again. One day, while scanning (through) some magazines, a true story caught her eye/she was attracted by a true story. It gave a vivid description of how a disabled girl became a writer. Greatly inspired, Susan began to feel that she, too, would finally be able to lead a useful life. Unit 2 Part ⅡReading Task Vocabulary Ⅰ1. 1)absolutely 2)available 3)every now and then 4)are urging/urged 5)destination 6)mostly 7)hangs out 8)right away 9)reunion 10)or something 11)estimate 12)going ahead 2. 1)in the examination was still on his mind. 2)was completely choked up by the sight of his team losing in the final minutes of the game. 3)was so lost in study that she forgot to have dinner. 4)has come up and I am afraid I won’t be able to accomplish the project on time. 5)of equipping the new hospital was estimated at﹩2 million. 3. 1)were postponed; the awful; is estimated 2)reference; not available; am kind of 3)not much of a teacher; skips; go ahead Ⅱ;on Ⅲor less of/sort of 4. kind of/sort of 5. more or less 6. or something Comprehensive Exercises ⅠCloze up; awful; practically; neighborhood; correspondence; available; destination; reunion; Mostly; postponing; absolutely ; savings; embarrassment; phone; interrupted; touch; envelope; signed; message; needed ⅡHalf an hour had gone by, but the last bus hadn’t come yet. We had to walk home. 2)Mary looks as if she is very worried about the Chinese exam because she hasn’t learned the texts by

英语听力教程 第三版 学生用书2 单词

Kindergarten: a school or class for young children, usually four to six years old, that prepares them for Nursery school: a school for very young children, usually 3 to 5 years of age Coo: speak gently and lovely wedding: the act or ceremony of becoming married Bride: a woman who has just been married or is about to be married relationship: Pick up: stop for and take or bring(person) along with one a romantic or sexual involvement Stability: steadiness, the state of being not likely to separate, break down or fall apart Discipline: strict control to enforce obedience; punishment / control, train, punish Lenient: merciful, not severe in disciplining, punishing, judging, ect. Spare the rod, spoil the child: a child who is not punished will become undisciplined and unruly. Harsh: unpleasant, unkind, cruel or more severe than is necessary Foldaway: that can be folded together for easy storage.Detached: not connected, separate Blind: anything that keeps out light, as a window shade or shutter. Estate: landed property; individually owned piece of land containing a residence. Sink:any of various basins, as in a kitchen or laundry, connected with a drainpipe and usually, with Appliance: a device or machine for performing a specific task, esp. one that is worked mechanically Property: a building or area of land, or both together Mortgage: an agreement that allows you to borrow money from or similar organization, Tenant: a person who pays rent for the use of land or a building Counselor: someone who is paid to listen to people’s problems and provide support and advice. Make the grade: succeed; reach the necessary standard quit: stop (doing something) and leave Goody-goody: a person who likes to appear faultless in behavior so as to please others, not because Emblazon: decorate something with a design, a symbol or words so that people will notice it easily Go to pieces: lose the ability to think or act clearly because of fear, sorrow, ect. Potter about: do things or move without hurrying, especially when you are doing something that Plough through: make slow progress through something difficult or boring especially a book Small hours: the early morning hours just after midnight.Regulate: make work at a certain speed Well-rounded: complete; well-planned for proper balance Abstruse:deep; hard to understand Compulsory: required; obligatory; that must be done Be cut out for: be fitted for; be suited for Burn one’s bridges: destroy all means of going back, so that one must go forward Segregation: separation; isolation; the policy or practice of compelling racial groups or people of Dispel: scatter or drive away; cause to disappear Cohort: a group of people who share a common feature or aspect of behavior High-flyer: a person who has the desire and the ability to be very successful in their job or their Flunk: fail to reach the required standard in (an exam, test, or course of study) Career: the general course of a person’s working life. Client: a person who buys goods or services Personnel: the department of a company or organization that deals with its employees when they need Make a fortune: earn a great amount of money, possessions, etc. Torture: severe pain or suffering caused in the mind or body Shift: a group of workers who take turns with one or more other groups Teamwork: the ability of a group of people to work together effectively Survey: a general examination or study (of conditions, opinions, etc.), especially carried out by Cross-section: a part or group that is typicalor representative of the whole Brainstorming: a way of making a group of people all think about sth at the same time, often in order

新世纪大学英语阅读教程2课文翻译

新世纪大学英语阅读教程翻译 Unit 1 塞克哈尔觉得,事实就像太阳一样。大概没有谁能直视太阳而不眨眼,不觉眩晕。他发觉人际关系的精髓在于时时刻刻调和事实,避免冲突。他设定了一个特殊的日子——一年中至少有一天无论如何必须说实话。否则生命还有什么意义。他对这一天充满无数期待,也没有告诉任何人要做这个实验。这是个秘密的决定,一件永远不为人知的事。 首次尝试便从妻子准备的早餐开始。他对一道美味举筷不定,这可是妻子自认为的厨中之冠。“怎么啦?不好吃吗?”她问道。要是往常,为了照顾她的情绪,他肯定说:“没有,我吃饱了而已。”可今天他却说:“不好吃。我咽不下去。”看到妻子眉头紧锁,他对自己说:“没办法,事实就像太阳一样。” 第二次尝试是在教师休息室,一个同事走过来说:“某某死了听说了吗?觉得很遗憾吧。”“不觉得,”赛克哈尔回答。“他的确是个好人……”另一个还没说完。塞克哈尔就抢过来说:“好什么啊,对我他可是个刻薄、自私的家伙。” 塞克哈尔给三年级A班上最后一节地理课时,收到校长递来的便条:回家前请过来一趟。他自言自语道:“肯定是那些可怕的试卷。一百多份字迹潦草的男生的试卷;他已经消极怠工几个礼拜了,感觉头顶像是悬了一把利剑,随时都有刺下来的可能。” 下课铃响起,孩子们潮水般涌出教室。塞克哈尔在校长门口停了会儿,扣好上衣扣子;扣子也是校长经常训诫的目标。 他进了门,彬彬有礼地说了句:“晚上好,校长。” 校长抬起头看着他,十分友善地问道:“今晚有空吗?” 塞克哈尔回答:“答应过家里的孩子要出去……” “那,可以改天再带他们出去。现在跟我回家。” “噢……好的,校长,当然没问题……”然后怯生生地问:“有什么要紧事吗,校长?”“是的,”校长回答,像是在对自己笑……“你真的不知道我缺乏音乐天赋吗?” “噢,知道,校长……” “我一直在偷偷地学习和练习,今晚想让你听听我演唱。我约好了一个鼓手和一个小提琴手为我伴奏。这还是我的第一次正式演出,想听听你的建议。我知道你的建议弥足珍贵。”塞克哈尔的音乐品味无人不知。他是小镇里最令人生畏的音乐评论人。可他怎么也没想到,他的音乐爱好将它引入这层磨难……。“对你来说,有点突然是吧?”校长问。“我已经关上门花了不知道多少钱……”他们开始往校长家走。“上帝没能给我一个孩子,可至少没有剥夺音乐给我的慰藉,”他们边走校长边悲戚戚地说。他喋喋不休地说着音乐的事:如何完全因打发无聊起步;如何被音乐老师取笑,又被给予希望;他人生的雄心壮志又是如何在音乐的世界里达到忘我的境界。 一到家,校长就大献殷勤。他请塞克哈尔坐在红丝毯上,敬上几样碟中美味,在旁边忙来忙去像是招待上门女婿。他甚至说:“你务必完全放松去听。别为那些试卷烦心。”然后不无幽默的加了一句:“我会给你一周的时间。” “十天怎么样,校长?”塞克哈尔请求。 “好,同意,”校长慷慨地说。塞克哈尔彻底松了口气——他可以一天干掉十份,彻底除掉这件烦心事。 校长点上熏香。“营造点气氛。”他解释说。鼓手和小提琴手已经到位,坐在缅甸仰光进口的小毯子上等他。校长在两人中间坐下来,像音乐会专业演出一般,清清喉咙,起了调子又停下来问:“可以吗,卡亚尼?(塞克哈尔的姓)”塞克哈尔假装没听到校长叫他。校长继

大学英语综合教程答案

3.Many products for sale seem to scream at us, "Buy me! Buy me!" Advertising is a big busin ess in our world with many products competing for our attention. Think of the last time you boug ht clothes. You probably noticed the variety of colors, patterns, fabrics and brands you could choo se from. Which kind of soft drink would you like to have today or what kind of computer do you want? Advertisers are skilled in the art of making their products look the best to appeal to our se nses. But products aren't always what they seem. Sometimes advertising is deceptive and as cons umers ,we must be careful about what we choose to buy. It is important to learn to compare prod ucts and identify our purpose in purchasing the things we need. But the good thing about advertising is that it helps people to make decisions and refine thei r choices. In the United States, the Ad Council creates timely public service messages to the nation. Th eir purpose is to raise awareness of public problems that citizens can respond to. Inspiring ads ca use individuals to take action and even save lives. Pollution in America, for example has been red uced over the years because of the creative Public Service advertisements that the council provid es" Please, please don't be a litter bug, 'cause every 'litter bit' hurts." Many families have taught t heir children to place litter in the trash can in response to this catchy phrase, which has affected g enerations as each succeeding generation has taught their children not to litter. 4.Nature imposes difficult conditions upon the earth from time to time . The tornado and fo rest fire destroy natural resources ,homes and other structures ,and very often harm or kill peopl e . Technological tragedies happen with little or no warning as we see trains crash and airplanes f all from the sky shortly after take-off. As tragic as calamities are , they seem to bring out the best in human nature . people trained in em ergency care arrive at the scene and begin assisting the inj ured .Others come with equipment to remove debris. Men , women ,and young people willingly c ome to the scene of an accident , hoping to be of help in some way . These selfless acts of kindne ss make our world a better place . compassion eases the wounds of calamities. American Airlines flight number 587 crashed less than three minutes after taking off from JF K Airport in New York in November,2001. Witnesses s aw an engine fire develop on the plane’s nu mber one engine located under the left wing of the aircraft .seconds later ,the airliner crashed int o eight homes ,completely destroying four of them .All 260 people aboard the airplane were kille d along with six people at the crash site ,leaving many people to mourn the loss of their loved on es .the residents (people who live in the area of the crash ) rallied together to comfort those griev ing, while others removed bodies from the wreckage and did the necessary clean-up. 工程实施困难的条件下在地上的时候。龙卷风和森林火灾破坏自然资源,房屋和其他建筑物,和经常伤害或杀死人。技术的悲剧发生在很少或没有预警,因为我们看到火车事故,飞机起飞后不久就从天空坠落。一样悲惨的灾难,他们似乎显示出人性中最好的。在急诊受训的人到达现场并开始帮助受伤的人则跟设备清除残骸。男人,女人,和年轻人自愿来到事故现场,希望能有帮助。这些无私的善举让我们的世界变得更美好。同情减轻灾害的伤口。 美国航空公司587号航班坠毁不到三分钟后从纽约肯尼迪机场起飞,11月2001。目击者看到一个引擎火灾发展在飞机上的1号引擎位于下飞机的左翼,接着后,客机坠毁八家,完全摧毁了四个260名乘客的飞机遇难连同6人在事故现场,造成许多人悼念失去的亲人,居民(住在崩溃的面积)聚集在一起,安慰那些悲伤,而另一些人则从残骸,并把尸体移走必要的清理。 5.Success can be reached in different ways by people in different careers. Bill Gates began at age to program computers,His vision for personal computing has been central to the success of M icrosoft Corporation, the company he founded with his childhood friend in 1975 . The former CEO of General Electric, Jack Welch, is a business legend. A famous quote by Mr. Welch is,” Chang before you have to. ”He believes in leading by example and encourages his empl oyees to do their best every day. Michael Jordan s aid,”I accept failure, but I can’t accept not trying.” He is one of the best athl etes to ever play team sports. His great smile, athletic achievements, and pleasant personality ha ve made him one of the most famous athletes in the world. Michael Jordan spent a lot of time pla ying basketball as a child but in senior middle school he was taken off the team . Instead of giving up , he worked through adversity and became the greatest basketball player yet .

听力教程第三版Unit4施心远学生用书答案

Unit 4 Section One Tactics for Listening Part 1 Phonetics Stress, Intonation and Accent Script Listen to some short conversations. Has the second speaker finished talking? Tick the right box. 1. A: Excuse me. Could you tell me where the secretary’s off ice is, please? B: Yes. It’s up the stairs, then turn left, …↗ 2. A: Excuse me. Can you tell me where the toilets are? B: Yes, they’re at the top of the stairs. ↘ 3. A: What did you do after work yesterday? B: Ah, well, I went for a drink in the pub opposite the carpark. ↘ 4. A: What did you do after work yesterday? B: Oh, I ran into Jane and Tom, …↗ 5. A: Excuse me, can you tell me how the machine works? B: Certainly. Erm, first of all you adjust the height of the stool, and then put four 10-pence pieces there, ... ↗ 6. A: Excuse me, can you tell me how the machine works? B: Yes. You put 30 pence in the slot and take the ticket out here. ↘Key Part 2 Listening and Note-Taking Frog Legs Script A. Listen to some sentences and fill in the blanks with the missing words. 1. Many Asian cultures have included frog legs in their diets for centuries. 2. By 1977 the French government banned commercial hunting of its own amphibians. 3. Indian scientists have describ ed as “disastrous” the rate at which frogs are disappearing from the rice fields and wetlands. 4. The United States imported more than 6.5 million pounds of frozen frog meat each year between 1981 and 1984.

大学法语简明教程第12单元至17单元动词总结

1. Habiter à 2. il fait +adjective 表天气的无人称短语 3. il+ vimpers(无人称动词)表天气 4. falloir 需要,应该il faut +n./inf. 需要某物,应该做某事 5. il y a+n./pronom 某处有…… 6. chanter vt./ Vi. danser vi. 7. aller à去某地 venire de从……来 venire à来到某地 10. avoir +n. 觉得…… Avoir faim /soif /chaud / froid 8. aimer qch. /qn. 9. travailler vi. 工作 10. prendre vt. 乘坐~ l’autobus / le metro / le train /le train / le bateau 吃喝~le petit déjeuner /le d?ner /un café /du lait 取道~ la première rue à gauche 11. descendre 下车 ~ du train /de la voiture 12. passer vt. ~ un examen /ses vacances vi. ~devant la bibliothèque 13. se trouver 位于 14. regarder la television voir le film lire 15. aller +faire qch. 去做某事 16. remercier qn.de qch. 因某事感谢某人 17. penser à qch.考虑…… 18. prier qn. de faire qch. 请求某人做某事 19. s’appeller 名叫…… 20. apprendre ~ qch. à qn. 教某人某物 ~ qch. aurès de qn. 向…学… 23.Faire ses etudes 学习 24.faire des progress 取得进步 25. écouter qch. v.t. écouter de la m usique 听音乐 26. se réveiller 醒来 Réveiller qn. 唤醒某人 Se lever 起床 Endormir 使……入睡 S’endormir 睡着

《全新版大学英语阅读教程4(高级本)》课文翻译

---------------------------------------------------------------最新资料推荐------------------------------------------------------ 《全新版大学英语阅读教程4(高级本)》课文翻译 《全新版大学英语阅读教程 4(高级本)》 ------普通高等教育“十五”国家级规划教材译文(部分) 1.The Campers at Kitty Hawk 在这篇文章中,John Dos Passos 运用散文和诗歌两种文学形式,讲述了莱特兄弟制造的世界上第一架飞机,这是人类历史上最重要的里程碑之一。 他还描述了杰出的莱特兄弟的生活,他们去 kitty Hawk 不是为了野营,而是去完成一个听起来不可能的事情。 1903 年 12 月 17 日,住在俄亥俄州代顿市霍桑街一幢木头房子里的兄弟联合会主教、曾任《宗教嘹望》报编辑的莱特先生收到了他的儿子威尔伯和奥维尔发来的电报。 他们两个突发奇想, 去北卡罗来纳州海岸沙丘上的一个小宿营地度假 ,给自己匆忙赶制的滑翔机做一些修补。 电文:周四早成功四次飞行,在 21mile/hour 从水平面起飞,仅靠引擎力量启动,平均 31mile/hour 最长 57 秒。 数字有点出入,因为电报员误读了奥维夫的潦字。 但事实并没改变,来自 dayton,俄亥俄州的两个单车修理工设计,建造,并试飞了一架真正的飞机。 电机预热几分钟后,我松了拉住飞机在跑道的绳,飞机迎风冲去。 韦伯扶着机翼跑以保持机身的平衡,以免跑出跑道。 不像 14 号那天,今天电机平静的向前稳行,直面 27M/H 的风。 1/ 6

大学英语综合教程答案

Key to Exercises Opener Mary is thinking of getting a tattoo tomorrow afternoon. She asks Mel to join her, but Mel cannot because she has to work tomorrow. And then Mary invites Mel to go to a party tomorrow night. Mel hesitates at first, but finally decides to go with Mary. They will meet at eight o’clock. Abbreviation Meaning 1. TGIF Thank God it’s Friday 2. AMA Ask me anything 3. OMG Oh my God! 4. YOLO You only live once 5. FOMO Fear of missing out 6. FYI For your information 7. LOL Laugh out loud 8. TBH To be honest 9. PPL People 10. ETA Estimated time of arrival Transcript: A: Hey, Mary. B: Hey, Mel. A: TGIF.

B: TGIF. A: Mel, I need some advice on something. B: AMA A: Yeah, thanks. I’m thinking of getting a tattoo. B: OMG! Really Are you serious A: Well, YOLO. B: That’s true. A: Well. B: When are you going to do it A: I’m thinking tomorrow afternoon. Do you want to come B: Oh, I’d love to come, but I’ve got to work tomorrow. Oh, major FOMO. A: What a shame! B: Yeah, A: Well, FYI, there’s a party tomorrow night. And if you are not busy, you can come to that instead. B: I’m not busy, but TBH I really need to take it easy this weekend. A: What That’s so not like you. B: LOL, that’s true. A: Party is in Hackney Wick. It’s gonna be good, good music, good PPL. B: Oh, major FOMO again. Oh, what the hell Yes, why not I’ll go.

英语听力教程第三版(张民伦主编)Unit-8-The-Sound-of-Music听力原文

英语听力教程第三版(张民伦主编)Unit-8-The-Sound-of-Musi c听力原文

Listen this way听力教程第三册-8 Unit 8 The Sound of Music Part I Getting ready A quiz game show is a type of radio or television programming genre in which contestants, television personalities or celebrities, sometimes as part of a team, play a game which involves answering questions or solving puzzles usually for money and/or prizes. A The following words will appear in this unit. Listen carefully and study the definitions. 1. panel:a group of specialists who give their advice or opinion about something 2. contender:a person who takes part in a competition or tries to win something 3. nomination:the act of suggesting or choosing somebody as a candidate in an election, or for a job or an award 4. cinematography:the art or process of making films 5. score:the music written for a film/movie or play

大学法语简明教程(文档)-05[1].法语句法总结之间接引语.

法语句法总结之间接引语 间接引语(Le discours indirect)以从句的方式来转述他人的思想、意见。与直接引语不同,间接引语只保持原话内容的完整,而形式则根据叙述者的人称、性、数及其谓语的语式、时态作相应调整。 1.1 人称代词、主有代词及主有形容词的变化 1、引语的人称和叙述者的人称必须一致,例如: Il dit:“Je suis fatigué.”他说:“我累了。” Il dit qu’il est fatigué. 他说他累了。 2、引语中的主有代词、主有形容词必须和叙述者配合,例如: Il me demande:“Quelle est ton opinion?”他问我:“你有什么意见?” Il me demande quelle est mon opinion. 他问我有什么意见。 1.2 时态的变化 1、如果间接引语的主句谓语用现在时或将来时,间接引语的谓语保持原句中使用的语式和时态,例如: Je lui demande:“Est-ce que tu aimes ce film?”我问他:“你是否喜欢这部电影?”Je lui demande s’il aime ce film. 我问他是否喜欢这部电影。 2、如果间接引语的主句谓语用过去时,间接引语谓语的语式和时态变化原则上是以叙述者叙述的时间为基准对原句谓语时间作变更,例如: J’ai dit:“Je viendrai tout de suite.”我当时说:“我立刻就来。” J’ai dit que je viendrais tout de suite. 我当时说我马上就来。 3、当直接引语为命令式时,变为间接引语应换成不定式或虚拟式,例如: Elle dit aux enfants:“partez tout de suite!”她对孩子们说:“快出发吧!” Elle dit aux enfants de partir tout de suite. 她让孩子们快出发。 Je lui dit“Viens!”我对他说:“来吧!” Il disait qu’il était arrivé la veille. 他说他是前一天到的。 Il dit:“Elle viendra ici.”他说:“她要来这儿。” Il dit qu’elle vien dra là. 他说她要去那儿。 1.4 间接引语疑问词的用法 1、普通疑问句(以oui、non回答的疑问句)变成间接引语时si以引导,例如: Je lui demande:“Est-ce que tu aimes ce film?”我问他:“你是否喜欢这部电影?”Je lui demande s’il aime ce film. 我问他是否喜欢这部电影。 2、疑问句以qui、que、quel、où、pourquoi、comment、combien等疑问词引导时,间

相关主题