예제 #1
0
VkResult DeviceMemory::mapMemory(const VkDeviceSize offset, const VkDeviceSize size, const VkMemoryMapFlags flags)
{
    if (!(memoryPropertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT))
    {
        return VK_ERROR_MEMORY_MAP_FAILED;
    }

    if (mapped)
    {
        unmapMemory();
    }

    auto result = vkMapMemory(device, deviceMemory, offset, size, flags, &data);

    if (result == VK_SUCCESS)
    {
        mapped = VK_TRUE;
    }
    else
    {
        data = nullptr;
    }

    return result;
}
/*
 * Class:     sharedmemory_SharedMemory
 * Method:    unmapMemory
 * Signature: (Ljava/nio/ByteBuffer;)I
 */
JNIEXPORT jint JNICALL Java_sharedmemory_SharedMemory_unmapMemory
  (JNIEnv *env, jobject obj, jobject memory) {
  int ret = -1;
  char* memory_address = (char*) (*env)->GetDirectBufferAddress(env, memory);
  int size = (*env)->GetDirectBufferCapacity(env, memory);
  ret = unmapMemory(memory_address, size);
  return ret;
}
예제 #3
0
int main(int argc, char *argv[])
{
	char* filename;
	s32 ret;
	mipsCpu* cpu;
	
	printf("greenLeaf 0.1\n");
	printf("mips emulator by The Lemon Man and SquidMan\n");

	if(argc < 2) {	/* No arguments passed. */
		filename = calloc(5, 1);
		sprintf(filename, "test/mmon");
	}else{
		filename = calloc(strlen(argv[1]) + 1, 1);
		sprintf(filename, argv[1]);
	}

#ifdef DEBUG
	printf("Debug mode enabled\n");
#endif
	printf("Initializing the CPU core...\n");
	cpu = initializeCPU(ENDIANNESS_LE, 0x80000000);
	
	printf("Mapping the ram...\n");
	
	printf("Main memory %d\n",	mapMemory(cpu, 0x80000000, 0x40000, FLAG_RAM));
	printf("Reset vector %d\n",	mapMemory(cpu, 0xBFC00000, 0x40000, FLAG_RAM));
	printf("Additional mem %d\n",	mapMemory(cpu, 0xA0000010, 0x2000, FLAG_RAM));
	
//	ret = openRaw(cpu, filename, 0xBFC00000);
	ret = openElf32(cpu, filename);

	printf("Entry %#x\n",	(u32)ret);
	
	printf("Uart %i\n",	setupUart(cpu, 0xB40003f8));
	
	setPC(cpu, ret);
	
	printf("Press enter to run a tick and print the registers...\n");
	printf("Press enter to continue.\n");
	for(;;) {
#ifdef TICK_AT_A_TIME
		fgetc(stdin);
#endif
		runProcessor(cpu, 1);		/* Run a single cycle at a time */
		//~ printRegisters(cpu);
	}
	
	printf("Execution finished... unmapping the ram\n");
	
	unmapMemory(cpu);
	
	free(filename);
	
	return 1;
}
예제 #4
0
void DeviceMemory::destroy()
{
    if (deviceMemory)
    {
        if (mapped)
        {
            unmapMemory();
        }

        vkFreeMemory(device, deviceMemory, nullptr);

        deviceMemory = VK_NULL_HANDLE;
    }
}
예제 #5
0
VkResult DeviceMemory::upload(const VkDeviceSize offset, const VkDeviceSize size, const VkMemoryMapFlags flags, const void* uploadData, const size_t uploadDataSize)
{
    auto result = mapMemory(offset, size, flags);

    if (result != VK_SUCCESS)
    {
        return result;
    }

    memcpy(data, uploadData, uploadDataSize);

    unmapMemory();

    return result;
}
bool
mapMemory(MemoryMappedFile *file, size_t offset, size_t address, size_t size)
{
   if (!file || offset > file->size || offset + size > file->size) {
      return false;
   }

   auto baseAddress = reinterpret_cast<void *>(address);
   auto result = mmap(baseAddress, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);

   if (result != baseAddress) {
      unmapMemory(file, address, size);
      return false;
   }

   return true;
}
예제 #7
0
VkResult DeviceMemory::upload(const VkDeviceSize offset, const VkMemoryMapFlags flags, const void* uploadData, const size_t uploadDataSize)
{
    auto result = mapMemory(offset, uploadDataSize, flags);

    if (result != VK_SUCCESS)
    {
        return result;
    }

    memcpy(data, uploadData, uploadDataSize);

	if (!(memoryPropertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))
	{
		result = flushMappedMemoryRanges(offset, uploadDataSize);
	}

    unmapMemory();

    return result;
}
예제 #8
0
int main(int argc, char *argv[])
{
    if(argc < 3)
    {
        printf("\nPor favor, informe o nome dos arquivos onde as duas matrizes a serem multiplicadas se encontram.\n\n");
        exit(-1);
    }
    else
    {
        FILE *file1 = fopen(argv[1], "r");
        FILE *file2 = fopen(argv[2], "r");

        if (file1 == 0 || file2 == 0)
        {
            printf("\nImpossivel abrir um dos aqrquivos informados. Verifique possiveis erros de sintaxe.\n\n");
            exit(-1);
        }
        else 
        {
            int **mat1, **mat2, **matout, m1, n1, m2, n2, i;
            getMatrixDimension(&m1, &n1, &m2, &n2, &file1, &file2);
            mat1 = initializeSharedReadMatrix(mat1, m1, n1, &file1);
            close(file1);
            mat2 = initializeSharedReadMatrix(mat2, m2, n2, &file2);
            close(file2);
            matout = initializeSharedOutputMatrix(matout, m1, n2);

            int forkNumber;
            if(argc == 4)
                forkNumber = atoi(argv[3]);
            else
                forkNumber = m1;
            if(forkNumber <= 0)
            {
                printf("\nNumero de processos deve ser maior ou igual a um.\n");
                exit(-1);
            }
            printMatrix(mat1, m1, n1);
            printMatrix(mat2, m2, n2);
            pid_t pid;
            for(i = 0; i < forkNumber; i++)
            {
                pid = fork();
                if(pid == 0)
                {
                    int k;
                    for(k = i; k < m1; k += forkNumber)
                    {
                        printf("\num filho %d: Vou calcular: linha %d", i, k);
                        multiplyMatrix(mat1, mat2, matout, k, n1, n2);
                    }
                    break;
                }
            }
            waitpid(-1, 0, 0);
            if(pid != 0)
            { 
                printMatrix(matout, m1, n2);
                unmapMemory(mat1, m1, n1);
                unmapMemory(mat2, m2, n2);
                unmapMemory(matout, m1, n2);
                printf("\nFim processo pai\n\n");
            }
        }
    }
    exit(0);
}